![](/img/trans.png)
[英]Running Python script as upstart service shows different time output
[英]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.