1 #! /bin/bash
2
3 # chkconfig: 35 85 15
4 # description: Nginx is an HTTP(S) server, HTTP(S) reverse
5
6 set -e
7 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
8 DESC="nginx daemon"
9 NAME=nginx
10 DAEMON=/usr/local/nginx/$NAME
11 SCRIPTNAME=/etc/init.d/$NAME
12
13 test -x $DAEMON || exit 0
14
15 d_start(){
16 $DAEMON || echo -n " already running"
17 }
18
19 d_stop() {
20 $DAEMON -s quit || echo -n " not running"
21 }
22
23 d_reload() {
24 $DAEMON -s reload || echo -n " counld not reload"
25 }
26
27 case "$1" in
28 start)
29 echo -n "Starting $DESC:$NAME"
30 d_start
31 echo "."
32 ;;
33 stop)
34 echo -n "Stopping $DESC:$NAME"
35 d_stop
36 echo "."
37 ;;
38 reload)
39 echo -n "Reloading $DESC configuration..."
40 d_reload
41 echo "reloaded."
42 ;;
43 restart)
44 echo -n "Restarting $DESC: $NAME"
45 d_stop
46 sleep 2
47 d_start
48 echo "."
49 ;;
50 *)
51 echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
52 exit 3
53 ;;
54 esac
55
56 exit 0
将第10行nginx执行地址修改一下即可
启动nginx:service nginx start
停止nginx:service nginx stop