原碼安裝nginx,啓動腳本和加入開機自啓

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 ~]#

[root@wangying2 ~]# chmod a+x ping.sh
[root@wangying2 ~]# cp ping.sh /etc/init.d/ping
[root@wangying2 ~]# chkconfig --add ping
服務 ping 不支持 chkconfig
[root@wangying2 ~]#
當腳本文件中沒有
#chkconfig: 2345 96 14 這條語句解釋時,就會出現上面的問題

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章