【问题标题】:python script as a service on Ubuntu [closed]python脚本作为Ubuntu上的服务[关闭]
【发布时间】:2012-06-12 11:36:33
【问题描述】:

我面临以下问题。我想在 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 代码?

【问题讨论】:

  • cron环境路径中是否有python进程?尝试使用绝对路径 /usr/local/bin/python 或您使用的 python 所在的位置。
  • @TeemuIkonen:它不是由 cron 运行的。它正在使用init运行。 ... init 的路径中没有任何内容...
  • @Teemu Ikonen - 尝试使用 exec /usr/bin/python 文件名,但还是一样
  • 在此处查看调试帮助upstart.ubuntu.com/cookbook/#exec 第 20.5 节。就我个人而言,我已经抛弃了 linux init mess 并切换到 supervisord
  • 你能发布你的 Python 脚本内容吗?

标签: python ubuntu upstart


【解决方案1】:

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

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

【讨论】:

  • 重定向错误输出文件没有给出任何结果。尝试了以下 - sudo start script 2> error.txt
  • 好的,我在 :- exec python 文件名中添加了 /usr/bin/python 而不是 python,但仍然是同样的问题
猜你喜欢
  • 2019-06-17
  • 2012-08-02
  • 2018-05-28
  • 2018-10-15
  • 2012-11-12
  • 1970-01-01
  • 2020-09-05
  • 2023-02-07
  • 2016-10-03
相关资源
最近更新 更多