Chkconfig添加服务
1. chkconfig脚本格式:
#!/bin/sh
#chkconfig 2345 55 45
#上面为固定格式:2345 表示运行级别,55表示开机执行顺序,45为关机顺序
#description:this is just a demo of chkconfig script
case “$1” in
start)
<start-script>
;;
Stop)
<stop-script>
;;
Status)
Echo <the information you want to display>
;;
*)
Echo “the usage of the script”
Case
2. 然后将脚本保存,并赋予执行权限,再复制到/etc/init.d目录
#chmod a+x <myscript>
#copy <myscript> /etc/init.d
3. 使用chkconfig命令添加成服务
#chkconfig --add <myscript>
#chkconfig --level 35 <myscript > on
#chkconfig --list <myscript>
4. 然后就可以通过service命令管理了
#service <myscript> start | stop | status
5. 下面是我写的一个实例脚本,大家可以参考一些格式:
#!/bin/sh
#chkconfig: 2345 99 99
#description:the script to set the network at run level 2345
IN=eth0
OUT=eth1
HOST_NAME=cluster1.yang.com
INIP=192.168.10.10
OUTIP=192.168.136.10
MASK=255.255.255.0
IP=/sbin/ip
IFC=/sbin/ifconfig
ROUTE=/sbin/route
#flush the address
case "$1" in
start)
#echo "flush the address..."
#$IP addr flush dev eth0
#$IP addr flush dev eth1
echo "set the address..."
$IFC $IN $INIP netmask $MASK up
$IFC $OUT $OUTIP netmask $MASK up
echo "set the hostname..."
hostname $HOST_NAME
echo "set the default gateway..."
$IP route flush all
$ROUTE add default gw 192.168.136.2
echo "finshed!!!"
;;
stop)
echo "flush the network setting..."
$IP addr flush dev eth0
$IP addr flush dev eth1
echo "flush finshed!!!"
;;
status)
echo "hostname is $HOST_NAME"
$IFC eth0
$IFC eth1
;;
*)
echo "requires start,stop or status"
;;
esac
注:如果你的脚本在使用chkconfig添加时报错,请确认脚本里面有chkconfig行(上面的红色部分)