-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnginxConsole
executable file
·58 lines (50 loc) · 1.03 KB
/
nginxConsole
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
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
# 设置环境变量
RPATH=`realpath $0 | xargs dirname`
# 设置服务名称
SVRNAME="nginx"
SVRBIN=/usr/sbin/${SVRNAME}
USAGE="Usage: $0 {start|stop|restart}"
if [[ $# -ne 1 ]]; then
echo $USAGE
exit 1
fi
SVRCONF="/opt/script/nginx/nginx.conf"
#SVRCONF="-c /etc/nginx/nginx.conf"
DAEMON="start-stop-daemon --start -m --exec $SVRBIN --pidfile /tmp/${SVRNAME}.pid --background -- -c $SVRCONF"
if [[ ! -e $SVRCONF ]]; then
echo "$SVRCONF is not exist"
exit 1
fi
do_start()
{
echo $DAEMON
$DAEMON
echo "started $SVRNAME service"
}
do_stop()
{
ps -ef | grep "nginx" | grep -v "grep" | awk '{print $2}' | while read pid
do
echo "PID:" $pid
kill -9 $pid
done
echo "stopped $SVRNAME service"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
sleep 1s
do_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac