[root@localhost init.d]# vi test
#!/bin/bash
#chkconfig: 345 38 83
#description: test
restart(){
/etc/init.d/iptables restart
}
case "$1" in
rest)
restart
;;
*)
echo $"Usage:$0 {rest}"
esac
~
~
~
~
~
~
~
~
~
~
"test" 13L, 202C written
[root@localhost init.d]#chmod +x test.sh
[root@localhost init.d]#cp -a test.sh /etc/init.d/test
[root@localhost init.d]#chkconfig --add test
[root@localhost init.d]# service test rest
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
注释:
1、写好shell;
2、赋予执行权限;
3、复制到/etc/init.d下;
4、添加到服务chkconfig --add test;
5、测试。
chkconfig: 345 38 83 启动在3 4 5三个级别,启动和关闭的需要,在/etc/rc(3~5).d中可以找到:
[root@localhost rc4.d]# pwd
/etc/rc4.d
[root@localhost rc4.d]# ls | grep 38
S38test
[root@localhost rc4.d]# ll | grep test
lrwxrwxrwx. 1 root root 14 Sep 10 11:51 S38test -> ../init.d/test
转载于:https://blog.51cto.com/shouhouzhe/1551243