Centos下Nginx自启动脚本
01 www.zhishiwu.com
#!/bin/bash
02
#ckconfig: 345 40 40
03
NGINX_PATH=/web/container/nginx-1.2.6
04
NGINX_COMMAND=$NGINX_PATH/sbin/nginx
05
NGINX_PID=$NGINX_PATH/logs/nginx.pid
06
VERSION=1.2.6
07
CONF=$2
08
09
start()
10
{
11
if [ -f $NGINX_PID ];
12
then
13
echo "[Failure] Nginx is starting"
14
else
15
echo "[Success] Starting Nginx $VERSION"
16
#用户设置好后统一使用同一个用户操作
17
#/bin/su - nginx -c "$NGINX_PATH/nginx $CONF 1>/dev/null 2>/dev/null"
18
$NGINX_COMMAND $CONF 1>/dev/null 2>/dev/null
19
fi
20
}
21
22
stop()
23
{
24
echo $NGINX_PID
25
if [ -f $NGINX_PID ];
26
then
27
echo "[Success] Stopping Nginx $VERSION"
28
$NGINX_COMMAND -s quit
29
#/bin/kill -QUIT $(eval "/bin/cat $NGINX_PID")
30
else
31
echo "[Failure] Stop Failure. Nginx isn't starting "
32
fi
33
}
34
35
reload()
36
{
37
if test -f $NGINX_PID;
38
then
39
echo "[Success] Reloading Nginx $VERSION"
40
$NGINX_COMMAND -s reload
41
else
42
echo "[Failure] Reload Failure. Nginx isn't starting "
43
fi
44
}
45
46
out()
47
{
48
if test -f $NGINX_PID;
49
then
50
echo "[Success] Exiting Nginx $VERSION"
51
$NGINX_COMMAND -s stop
52
#/bin/kill -9 $(eval "/bin/cat $NGINX_PID")
53
else
54
echo "[Failure] Exiting Failure . Nginx isn't starting "
55
fi
56
}
57
58
case "$1" in
59
start)
60
start
61
;;
62
stop)
63
stop
64
65
;;
66
restart)
67
68
stop
69
sleep 3
70
start
71
;;
72
exit)
73
out
74
;;
75
reload)
76
reload
77
;;
78
*)
79
echo $"Usage: $0 {start|stop|restart|exit|reload}"
80
exit 1
81
;;
82
esac
83
exit 0
保存文件为nginx,然后输入(假设在/web 目录下)
mv /web/nginx /etc/init.d
回车
cd /etc/init.d
chkconfig --add ./nginx
回车
chkconfig nginx on
回车
/sbin/service nginx start
然后reboot 看看即可.