本文介绍了需要帮助在 Ubuntu 中使用 Upstart 将 Python 应用程序作为服务运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Python 编写了一个日志应用程序,该应用程序旨在在启动时启动,但我一直无法使用 Ubuntu 的 Upstart init 守护进程.当使用 sudo/usr/local/greenlog/main.pyw 从终端运行时,应用程序运行良好.这是我为 Upstart 工作所尝试的:

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/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 返回:

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.

推荐答案

多亏了 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):

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

我的程序依赖于设置的几个变量,所以这里是使用正确环境变量修改后的作业:

My program relies on a couple of these variables being set, so here is the revised job with the right environment variables:

# 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

谢谢!

这篇关于需要帮助在 Ubuntu 中使用 Upstart 将 Python 应用程序作为服务运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:28