Skip to content

Commit 6f36952

Browse files
committed
Ubuntu 16.04.2 LTS
1 parent 2149e14 commit 6f36952

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

Nginx/nginx-start-script.md

+58-31
Original file line numberDiff line numberDiff line change
@@ -629,40 +629,67 @@
629629
630630
```javascript
631631
#!/bin/sh
632-
unalias stop
633-
NGINX_CMD="/usr/local/openresty/nginx/sbin/nginx"
634-
NGINX_CONF="/usr/local/openresty/nginx/conf/nginx.conf"
635-
RETVAL=0
636-
start() {
637-
echo "Starting NGINX Web Server: \c"
638-
$NGINX_CMD -c $NGINX_CONF &
639-
RETVAL=$?
640-
[ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
641-
return $RETVAL
642-
}
643-
stop() {
644-
echo "Stopping NGINX Web Server: \c"
645-
$NGINX_CMD -s quit
646-
RETVAL=$?
647-
[ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
648-
return $RETVAL
649-
}
632+
633+
### BEGIN INIT INFO
634+
# Provides: nginx
635+
# Required-Start: $all
636+
# Required-Stop: $all
637+
# Default-Start: 2 3 4 5
638+
# Default-Stop: 0 1 6
639+
# Short-Description: starts the nginx web server
640+
# Description: starts nginx using start-stop-daemon
641+
### END INIT INFO
642+
643+
PATH=/opt/bin:/opt/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
644+
DAEMON=/usr/local/openresty/nginx/sbin/nginx
645+
NAME=nginx
646+
DESC=nginx
647+
648+
test -x $DAEMON || exit 0
649+
650+
# Include nginx defaults if available
651+
if [ -f /etc/default/nginx ] ; then
652+
. /etc/default/nginx
653+
fi
654+
655+
set -e
656+
650657
case "$1" in
651-
start)
652-
start
653-
;;
654-
stop)
655-
stop
656-
;;
657-
restart)
658-
stop
659-
start
658+
start)
659+
echo -n "Starting $DESC: "
660+
start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid \
661+
--exec $DAEMON -- $DAEMON_OPTS
662+
echo "$NAME."
663+
;;
664+
stop)
665+
echo -n "Stopping $DESC: "
666+
start-stop-daemon --stop --quiet --pidfile /var/run/nginx.pid \
667+
--exec $DAEMON
668+
echo "$NAME."
669+
;;
670+
restart|force-reload)
671+
echo -n "Restarting $DESC: "
672+
start-stop-daemon --stop --quiet --pidfile \
673+
/var/run/nginx.pid --exec $DAEMON
674+
sleep 1
675+
start-stop-daemon --start --quiet --pidfile \
676+
/var/run/nginx.pid --exec $DAEMON -- $DAEMON_OPTS
677+
echo "$NAME."
678+
;;
679+
reload)
680+
echo -n "Reloading $DESC configuration: "
681+
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/nginx.pid \
682+
--exec $DAEMON
683+
echo "$NAME."
660684
;;
661-
*)
662-
echo "Usage: $0 {start|stop|restart}"
663-
exit 1
685+
*)
686+
N=/etc/init.d/$NAME
687+
echo "Usage: $N {start|stop|restart|force-reload}" >&2
688+
exit 1
689+
;;
664690
esac
665-
exit $RETVAL
691+
692+
exit 0
666693
```
667694
+ CP到默认开启的服务脚本:
668695

0 commit comments

Comments
 (0)