Daemon vs Upstart for python script

后端 未结 3 940
逝去的感伤
逝去的感伤 2020-12-12 12:12

I have written a module in Python and want it to run continuously once started and need to stop it when I need to update other modules. I will likely be using monit to resta

3条回答
  •  一生所求
    2020-12-12 12:44

    You could check out supervisor. What it is capable of is starting a process at system startup, and then keeping it alive until shutdown.

    The simplest configuration file would be:

    [program:my_script]
    command = /home/foo/bar/venv/bin/python /home/foo/bar/scripts/my_script.py
    environment = MY_ENV_VAR=FOO, MY_OTHER_ENV_VAR=BAR
    autostart = True
    autorestart = True
    

    Then you could link it to /etc/supervisord/conf.d, run sudo supervisorctl to enter management console of supervisor, type in reread so that supervisor notices new config entry and update to display new programs on the status list.

    To start/restart/stop a program you could execute sudo supervisorctl start/restart/stop my_script.

提交回复
热议问题