Gracefully restarting the action movie after switching the current symbolic link to the new directory

I am trying to deploy my application and my folders are organized in such a way that it means that I only change the symbolic link when I want to deploy a new version. Like this:

./2013-07-16-10-12-48-test/ ./2013-07-16-10-17-01-test/ ./current -> 2013-07-16-10-17-01-test/ 

Usually I just used kill -HUP master-pid and everything works until the directory remains the same. But when I first change the symbolic link, and then reload the code, it is still executed from the old directory by its absolute path, for example, shooting follows the symbolic link and saves the final path. I start shooting like this: gunicorn run:app -c gunicorn-config.py inside the "current" directory, and my configuration file looks like this:

 workers = 4 worker_class = 'gevent' bind = '127.0.0.1:5000' pidfile = '/var/run/gunicorn.pid' debug = False loglevel = 'debug' errorlog = '/var/log/gunicorn-error.log' daemon = True 

Is there a way for the gun to overestimate a symbolic link or save a symbolic link instead of the full path? Perhaps something like on_starting or on_reload hook?

Here is a solution that I could not work with, perhaps this gives an even greater context.

+4
source share
1 answer

I got this working using the USR2 signal. This is my init.d file, and after deployment, I just ran service gunicorn start_or_reload , which either starts or gracefully reloads the code based on the new location. He technically spawns another master in the current master, then kills the old workers and craftsmen and finally promotes the newly created master. I went with this solution to add smoke tests later, before killing the old master and the like. Hope this helps someone!

 #!/bin/sh ### BEGIN INIT INFO # Provides: thin # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: S 0 1 6 # Short-Description: thin initscript # Description: thin ### END INIT INFO # Original author: Forrest Robertson # Do NOT "set -e" DEPLOY_PATH=/opt/project/current PID_FOLDER=/var/run/gunicorn PID_FILE=$PID_FOLDER/project.pid OLD_PID_FILE=$PID_FOLDER/project.pid.oldbin start() { cd $DEPLOY_PATH && gunicorn run:app -c gunicorn-config.py } stop() { if [ -f $PID_FILE ] then kill `cat $PID_FILE` rm $PID_FILE fi } reload() { kill -USR2 `cat $PID_FILE` sleep 1 kill -QUIT `cat $OLD_PID_FILE` rm $OLD_PID_FILE } start_or_reload() { if [ -f $PID_FILE ] then reload else start fi } case "$1" in start) echo "Starting server..." start ;; reload) echo "Reloading server..." reload ;; stop) echo "Stopping server..." stop ;; restart) echo "Restarting server..." stop && sleep 1 && start ;; start_or_reload) echo 'Starting or reloading server...' start_or_reload ;; wup) echo "Increasing workers..." kill -TTIN `cat $PID_FILE` ;; wdown) echo "Decreasing workers..." kill kill -TTOU `cat $PID_FILE` ;; *) echo "Usage: $SCRIPT_NAME {start|reload|stop|restart|start_or_reload|wup|wdown}" >&2 exit 3 ;; esac : 
+1
source

Source: https://habr.com/ru/post/1491643/


All Articles