Debian下设置Shell脚本开机自动启动

来源:互联网 发布:ps裁切快捷键 mac 编辑:程序博客网 时间:2024/06/05 16:30

Debian下设置Shell脚本开机自动启动


1) 进入init.d初始化脚本目录


#切换到root用户
sudo -s
cd /etc/init.d

2) 创建启动Shell脚本,安装nano: apt-get install nano


nano /etc/init.d/footbar

3) 编写Node.JS启动脚本,以OnceDoc启动脚本为例


#! /bin/sh
### BEGIN INIT INFO
# Provides: OnceDoc
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop node
# Description: OnceDoc
### END INIT INFO
WEB_DIR='/var/www/oncedoc'
WEB_APP='svr/service.js'
#location of node you want to use
NODE_EXE=/usr/local/bin/node
start()
{
echo "Start OnceDoc"
#important! change current folder, in order to make the relative path work.
cd $WEB_DIR
#make sure it will running forever and error will be logged
$NODE_EXE $WEB_DIR/$WEB_APP svr/oncedoc.js config.guoxiehui.js &
}
stop()
{
echo "This program cann't be stopped"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
#start
;;
*)
echo "Usage: /etc/init.d/ourjs {start|stop|restart}"
;;
esac
exit 0

4) 设置文件为可执行脚本


chmod 755 /etc/init.d/foobar

5) 设置脚本开机时启动


update-rc.d foobar defaults

7) 设置脚本开机时不启动[可选]


update-rc.d -f foobar remove

8) 重启测试


reboot
0 0
原创粉丝点击