Skip to content

Commit

Permalink
feat: Use systemctl
Browse files Browse the repository at this point in the history
  • Loading branch information
WCY-dt committed Dec 17, 2024
1 parent a73af3e commit ed76e2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 15 additions & 0 deletions my-github-2024.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Gunicorn instance to serve my-github-2024
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/my-github-2024
Environment="PATH=/var/www/my-github-2024/venv/bin"
Environment="FLASK_ENV=production"
EnvironmentFile=/var/www/my-github-2024/.env
ExecStart=/var/www/my-github-2024/venv/bin/python3 /var/www/my-github-2024/my-github-2024.py

[Install]
WantedBy=multi-user.target
13 changes: 8 additions & 5 deletions script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
cd /var/www/my-github-2024 || { echo "Directory not found"; exit 1; }

# Find and kill the existing process
PID=$(ps -ef | grep my-github-2024.py | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
kill -9 $PID || { echo "Failed to kill existing process"; exit 1; }
fi
systemctl stop my-github-2024 || { echo "Failed to stop the existing process"; exit 1; }

# Remove old log files
rm -f app.log nohup.out
Expand All @@ -21,5 +18,11 @@ source venv/bin/activate || { echo "Failed to activate virtual environment"; exi
pip install -r requirements.txt || { echo "Failed to install dependencies"; exit 1; }

# Start the application
nohup python3 my-github-2024.py > ./app.log 2>&1 &
cp my-github-2024.service /etc/systemd/system/
systemctl daemon-reload || { echo "Failed to reload systemctl"; exit 1; }
systemctl start my-github-2024 || { echo "Failed to start the application"; exit 1; }
sudo systemctl enable my-github-2024 || { echo "Failed to enable the application"; exit 1; }

systemctl status my-github-2024

echo "Deployment completed successfully"

0 comments on commit ed76e2f

Please sign in to comment.