我正在使用运行Raspbian的树莓派上运行Node.js应用程序,并尝试在树莓派启动时启动它。我找到了一些例子,但好像无法使其正常工作。我的当前代码如下:
#! /bin/sh
# /etc/init.d/MyApp
### BEGIN INIT INFO
# Provides: MyApp.js
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts MyApp.js
# Description: Start / stop MyApp.js at boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting MyApp.js"
# run application you want to start
node /home/pi/app/MyApp/MyApp.js
;;
stop)
echo "Stopping MyApp.js"
# kill application you want to stop
killall MyApp.js
;;
*)
echo "Usage: /etc/init.d/MyApp {start|stop}"
exit 1
;;
esac
exit 0
我把脚本放在 etc/init.d 文件夹下,并运行了 chmod +x /etc/init.d/MyApp
命令,能够手动运行脚本,在运行了sudo update-rc.d MyApp defaults
命令后重启,但脚本从未运行。我查看了一些不同的示例,做出了一些调整,但仍然没有成功。
>> &
是什么意思?它对我来说会导致错误。 - JeffThompson