Start the scheduler as a Linux service (upstart)
To install the scheduler as a permanent daemon on Linux (w/ Upstart), put the following into /etc/init/web2py-scheduler.conf, assuming your web2py instance is installed in <user>'s home directory, running as <user>, with app <myapp>, on network interface eth0.
description "web2py task scheduler"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn limit 8 60 # Give up if restart occurs 8 times in 60 seconds.
exec sudo -u <user> python /home/<user>/web2py/web2py.py -K <myapp>
respawn
You can then start/stop/restart/check status of the daemon with:
sudo start web2py-scheduler
sudo stop web2py-scheduler
sudo restart web2py-scheduler
sudo status web2py-scheduler
上面是web2py文档中的原话,大意是如果你需要在linux上跑scheduler,你要在/etc/init目录下创建一个web2py-scheduler.conf的配置文件,配置文件中最重要的是:exec sudo -u <user> python /home/<user>/web2py/web2py.py -K <myapp>其中第一个<user>表明要用哪个用户运行,python后面的路径是你的web2py文件存放的路径, <myapp>是你要运行的app名称。
这是我的配置文件:
root@180:/etc/init# cat web2py-scheduler.conf description "web2py task scheduler" start on (local-filesystems and net-device-up IFACE=eth0) stop on shutdown respawn limit 8 60 # Give up if restart occurs 8 times in 60 seconds. exec sudo -u root python /opt/linkDataAdmin/web2py/web2py.py -K linkDataAdmin respawn
运行状态:
root@180:/etc/init# start web2py-scheduler
web2py-scheduler start/running, process 19619
root@180:/etc/init# status web2py-scheduler
web2py-scheduler start/running, process 19619