Reputation: 2382
I can successfully launch a flask app in gunicorn like this:
$ gunicorn registry --daemon --bind x.x.x.x:8000 --workers xxx --pid xxx.api.registry.pid --error-logfile xxx.api.registry.error.log --access-logfile xxx.api.registry.access.log
Now the systemd related config looks like this:
/etc/systemd/system/api-registry.service
[Unit]
Description=api-registry
After=network.target
[Service]
User=app
WorkingDirectory=xxx/code/api/registry
EnvironmentFile=-/etc/sysconfig/api-registry
ExecStart=/usr/bin/gunicorn --daemon $OPTIONS registry
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
and the settings are configured from:
OPTIONS="--bind x.x.x.x:8000 --workers 8 --pid xxx.api.registry.pid --error-logfile xxx.api.registry.error.log --access-logfile xxx.api.registry.access.log"
Setting the systemd LogLevel
to debug
results in the following logs:
Jan 27 15:26:02 my-server systemd[31817]: Executing: /usr/bin/gunicorn --daemon --bind 172.31.141.233:8000 --workers 8 --pid /home/app/ip-spotlight/mon/pid/ip-spotlight.api.registry.pid --error-logfile /home/app/ip-spotlight/log/ip-spotlight.api.registry.error.log --access-logfile /home/app/ip-spotlight/log/ip-spotlight.api.registry.access.log registry
Jan 27 15:26:03 my-server systemd[1]: Received SIGCHLD from PID 31817 (gunicorn).
Jan 27 15:26:03 my-server systemd[1]: Child 31817 (gunicorn) died (code=exited, status=0/SUCCESS)
Jan 27 15:26:03 my-server systemd[1]: Child 31817 belongs to api-registry.service
Jan 27 15:26:03 my-server systemd[1]: api-registry.service: main process exited, code=exited, status=0/SUCCESS
Jan 27 15:26:03 my-server systemd[1]: About to execute: /bin/kill -s TERM $MAINPID
Jan 27 15:26:03 my-server systemd[1]: Forked /bin/kill as 31820
Jan 27 15:26:03 my-server systemd[1]: api-registry.service changed running -> stop
Jan 27 15:26:03 my-server systemd[1]: Child 31818 (gunicorn) died (code=exited, status=0/SUCCESS)
Jan 27 15:26:03 my-server systemd[1]: Received SIGCHLD from PID 31818 (n/a).
Jan 27 15:26:03 my-server systemd[31820]: Executing: /bin/kill -s TERM
Jan 27 15:26:03 my-server kill[31820]: Usage:
Jan 27 15:26:03 my-server kill[31820]: kill [options] <pid|name> [...]
Jan 27 15:26:03 my-server kill[31820]: Options:
Jan 27 15:26:03 my-server kill[31820]: -a, --all do not restrict the name-to-pid conversion to processes
Jan 27 15:26:03 my-server kill[31820]: with the same uid as the present process
Jan 27 15:26:03 my-server kill[31820]: -s, --signal <sig> send specified signal
Jan 27 15:26:03 my-server kill[31820]: -q, --queue <sig> use sigqueue(2) rather than kill(2)
Jan 27 15:26:03 my-server kill[31820]: -p, --pid print pids without signaling them
Jan 27 15:26:03 my-server kill[31820]: -l, --list [=<signal>] list signal names, or convert one to a name
Jan 27 15:26:03 my-server kill[31820]: -L, --table list signal names and numbers
Jan 27 15:26:03 my-server kill[31820]: -h, --help display this help and exit
Jan 27 15:26:03 my-server kill[31820]: -V, --version output version information and exit
Jan 27 15:26:03 my-server kill[31820]: For more details see kill(1).
Jan 27 15:26:03 my-server systemd[1]: Received SIGCHLD from PID 31820 (kill).
Jan 27 15:26:03 my-server systemd[1]: Child 31820 (kill) died (code=exited, status=1/FAILURE)
Jan 27 15:26:03 my-server systemd[1]: Child 31820 belongs to api-registry.service
Jan 27 15:26:03 my-server systemd[1]: api-registry.service: control process exited, code=exited status=1
Jan 27 15:26:03 my-server systemd[1]: api-registry.service got final SIGCHLD for state stop
Jan 27 15:26:03 my-server systemd[1]: api-registry.service changed stop -> stop-sigterm
Jan 27 15:26:03 my-server systemd[1]: Got cgroup empty notification for: /system.slice/api-registry.service/control
Jan 27 15:26:03 my-server systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1/agent interface=org.freedesktop.systemd1.Agent member=Released cookie=5775 reply_cookie=0 error=n/a
Jan 27 15:26:03 my-server systemd[1]: Received SIGCHLD from PID 31819 (gunicorn).
Jan 27 15:26:03 my-server systemd[1]: Child 31819 (gunicorn) died (code=killed, status=15/TERM)
Jan 27 15:26:03 my-server systemd[1]: Child 31819 belongs to api-registry.service
Jan 27 15:26:03 my-server systemd[1]: api-registry.service: cgroup is empty
Jan 27 15:26:03 my-server systemd[1]: api-registry.service changed stop-sigterm -> failed
Jan 27 15:26:03 my-server systemd[1]: Unit api-registry.service entered failed state.
Jan 27 15:26:03 my-server systemd[1]: api-registry.service failed.
Please note that there is no virtualenv
setup. Essentially it should be like /usr/bin/python3.4 /usr/bin/gunicorn
Could you please advise what I am doing wrong ?
Upvotes: 1
Views: 1766
Reputation: 2382
It turned out that the --daemon
gunicorn option and systemd do not work together
Upvotes: 1