#! /Bin/sh # Chkconfig: 2345 55 25 # Description: Startup script for nginx webserver on Debian. Place in/etc/init. d and # Run 'UPDATE-rc. d-f nginx defaults', or use the appropriate command on your # Distro. For CentOS/Redhat run: 'chkconfig-add nginx' ### BEGIN INIT INFO # Provides: nginx # Required-Start: $ all # Required-Stop: $ all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server # Description: starts nginx using start-stop-daemon ### END INIT INFO # Author: licess # Website: http://lnmp.org PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME = nginx NGINX_BIN =/usr/local/nginx/sbin/$ NAME CONFIGFILE =/usr/local/nginx/conf/$ NAME. conf PIDFILE =/usr/local/nginx/logs/$ NAME. pid Case "$1" in Start) Echo-n "Starting $ NAME... " If netstat-tnpl | grep-q nginx; then Echo "$ NAME (pid 'pidof $ name') already running ." Exit 1 Fi $ NGINX_BIN-c $ CONFIGFILE If ["$ ?" ! = 0]; then Echo "failed" Exit 1 Else Echo "done" Fi ;; Stop) Echo-n "Stoping $ NAME... " If! Netstat-tnpl | grep-q nginx; then Echo "$ NAME is not running ." Exit 1 Fi $ NGINX_BIN-s stop If ["$ ?" ! = 0]; then Echo "failed. Use force-quit" Exit 1 Else Echo "done" Fi ;; Status) If netstat-tnpl | grep-q nginx; then PID = 'pidof nginx' Echo "$ NAME (pid $ PID) is running... " Else Echo "$ NAME is stopped" Exit 0 Fi ;; Force-quit) Echo-n "Terminating $ NAME... " If! Netstat-tnpl | grep-q nginx; then Echo "$ NAME is not running ." Exit 1 Fi Kill 'pidof $ name' If ["$ ?" ! = 0]; then Echo "failed" Exit 1 Else Echo "done" Fi ;; Restart) $0 stop Sleep 1 $0 start ;; Reload) Echo-n "Reload service $ NAME... " If netstat-tnpl | grep-q nginx; then $ NGINX_BIN-s reload Echo "done" Else Echo "$ NAME is not running, can't reload ." Exit 1 Fi ;; Configtest) Echo-n "Test $ NAME configure files... " $ NGINX_BIN-t ;; *) Echo "Usage: $0 {start | stop | force-quit | restart | reload | status | configtest }" Exit 1 ;; |