【问题标题】:running web2py scheduler in production在生产环境中运行 web2py 调度程序
【发布时间】:2015-05-08 01:19:21
【问题描述】:

我知道我可以使用手动运行调度程序

python web2py.py -K myapp

但是在生产环境中应该在哪里指定呢?我在 ubuntu 上为 apache 使用标准 web2py 部署脚本。

【问题讨论】:

  • 对于生产,您必须使用mod_wsgi。这将适用于 apache。

标签: python deployment web2py production-environment


【解决方案1】:

只是为了使图片四舍五入。在 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 

【讨论】:

  • 启动服务可以调用systemctl:systemctl start /etc/systemd/system/web2py-sched
  • 或sudo service web2py-sched start
【解决方案2】:

使用 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
    

【讨论】:

  • 为什么重生限制为 8 60 ? sudo 真的有必要吗?
  • 重生限制对我来说是个不错的选择,1分钟内超过8次意味着有问题,调度器启动有点慢。
  • 出于安全原因,sudo 很重要。所以 web2py 调度程序以非特权用户身份运行。
【解决方案3】:

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

将调度程序作为 Linux 服务启动(新贵)

要将调度程序安装为 Linux 上的永久守护程序(w/ Upstart),请将以下内容放入 /etc/init/web2py-scheduler.conf,假设您的 web2py 实例安装在 user 的主目录,以 user 身份运行,带有应用程序 myapp,在网络接口 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

然后您可以使用以下命令启动/停止/重新启动/检查守护程序的状态:

sudo start web2py-scheduler
sudo stop web2py-scheduler
sudo restart web2py-scheduler
sudo status web2py-scheduler

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 2011-03-20
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多