When I was developing a Python web application with aws using the Tornado framework, the web application running with aws often sleeps (the app falls), so I made it a daemon and made it work 24/7 (always started). A memo when I tried to wake up (restart the application) even if I fell asleep.
Supervisor is a lightweight process management tool made in Python.
The procedure is as follows. All work is done on ubuntu 14.04 on aws.
Supervisor can be installed with either ʻapt-get or
pip, but for the time being, I will describe how to install with ʻapt-get
on Ubuntu.
Please note that the location of the setting file changes depending on the installation method. For apt-get * /etc/supervisor/conf.d/
*
For Ubuntu (apt-get)
$ sudo apt-get install supervisor
Confirm that it has been installed. The version seems to include 3.0b2
.
$ supervisord -v
3.0b2
$ sudo supervisorctl version
3.0b2
Write the information for starting the Web application in the Supervisor setting file (conf file).
Create a conf file in * /etc/supervisor/conf.d/
*.
$ sudo vim /etc/supervisor/conf.d/tornado.conf
The contents are as follows. The name of the process to be managed by Supervisor is ** tornado **.
tornado.conf
[program:tornado] ;Process name
directory=/home/ubuntu/tornado-app ;Working directory
command=/home/ubuntu/tornado-app/venv/bin/python /home/ubuntu/tornado-app/server.py --port=3000 ;Start command
numprocs=1 ;Number of boot instances?
autostart=true ;autostart
autorestart=true ;Reboot automatically
user=ubuntu ;Launch user
redirect_stderr=true ;Output standard error
stdout_logfile=/var/log/supervisor/tornado.log ;Log file output destination
Suppose your web app has already been git cloned to / home / ubuntu / tornado-app
.
$ cd ~/tornado-app
$ source venv/bin/activate #activate virtualenv
(venv)$ python server.py --port=3000 &
Also, please refer to Supervisor configuration for how to write the Supervisor configuration file.
Start Supervisor using the service supervisor
command
Restart Supervisor itself.
$ sudo service supervisor restart
Make sure that Supervisor itself is running.
$ sudo service supervisor status
is running
Manage the process with the supervisorctl
command.
If you change the conf file, you will definitely need to reread it. Use the following command to read the conf file.
$ sudo supervisorctl reread
After that, start the web application managed by Supervisor.
$ sudo supervisorctl start tornado #Start-up
Check if the web application is running.
$ sudo supervisorctl status #Status check
tornado RUNNING pid 3414, uptime 0:07:19
It started!
By the way, the stop and restart are as follows.
$ sudo supervisorctl stop tornado #Stop
$ sudo supervisorctl restart tornado #Reboot
In addition, here was helpful for the supervisorctl command.
Recommended Posts