脚本思路:仿照httpd的启动脚本,稍加修改即可。
注:省去了创建pid文件这一步。
脚本
#!/bin/sh # # nginx - this script starts and stops the nginx daemin # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse# proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 ETVAL=0nginx=/usr/local/nginx/sbin/nginxprog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"#lockfile="/var/lock/subsys/nginx "start() { echo -n $"Starting $prog: " daemon $nginx RETVAL=$? echo [ $RETVAL = 0 ] return $RETVAL} stop() { echo -n $"Stopping $prog: " killall $nginx RETVAL=$? echo [ $RETVAL = 0 ]}reload() { echo -n $"Reloading $prog: " if ! $nginx -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $nginx due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killall $nginx -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo}# See how we were called.case "$1" in start) start ;; stop) stop ;; status) status $prog RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status $prog >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $nginx -h RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2esacexit $RETVAL