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.
我错过了什么吗?
对我来说,我使用的是 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)
| 归档时间: |
|
| 查看次数: |
39900 次 |
| 最近记录: |