python脚本作为Ubuntu上的服务

时间:2012-06-08 11:53:42

标签: python ubuntu upstart

我面临以下问题。我想在Ubuntu 11.10系统上运行python脚本作为服务(已在以下链接中提到: Python script as linux service/daemon

我按照上面提到的链接中提到的步骤进行了操作,但是我在syslog中收到以下错误消息:

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

以下是script.conf/etc/init的内容:

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代码?

1 个答案:

答案 0 :(得分:0)

init脚本似乎很好,但脚本本身由于某种原因无法运行。您需要添加一些日志记录或至少将其标准和错误输出重定向到日志文件以查看它可能是什么。

编辑: Teemu Ikonen在评论中注意到您在没有完整路径的情况下运行python,并且在给定的上下文中它可能不在$ PATH中。我会扩展它:它肯定不在你的$ PATH中。您必须始终使用init脚本中的可执行文件的完整路径。

相关问题