1.准备好启动脚本;/etc/rc.d/startService 如下:
#!/bin/sh
#chkconfig: 2345 99 01
#description: Automates a packet filtering firewall withipchains
#安装程序所在目录
APP_HOME=/usr/local/CommClient/CommInsert
#操作程序的脚本文件
APP_SH=commInsert.sh
###################################
#(函数)启动程序
###################################
start() {
cd $APP_HOME
./APP_SH start
}
###################################
#(函数)停止程序
###################################
stop() {
cd $APP_HOME
./APP_SH stop
}
###################################
#(函数)检查程序运行状态
###################################
status() {
cd $APP_HOME
./APP_SH status
}
###################################
#(函数)打印系统环境参数
###################################
info() {
cd $APP_HOME
./APP_SH info
}
###################################
#读取脚本的第一个参数($1),进行判断
#参数取值范围:{start|stop|restart|status|info}
#如参数不在指定范围之内,则打印帮助信息
###################################
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
'info')
info
;;
*)
echo "Usage: $0 {start|stop|restart|status|info}"
exit 1
esac
exit 0
2.注意:
#!/bin/sh
#chkconfig: 35 99 01
#description: sth about this shell
35 : 就是哪种runlevel下启动
99:在rc3.d和rc5.d下产生S99startService
(越小优先权越高)
01: 在rc0.d,rc1.d,rc2.d,rc4.d,rc6.d下产生K01startService
(越小优先权越高)
S:代表Start
K:代表Kill
3.什么是运行级别
简单的说,运行级就是操作系统当前正在运行的功能级别。这个级别从1到6
,具有不同的功能。
不同的运行级定义如下
# 0 - 停机(千万不能把initdefault 设置为0 )
# 1 - 单用户模式 # s init s = init 1
# 2 - 多用户,没有 NFS
# 3 - 完全多用户模式(标准的运行级)
# 4 - 没有用到
# 5 - X11 多用户图形模式(xwindow)
# 6 - 重新启动 (千万不要把initdefault 设置为6 )
这些级别在/etc/inittab
文件里指定。这个文件是init 程序寻找的主要文件,最先运行的服务是放在/etc/rc.d 目录下的文件。在大多数的Linux 发行版本中,启动脚本都是位于 /etc/rc.d/init.d中的。这些脚本被用ln 命令连接到 /etc/rc.d/rcn.d 目录。(这里的n 就是运行级0-6)