python 脚本作为 Ubuntu 上的服务

标签 python ubuntu upstart

<分区>

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

我按照上述链接中提到的步骤进行操作,但系统日志中出现以下错误消息:

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

最佳答案

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

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

关于python 脚本作为 Ubuntu 上的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948350/

相关文章:

python - mkvirtualenv 给出权限被拒绝错误

python - (Buildbot) 无法使用 ShellCommand 激活 virtualenv

bash - 上次访问时间未更新?

ubuntu - Telegram Webhook 中的 SSL 证书验证失败

logging - 启用 Upstart 日志输出

linux - 如何为每个主管程序在/运行中创建一个目录?

python - virtualenv 使用 Python 2.6 而不是 2.7

python - 分配一个 pandas dataframe NULL=0, non-NULLvalue=1

python - 自定义 Django 管理界面功能

linux - 如何让服务知道当前用户名