运行 将金字塔服务器作为守护进程的最佳方式
Best way to run a pyramid pserve server as daemon
我曾经使用 pserve --daemon
命令 运行 我的金字塔服务器作为守护进程。
鉴于它已被弃用,我正在寻找最佳替代品。 This link 建议 运行 使用 screen
或 tmux
,但对于 运行 网络服务器来说似乎太重了。另一个想法是使用 setsid 启动它。
有什么好的方法可以运行吗?
最简单的选择是安装 supervisord 并为该服务设置一个 conf 文件。该程序将只是 env/bin/pserve production.ini
。网上有无数关于如何执行此操作的示例。
最好 选项是与系统的进程管理器集成(通常是 systemd,但也可能是 upstart 或 sysvinit 或 openrc)。编写用于启动 pserve 的 systemd 单元文件非常容易,然后它将 started/stopped 与系统的其余部分一起。在这些情况下甚至会自动处理日志文件。
在/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
Start/Stop/Restart 服务:
systemctl 启动pyramid.service
systemctl 重启pyramid.service
systemctl 停止 pyramid.service
我曾经使用 pserve --daemon
命令 运行 我的金字塔服务器作为守护进程。
鉴于它已被弃用,我正在寻找最佳替代品。 This link 建议 运行 使用 screen
或 tmux
,但对于 运行 网络服务器来说似乎太重了。另一个想法是使用 setsid 启动它。
有什么好的方法可以运行吗?
最简单的选择是安装 supervisord 并为该服务设置一个 conf 文件。该程序将只是 env/bin/pserve production.ini
。网上有无数关于如何执行此操作的示例。
最好 选项是与系统的进程管理器集成(通常是 systemd,但也可能是 upstart 或 sysvinit 或 openrc)。编写用于启动 pserve 的 systemd 单元文件非常容易,然后它将 started/stopped 与系统的其余部分一起。在这些情况下甚至会自动处理日志文件。
在/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
Start/Stop/Restart 服务:
systemctl 启动pyramid.service
systemctl 重启pyramid.service
systemctl 停止 pyramid.service