需要帮助在 Ubuntu 中使用 Upstart 将 Python 应用程序作为服务运行
我已经用 Python 编写了一个日志应用程序,该应用程序应该在启动时启动,但我无法使用 Ubuntu 启动该应用程序新贵初始化守护进程。当使用 sudo /usr/local/greenlog/main.pyw 从终端运行时,应用程序可以完美运行。以下是我为 Upstart 作业所做的尝试:
/etc/init/greenlog.conf
# greeenlog
description "I log stuff."
start on startup
stop on shutdown
script
exec /usr/local/greeenlog/main.pyw
end script
我的应用程序启动一个子线程,以防万一这很重要。我已经尝试使用 expect fork 节来完成这项工作,结果没有任何变化。我还尝试过使用 sudo 进行此操作,而无需使用脚本语句(只是一个单独的 exec 语句)。在所有情况下,启动后,运行 status greenlog 返回 greenlog stop/waiting 并运行 start greenlog 返回:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.61" (uid=1000 pid=2496 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
任何人都可以看到我在做什么错误的?我很感激你能提供的任何帮助。谢谢。
I have written a logging application in Python that is meant to start at boot, but I've been unable to start the app with Ubuntu's Upstart init daemon. When run from the terminal with sudo /usr/local/greeenlog/main.pyw, the application works perfectly. Here is what I've tried for the Upstart job:
/etc/init/greeenlog.conf
# greeenlog
description "I log stuff."
start on startup
stop on shutdown
script
exec /usr/local/greeenlog/main.pyw
end script
My application starts one child thread, in case that is important. I've tried the job with the expect fork stanza without any change in the results. I've also tried this with sudo and without the script statements (just a lone exec statement). In all cases, after boot, running status greeenlog returns greeenlog stop/waiting and running start greeenlog returns:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.61" (uid=1000 pid=2496 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
Can anyone see what I'm doing wrong? I appreciate any help you can give. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢unutbu的帮助,我已经能够纠正我的工作了。显然,这些是 Upstart 设置的唯一环境变量(在 Python 中使用 os.environ 检索):
我的程序依赖于设置的几个变量,因此这里是具有正确环境的修改后的作业变量:
谢谢!
Thanks to unutbu's help, I have been able to correct my job. Apparently, these are the only environment variables that Upstart sets (retrieved in Python with os.environ):
My program relies on a couple of these variables being set, so here is the revised job with the right environment variables:
Thank you!