【发布时间】:2017-02-16 15:55:39
【问题描述】:
我曾经使用pserve --daemon 命令将我的金字塔服务器作为守护进程运行。
鉴于它已被弃用,我正在寻找最佳替代品。 This link 建议使用screen 或tmux 运行它,但是只运行一个Web 服务器似乎太重了。另一个想法是使用 setsid 启动它。
什么是运行它的好方法?
【问题讨论】:
标签: daemon pyramid httpserver python-daemon
我曾经使用pserve --daemon 命令将我的金字塔服务器作为守护进程运行。
鉴于它已被弃用,我正在寻找最佳替代品。 This link 建议使用screen 或tmux 运行它,但是只运行一个Web 服务器似乎太重了。另一个想法是使用 setsid 启动它。
什么是运行它的好方法?
【问题讨论】:
标签: daemon pyramid httpserver python-daemon
在 /etc/systemd/system 中创建一个服务文件。这里是一个示例(pyramid.service):
[Unit]
Description=pyramid_development
After=network.target
[Service]
# your Working dir
WorkingDirectory=/srv/www/webgis/htdocs/app
# your pserve path with ini
ExecStart=/srv/www/app/env/bin/pserve /srv/www/app/development.ini
[Install]
WantedBy=multi-user.target
启用服务:
systemctl 启用 pyramid.service
启动/停止/重启服务:
systemctl start pyramid.service
systemctl restart pyramid.service
systemctl stop pyramid.service
【讨论】:
最简单的选择是安装 supervisord 并为该服务设置一个 conf 文件。该程序将只是env/bin/pserve production.ini。网上有无数的例子说明如何做到这一点。
最好的选项是与系统的进程管理器集成(通常是 systemd,但也可能是 upstart 或 sysvinit 或 openrc)。编写一个用于启动 pserve 的 systemd 单元文件非常容易,然后它将与系统的其余部分一起启动/停止。在这些情况下,甚至会自动处理日志文件。
【讨论】:
supervisord -c /etc/supervisord.conf 来“删除过时的套接字”。