2012-06-08 70 views
2

我正面臨以下問題。我想運行一個python腳本在Ubuntu 11.10系統中的服務(在下面的鏈接已經提到: Python script as linux service/daemonpython腳本作爲Ubuntu上的服務

我跟着上面提到的鏈接中提到的步驟,但我在系統日誌有以下錯誤信息:

init: script main process (21826) terminated with status 1 
Jun 8 16:59:55 bilbo kernel: [263012.984531] init: script main process ended, respawning 
Jun 8 16:59:55 bilbo kernel: [263013.044099] init: script main process (21827) terminated with status 1 

以上兩行代碼一直在重複着。

在說sudo start script,我得到如下:

$ sudo start script 
script start/running, process 21826 

以下是放置在/etc/init的我script.conf的內容:

description "Used to start python script as a service" 
author "bilbo" 
start on runlevel [2] 
stop on runlevel [06] 
exec python /home/bilbo/scripts/webserver.py 
respawn 

請告訴我什麼,我做錯了什麼?我是否還必須更改我的Python代碼?

+0

cron環境路徑中的python進程?嘗試使用絕對路徑/ usr/local/bin/python或者您正在使用的python。 –

+0

@TeemuIkonen:它不是由cron運行的。它正在使用init運行。 ... init的路徑中沒有任何內容... –

+0

@Teemu Ikonen - 用exec/usr/bin/python filename嘗試過,但仍然一樣 – bugs99

回答

0

初始化腳本看起來不錯,但腳本本身由於某種原因無法運行。您需要添加一些日誌記錄,或者至少將它的標準和錯誤輸出重定向到日誌文件以查看它可能是什麼。

編輯: Teemu Ikonen在評論中注意到您正在運行沒有完整路徑的python,並且它可能不在$ PATH的給定上下文中。我會擴展它:它肯定不在你的$ PATH中。您必須始終使用init腳本中的可執行文件的完整路徑。

+0

重定向錯誤輸出文件不會提供任何內容。嘗試了以下 - sudo啓動腳本2> error.txt – bugs99

+0

好吧,我添加/ usr/bin/python而不是python: - exec python filename 但仍然是同樣的問題 – bugs99