运行 生产中的 web2py 调度器

running web2py scheduler in production

我知道我可以 运行 使用

手动调度程序
python web2py.py -K myapp

但是生产环境应该在哪里指定呢?我在 ubuntu.

上为 apache 使用标准的 web2py 部署脚本

使用 Ubuntu 12.04 我手动制作:

  1. /etc/init目录下创建web2py-scheduler.conf文件:

    description     "Web2py scheduler"
    start on filesystem or runlevel [2345]
    stop on runlevel [!2345]
    
    respawn
    respawn limit 8 60
    
    exec sudo -u user <path_to_web2py>/web2py.py -K <your_app>
    
  2. /etc/init.d执行:

    ln -s /lib/init/upstart-job web2py-scheduler

  3. (可选,仅当您需要手动启动时)在/etc/init目录中创建web2py-scheduler.override 文件:

    manual
    

请看 Web2Py Book 这对我有用 运行 Ubuntu 14:

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

为了画圆。在 2015 年之后使用 Debian 或其他 Linux 发行版,要走的路是 systemd。对于 systemd,必须执行以下步骤: 创建文件 /etc/systemd/system/web2py-sched.service 包含以下内容

[Unit]
Description=Web2Py scheduler service

[Service]
ExecStart=/usr/bin/python /home/www-data/web2py/web2py.py -K <yourapp>
Type=simple

[Install]
WantedBy=multi-user.target

然后安装服务调用:

sudo systemctl enable /etc/systemd/system/web2py-sched.service