一个简单的OpenRC Service文件

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/

猜你喜欢

转载自blog.csdn.net/lbp0408/article/details/80473404