需求
将开发的程序在Linux服务器上设置开机启动
编写脚本test放在/etc/init.d目录下,内容如下:
#!/bin/bash
#chkconfig:2345 80 90
#description:just for test
start()
{
/opt/test &
}
stop()
{
killall -9 test
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring test"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
说明:第二行和第三行主要是提供给chkconfig可执行程序来读取分析,2345说明程序在哪种运行级下运行,80是启动的等级(数字越大越晚启动,一般情况考虑到是否依赖其他的服务),90是停止的等级
编写完成脚本
1)注册成为服务
chkconfig --add test
2)查看所有的注册服务
chkconfig --list
3)删除服务
chkconfig --del test