vi /etc/init.d/myApp
#!/sbin/openrc-run
pidfile="/run/$RC_SVCNAME.pid"
command="/usr/local/bin/myApp"
depend() {
need net
}
start() {
ebegin "Starting myApp"
start-stop-daemon --start --background \
--exec $command \
--make-pidfile --pidfile $pidfile
eend $?
}
stop() {
ebegin "Stopping myApp"
start-stop-daemon --stop \
--exec $command \
--pidfile $pidfile
eend $?
}
reload() {
ebegin "Reloading myApp"
start-stop-daemon --exec $command \
--pidfile $pidfile \
-s 1
eend $?
}
添加可执行权限
chmod +x /etc/init.d/myApp
启动
/etc/init.d/myApp start
停止
/etc/init.d/myApp stop
开机启动
rc-update add myApp default
参考来源:
http://big-elephants.com/2013-01/writing-your-own-init-scripts/
本文介绍了一个名为myApp的服务脚本实现方式,该脚本基于openrc-run进行编写,包括了启动(start)、停止(stop)及重载(reload)等基本操作,并详细展示了如何设置依赖项、PID文件路径及执行命令。
4875

被折叠的 条评论
为什么被折叠?



