chkconfig: 345 85 15 (这个比较有意思,345代表在设置在那个level中是on的,如果一个都不想on,那就写一个横线"-",比如:chkconfig: - 85 15。后面两个数字当然代表S和K的默认排序号啦)都在/etc/rc(0~6).d 中的S85tomcat K15tomc
#!/bin/bash
#chkconfig: 2345 96 14
. /etc/init.d/functions
start(){
if [ -f /usr/local/nginx/logs/nginx.pid ]
then
echo_failure
echo "nginx is running"
else
/usr/local/nginx/sbin/nginx
echo_success
echo
fi
}
stop(){
if [ -f /usr/local/nginx/logs/nginx.pid ]
then
/usr/local/nginx/sbin/nginx -s stop
echo_success
echo
else
echo "nginx is stop"
echo_failure
echo
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Useage: $0 |start|stop|restart"
esac
[root@wangying2 ~]#
[root@wangying2 ~]# bash nginx.sh restart
[root@wangying2 ~]# vim nginx.sh [ 确定 ]
[root@wangying2 ~]# bash nginx.sh restart
[ 确定 ]
[root@wangying2 ~]# bash nginx.sh start
nginx is running [失败]
[root@wangying2 ~]# bash nginx.sh stop
[root@wangying2 ~]# bash nginx.sh start
[ 确定 ]
[root@wangying2 ~]#
[root@wangying2 ~]# vim nginx.sh
[root@wangying2 ~]# bash nginx.sh start
nginx is running [失败]
[root@wangying2 ~]# bash nginx.sh stop
[ 确定 ]
[root@wangying2 ~]# bash nginx.sh stop
nginx is stop
[失败]
将写的脚本加入开机自启的服务中
[root@wangying2 ~]# chmod a+x nginx.sh 给脚本添加权限
[root@wangying2 ~]# cp -p nginx.sh /etc/init.d/nginx 将shell脚本复制到开启自启文件夹中
[root@wangying2 ~]# chkconfig --add nginx 将nginx加入到开机启动的服务中
[root@wangying2 ~]# systemctl daemon-reload 将开启自启的服务重载
[root@wangying2 ~]# systemctl start nginx
[root@wangying2 ~]# systemctl stop nginx
[root@wangying2 ~]# systemctl status nginx
● nginx.service - (null)
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: inactive (dead) since 五 2018-10-12 18:18:35 CST; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 12495 ExecStop=/etc/rc.d/init.d/nginx stop (code=exited, status=0/SUCCESS)
Process: 12480 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
10月 12 18:18:29 wangying2 systemd[1]: Starting (null)...
10月 12 18:18:29 wangying2 nginx[12480]: [ 确定 ]
10月 12 18:18:29 wangying2 systemd[1]: Started (null).
10月 12 18:18:35 wangying2 systemd[1]: Stopping (null)...
10月 12 18:18:35 wangying2 nginx[12495]: [ 确定 ]
10月 12 18:18:35 wangying2 systemd[1]: Stopped (null).
[root@wangying2 ~]#
注意点:
[root@wangying2 ~]# cat ping.sh
#!/bin/bash
for i in {0..255}
do
for j in {0..255}
do
if [ $i -eq 0 -a $j -eq 0 ] || [ $i -eq 255 -a $j -eq 255 ]
then
continue
else
( if /usr/bin/ping -c 1 172.25.$i.$j &> /dev/null
then
echo "172.25.$i.$j is ok"
fi ) &
fi
done
done
[root@wangying2 ~]#