如何配置 Python 脚本作为守护进程运行

Ace*_*Ace 2 ubuntu nginx daemon

我有几个网络服务器坐在负载均衡器后面,我在这里找到了“watcher.py”:https : //github.com/splitbrain/Watcher

我选择这个脚本有几个原因:通过文件夹递归,很多触发选项

无论如何,我将使用它来同步负载平衡服务器之间的 Web 内容。有没有办法确保这个脚本在启动时运行?

EEA*_*EAA 9

我发现处理此类应用程序的最简单方法是安装supervisord,然后使用它来启动、监视和收集脚本的输出。

这是一个示例主管配置文件:

[program:watcher]
command = /usr/bin/python /path/to/watcher.py
stdout_logfile = /var/log/watcher-stdout.log
stdout_logfile_maxbytes = 10MB
stdout_logfile_backups = 5
stderr_logfile = /var/log/watcher-stderr.log
stderr_logfile_maxbytes = 10MB
stderr_logfile_backups = 5
Run Code Online (Sandbox Code Playgroud)