我正在尝试将我的 node.js 服务器转变为服务。
我尝试了几种不同的方法,但还没有成功。有谁能帮我解决这个问题吗?
谢谢!
答案1
也许你可以做类似下面的事情。只需将以下内容替换为您的脚本,然后将脚本放在 /etc/init.d 中
#!/bin/sh
#
# myservice This shell script takes care of starting and stopping
# the <myservice>
#
# Source function library
. /etc/rc.d/init.d/functions
# Do preliminary checks here, if any
#### START of preliminary checks #########
##### END of preliminary checks #######
# Handle manual control parameters like start, stop, status, restart, etc.
case "$1" in
start)
# Start daemons.
echo -n $"Starting <myservice> daemon: "
echo
daemon <myservice>
echo
;;
stop)
# Stop daemons.
echo -n $"Shutting down <myservice>: "
killproc <myservice>
echo
# Do clean-up works here like removing pid files from /var/run, etc.
;;
status)
status <myservice>
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit 0
原始来源,这里。