Update Bot #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Bot | |
on: | |
workflow_dispatch: | |
jobs: | |
deploy-via-sftp: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: SFTP Deploy | |
uses: wlixcc/[email protected] | |
with: | |
username: root | |
server: ${{ secrets.SERVER_IP }} | |
port: 22 | |
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} | |
local_path: ./* | |
remote_path: /home/antbot/ | |
args: '-o ConnectTimeout=5' | |
restart-bot: | |
needs: [deploy-via-sftp] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Restart Bot via SSH | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: root | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
echo "Changing to /home/antbot/" | |
cd /home/antbot/ | |
echo "Activating virtual environment" | |
source .venv/bin/activate | |
echo "Checking for existing bot process" | |
BOT_PID=$(pgrep -f 'python main.py') | |
if [ -n "$BOT_PID" ]; then | |
echo "Stopping existing bot process (PID: $BOT_PID)" | |
kill -TERM $BOT_PID | |
sleep 5 | |
else | |
echo "No existing bot process found" | |
fi | |
echo "Starting bot" | |
nohup python main.py > /dev/null 2>&1 & | |
echo "Workflow completed" | |
script_stop: true | |
timeout: 60s |