无法启动 <myapp>.service: Unit <myapp>.service not found

cto*_*ote 15 python init.d upstart services

我为我的 python 机器人创建了一个超级基本的 init.d 脚本:

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    echo "starting torbot"
    python /home/ctote/dev/slackbots/torbot/torbot.py
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here
    # example: killproc program_name
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac
Run Code Online (Sandbox Code Playgroud)

并已torbot.py成为+x#!/usr/local/bin/python在顶部。但是,当我尝试实际启动它时,我得到:

:/var/lock/subsys$ sudo service torbot start Failed to start torbot.service: Unit torbot.service not found.

我错过了什么吗?

Leo*_*olf 2

对我来说,我使用的是 Ubuntu 16.04。

首先更改init函数

. /etc/init.d/functions
Run Code Online (Sandbox Code Playgroud)

. /lib/lsb/init-functions
Run Code Online (Sandbox Code Playgroud)

然后在 shell 中,创建从 /etc/rc* 到我的脚本的符号链接:

sudo update-rc.d <myapp> defaults 95
Run Code Online (Sandbox Code Playgroud)


小智 0

你厌倦了这样的事情吗?如何调试 Upstart 脚本?

您能否提供本指南提供的输出,以便我们可以帮助您调试问题?