繁体   English   中英

需要帮助在Ubuntu中使用Upstart将Python应用程序作为服务运行

[英]Need help running Python app as service in Ubuntu with Upstart

我已经在Python中编写了一个日志应用程序,它应该在启动时启动,但我无法使用Ubuntu的Upstart init守护程序启动应用程序 当使用sudo /usr/local/greeenlog/main.pyw从终端运行时,应用程序可以正常运行。 以下是我为Upstart工作尝试的内容:

/etc/init/greeenlog.conf

# greeenlog

description     "I log stuff."

start on startup
stop on shutdown

script
    exec /usr/local/greeenlog/main.pyw
end script

我的应用程序启动一个子线程,以防重要。 我已经尝试了期望fork节的工作而没有任何结果的变化。 我也尝试过使用sudo而没有脚本语句(只是一个单独的exec语句)。 在所有情况下,启动后,运行状态greeenlog返回greeenlog停止/等待并运行启动greeenlog返回:

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"))

谁能看到我做错了什么? 我感谢您提供的任何帮助。 谢谢。

感谢unutbu的帮助,我能够纠正我的工作。 显然,这些是Upstart设置的唯一环境变量(使用os.environ在Python中检索):

{'TERM': 'linux', 'PWD': '/', 'UPSTART_INSTANCE': '', 'UPSTART_JOB': 'greeenlog', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin'}

我的程序依赖于设置的几个变量,因此这里是具有正确环境变量的修订作业:

# greeenlog

description     "I log stuff."

start on startup
stop on shutdown

env DISPLAY=:0.0
env GTK_RC_FILES=/etc/gtk/gtkrc:/home/greeenguru/.gtkrc-1.2-gnome2

script
    exec /usr/local/greeenlog/main.pyw > /tmp/greeenlog.out 2>&1
end script

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM