我在用os-svc-daemon
为 openstack 项目创建我的 upstart 服务。
我的 upstart 工作配置如下
文件:/etc/init/myservice.conf
start on runlevel [2345]
stop on runlevel [016]
env OS_SVC_ENABLE_CONTROL=1
export OS_SVC_ENABLE_CONTROL
pre-start script
mkdir -p /var/run/myservice
chown -R root:root /var/run/myservice
end script
respawn
# the default post-start of 1 second sleep delays respawning enough to
# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s.
respawn limit 2 5
exec start-stop-daemon --start -c root --exec /opt/stack/venvs/openstack/bin/myservice --
post-start exec sleep 1
该服务以 root 用户身份运行。
如果我运行start-stop-daemon --start -c root --exec /opt/stack/venvs/openstack/bin/myservice
它就运行正常。
但是当我使用检查状态时
~# initctl start myservice
myservice stop/starting
~# initctl status myservice
myservice stop/waiting
我也试过调试
start on runlevel [2345]
stop on runlevel [016]
env OS_SVC_ENABLE_CONTROL=1
export OS_SVC_ENABLE_CONTROL
pre-start script
mkdir -p /var/run/myservice
chown -R root:root /var/run/myservice
end script
script
echo "DEBUG: `set`" >> /tmp/myjob.log
# rest of script follows...
end script
respawn
# the default post-start of 1 second sleep delays respawning enough to
# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s.
respawn limit 2 5
exec start-stop-daemon --start -c root --exec /opt/stack/venvs/openstack/bin/myservice --
post-start exec sleep 1
但它不是在创建文件/tmp
答案1
我猜你的命令之一启动前脚本失败(可能是 mkdir)。尝试附加“|| true”
pre-start script
mkdir -p /var/run/myservice || true
chown -R root:root /var/run/myservice || true
end script
您应该看到进程号出现在initctl start myservice
命令之后