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

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
阅读更多
个人分类: linux
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭