v2: adaptive python3.10 install (local or ssh)
This commit is contained in:
@@ -1,33 +1,162 @@
|
||||
name: Fix Python 3.10 on New Server
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- ops/downgrade-runners
|
||||
paths:
|
||||
- '.gitea/workflows/fix-python310.yml'
|
||||
- 'scripts/fix_python310_and_port.py'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
fix-python310:
|
||||
install-python310:
|
||||
runs-on: runtime-builder:host
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare SSH key
|
||||
- name: Detect environment and install Python 3.10
|
||||
run: |
|
||||
mkdir -p /root/.ssh
|
||||
echo "$SSH_PRIVATE_KEY" > /root/.ssh/new_server_ed25519
|
||||
chmod 600 /root/.ssh/new_server_ed25519
|
||||
# 测试连接
|
||||
ssh -i /root/.ssh/new_server_ed25519 -o StrictHostKeyChecking=no root@172.30.18.199 "echo SSH连接成功"
|
||||
set -e
|
||||
|
||||
PY_VER=$(python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>/dev/null || echo "0.0")
|
||||
echo "Current Python version: $PY_VER"
|
||||
|
||||
NEW_SERVER="172.30.18.199"
|
||||
|
||||
install_python() {
|
||||
echo "=== Installing Python 3.10.14 ==="
|
||||
|
||||
# 安装编译依赖(CentOS用yum,Ubuntu用apt)
|
||||
if command -v yum &> /dev/null; then
|
||||
echo "Detected CentOS, using yum..."
|
||||
yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make readline-devel sqlite-devel 2>&1 | tail -5
|
||||
elif command -v apt-get &> /dev/null; then
|
||||
echo "Detected Ubuntu, using apt..."
|
||||
apt-get update -qq && apt-get install -y build-essential zlib1g-dev libffi-dev libssl-dev wget 2>&1 | tail -5
|
||||
fi
|
||||
|
||||
# 下载源码
|
||||
cd /tmp
|
||||
if [ ! -f Python-3.10.14.tgz ]; then
|
||||
echo "Downloading Python 3.10.14..."
|
||||
wget -q https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz
|
||||
fi
|
||||
|
||||
# 编译安装
|
||||
echo "Extracting..."
|
||||
tar xzf Python-3.10.14.tgz
|
||||
cd Python-3.10.14
|
||||
|
||||
echo "Configuring..."
|
||||
./configure --prefix=/usr/local/python310 --enable-optimizations --with-ensurepip=install 2>&1 | tail -3
|
||||
|
||||
echo "Compiling (this takes 5-10 min)..."
|
||||
make -j$(nproc) 2>&1 | tail -5
|
||||
|
||||
echo "Installing..."
|
||||
make install 2>&1 | tail -5
|
||||
|
||||
# 替换默认python3
|
||||
echo "Setting as default python3..."
|
||||
if [ -f /usr/bin/python3 ]; then
|
||||
mv /usr/bin/python3 /usr/bin/python3.bak 2>/dev/null || true
|
||||
fi
|
||||
if [ -f /usr/bin/pip3 ]; then
|
||||
mv /usr/bin/pip3 /usr/bin/pip3.bak 2>/dev/null || true
|
||||
fi
|
||||
ln -sf /usr/local/python310/bin/python3.10 /usr/bin/python3
|
||||
ln -sf /usr/local/python310/bin/pip3.10 /usr/bin/pip3
|
||||
ln -sf /usr/local/python310/bin/python3.10 /usr/local/bin/python3
|
||||
ln -sf /usr/local/python310/bin/pip3.10 /usr/local/bin/pip3
|
||||
|
||||
echo "=== Python 3.10 installation complete ==="
|
||||
python3 --version
|
||||
pip3 --version
|
||||
}
|
||||
|
||||
# 判断是否在新服务器上(Python 3.6 = CentOS新服务器)
|
||||
if [ "$PY_VER" = "3.6" ]; then
|
||||
echo "Running on new server (Python 3.6), installing locally..."
|
||||
install_python
|
||||
|
||||
echo "=== Fixing CMD Agent port (5000 -> 5927) ==="
|
||||
if [ -f /opt/cmd-agent/server.py ]; then
|
||||
sed -i 's/port=5000/port=5927/g; s/port = 5000/port = 5927/g' /opt/cmd-agent/server.py 2>/dev/null || true
|
||||
# 直接替换所有5000为5927(只在app.run那行)
|
||||
sed -i 's/app.run(host=.0.0.0.*, port=5000/&\n# fixed port/' /opt/cmd-agent/server.py 2>/dev/null || true
|
||||
systemctl restart cmd-agent
|
||||
sleep 2
|
||||
systemctl status cmd-agent --no-pager | head -5
|
||||
ss -tlnp | grep 5927 || echo "port 5927 not found"
|
||||
fi
|
||||
|
||||
echo "=== Restarting all 6 runners ==="
|
||||
for i in 1 2 3 4 5 6; do
|
||||
systemctl restart act-runner-$i
|
||||
echo "act-runner-$i restarted"
|
||||
done
|
||||
sleep 3
|
||||
systemctl list-units 'act-runner-*' --no-legend
|
||||
|
||||
else
|
||||
echo "Running on old server (Python $PY_VER), installing via SSH to new server..."
|
||||
|
||||
# 准备SSH密钥
|
||||
mkdir -p /root/.ssh
|
||||
echo "$SSH_PRIVATE_KEY" > /root/.ssh/new_server_ed25519
|
||||
chmod 600 /root/.ssh/new_server_ed25519
|
||||
|
||||
echo "Testing SSH connection..."
|
||||
ssh -i /root/.ssh/new_server_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@$NEW_SERVER "echo SSH_OK && python3 --version"
|
||||
|
||||
# 把安装脚本传过去并执行
|
||||
echo "Transferring and executing install script..."
|
||||
ssh -i /root/.ssh/new_server_ed25519 -o StrictHostKeyChecking=no root@$NEW_SERVER 'bash -s' << 'INSTALL_SCRIPT'
|
||||
set -e
|
||||
|
||||
echo "=== Installing build dependencies ==="
|
||||
yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make readline-devel sqlite-devel 2>&1 | tail -5
|
||||
|
||||
echo "=== Downloading Python 3.10.14 ==="
|
||||
cd /tmp
|
||||
if [ ! -f Python-3.10.14.tgz ]; then
|
||||
wget -q https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz
|
||||
fi
|
||||
ls -lh Python-3.10.14.tgz
|
||||
|
||||
echo "=== Compiling Python 3.10.14 ==="
|
||||
tar xzf Python-3.10.14.tgz
|
||||
cd Python-3.10.14
|
||||
./configure --prefix=/usr/local/python310 --with-ensurepip=install 2>&1 | tail -3
|
||||
make -j$(nproc) 2>&1 | tail -10
|
||||
make install 2>&1 | tail -5
|
||||
|
||||
echo "=== Setting as default ==="
|
||||
mv /usr/bin/python3 /usr/bin/python3.bak 2>/dev/null || true
|
||||
mv /usr/bin/pip3 /usr/bin/pip3.bak 2>/dev/null || true
|
||||
ln -sf /usr/local/python310/bin/python3.10 /usr/bin/python3
|
||||
ln -sf /usr/local/python310/bin/pip3.10 /usr/bin/pip3
|
||||
ln -sf /usr/local/python310/bin/python3.10 /usr/local/bin/python3
|
||||
ln -sf /usr/local/python310/bin/pip3.10 /usr/local/bin/pip3
|
||||
|
||||
echo "=== Verification ==="
|
||||
python3 --version
|
||||
pip3 --version
|
||||
pip3 install --help 2>&1 | grep -q "break-system" && echo "break-system-packages: SUPPORTED" || echo "WARNING: break-system not supported"
|
||||
|
||||
echo "=== Fix CMD Agent port ==="
|
||||
if [ -f /opt/cmd-agent/server.py ]; then
|
||||
sed -i 's/port=5000/port=5927/g' /opt/cmd-agent/server.py
|
||||
sed -i 's/port = 5000/port = 5927/g' /opt/cmd-agent/server.py
|
||||
systemctl restart cmd-agent
|
||||
sleep 2
|
||||
ss -tlnp | grep 5927 && echo "CMD Agent on port 5927" || echo "CMD Agent port check failed"
|
||||
fi
|
||||
|
||||
echo "=== Restart all runners ==="
|
||||
for i in 1 2 3 4 5 6; do
|
||||
systemctl restart act-runner-$i
|
||||
done
|
||||
sleep 3
|
||||
systemctl list-units 'act-runner-*' --no-legend
|
||||
|
||||
echo "=== DONE ==="
|
||||
INSTALL_SCRIPT
|
||||
fi
|
||||
|
||||
echo "=== All done ==="
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.NEW_SERVER_SSH_KEY }}
|
||||
|
||||
- name: Install Python 3.10 + Fix CMD Agent port
|
||||
run: |
|
||||
export NEW_SERVER=172.30.18.199
|
||||
export SSH_KEY_PATH=/root/.ssh/new_server_ed25519
|
||||
python3 scripts/fix_python310_and_port.py
|
||||
|
||||
Reference in New Issue
Block a user