项目
Linux中nginx服务器启动脚本,将此脚本放入/etc/init.d/目录下,进行启动和关闭,并用chkconfig命令将nginx加入到chkconfig管理中,设置开机自启动。
详细脚本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/bin/bash
#author wangning
#date 2017-7-14
#qq 1198143315
#Email 1198143315@qq.com
[ -f
/etc/init
.d
/functions
] && .
/etc/init
.d
/functions
#chkconfig: 2345 46 78
#description: nginx service manage
#################define variable################################################
num=`
ps
-ef|
grep
worker|
grep
-
v
grep
|
wc
-l`
nginx=
/application/nginx/sbin/nginx
########################start stop restart reload functions##########################
nginx_start(){
if
[ $num -gt 5 ];
then
echo
"the nginx service has running"
exit
1
else
$nginx &>
/dev/null
action
"start nginx"
/bin/true
fi
}
nginx_stop(){
if
[ $num -lt 5 ];
then
echo
"the nginx service has stoped"
exit
2
else
$nginx -s stop
action
"stop nginx"
/bin/true
fi
}
nginx_restart(){
$nginx -s stop
$nginx
action
"restart nginx"
/bin/true
}
nginx_reload(){
$nginx -s reload
action
"reload nginx"
/bin/true
}
#########################nginx manage###########################################
case
$1
in
start)
nginx_start
;;
stop)
nginx_stop
;;
restart)
nginx_restart
;;
reload)
nginx_reload
;;
*)
echo
"USAGE:$0 {start|stop|restart|reload}"
esac
|
本文转自 茁壮的小草 51CTO博客,原文链接:http://blog.51cto.com/wn2100/1947817,如需转载请自行联系原作者