Daemon vs Upstart for python script -


i have written module in python , want run continuously once started , need stop when need update other modules. using monit restart it, if module has crashed or otherwise not running.

i going through different techniques daemon, upstart , many others.

which best way go use approach through out new modules keep running them forever?

from mention of upstart assume question service being run on ubuntu server.

on ubuntu server upstart job simplest , convenient option creating on service starts @ right time , can stopped or reloaded familiar commands.

to create upstart service need add single file /etc/init. called <service-name>.conf. example script looks this:

description "my chat server" author "your@email-address.com"  start on runlevel [2345] stop on runlevel [!2345]  env an_environmental_variable=i-want-to-set  respawn  exec /srv/applications/chat.py 

this means everytime machine started start chat.py program. if dies whatever reason restart it. don't have worry double forking or otherwise daemonizing code. that's handled upstart.

if want stop or start process can

service chat start  service chat stop 

the name chat automatically found name of .conf file inside /etc/init

i'm covering basics of upstart here. there lots of other features make more useful. available running man upstart.

this method more convenient, writing own daemonization code. 4-8 line config file built in ubuntu component less error prone making code safely double fork , having process monitor make sure doesn't go away.

monit bit of red herring. if want downtime alerts need run monitoring program on separate server anyway. rely on upstart keep process running on server. have different service makes sure server running. downtime happens many different reasons. process running on same server tell precisely nothing if server goes down. need separate machine (or third party provider pingdom) alert condition.


Comments