💾 Archived View for chirale.org › 2013-06-07_1198.gmi captured on 2024-08-24 at 23:56:28. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-12)

-=-=-=-=-=-=-

Autolaunch a command and restart it on quit on CentOS

I’ve a django-admin command running as a server thanks to gevent. I want this server to run on boot and autorestart on quit.  StackOverflow give me a hint: use Supervisor.

django-admin command

gevent

Supervisor

On a Centos 5 distro:

 # find supervisor for your distro... yum search supervisor # ...and install it yum install supervisor.noarch nano /etc/supervisord.conf 

At the end of the file, add a new program:

 [program:myfunnydjangocommand] command=/usr/bin/env python26 /usr/local/etc/django-apps/foo/manage.py tcpapi 4114 priority=999 ; the relative start priority (default 999) autostart=true ; start at supervisord start (default: true) autorestart=true ; retstart at unexpected quit (default: true) ; startsecs=-1 ; number of secs prog must stay running (def. 10) ; startretries=3 ; max # of serial start failures (default 3) exitcodes=0,2 ; 'expected' exit codes for process (default 0,2) stopsignal=QUIT ; signal used to kill process (default TERM) ; stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10) ; user=root ; setuid to this UNIX account to run the program log_stdout=true ; if true, log program stdout (default true) log_stderr=true ; if true, log program stderr (def false) logfile=/var/log/myfunnydjangocommand.log ; child log path, use NONE for none; default AUTO logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) logfile_backups=10 ; # of logfile backups (default 10) 

Then, start supervisord.

 service supervisord start 

Take a look to supervisord log file:

 less +G /var/log/supervisor/supervisord.log 

You’ll see something like this:

 2013-06-07 11:54:16,559 CRIT Supervisor running as root (no user in config file) 2013-06-07 11:54:16,576 INFO /var/tmp/supervisor.sock:Medusa (V1) started at Fri Jun 7 11:54:16 2013 Hostname: <unix domain socket> Port:/var/tmp/supervisor.sock 2013-06-07 11:54:16,645 CRIT Running without any HTTP authentication checking 2013-06-07 11:54:16,654 INFO daemonizing the process 2013-06-07 11:54:16,657 INFO supervisord started with pid 19316 2013-06-07 11:54:16,666 INFO spawned: 'myfunnydjangocommand' with pid 19318 2013-06-07 11:54:17,670 INFO success: myfunnydjangocommand entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 

Read documentation about the configuration options but keep in mind your Supervisor version. I don’t use supervisorctl because of this bug, if you get an error simply go with service supervisord… but if you have a newer version this should be already fixed.

Read documentation

Note: myfunnydjangocommand.log doesn’t contain anything useful in my experience but maybe it’s related how I write the output since I’ve written it to use interactively, outputting lines directly to the user. I’ll update this post if I find how to solve this issue.

https://web.archive.org/web/20130607000000*/https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

https://web.archive.org/web/20130607000000*/http://www.gevent.org/gevent.server.html

https://web.archive.org/web/20130607000000*/http://supervisord.org/

https://web.archive.org/web/20130607000000*/http://supervisord.org/configuration.html