nginx管理脚本用于nginx启动、停止、重新启动,并添加为linux服务,像启动linux下的服务一样方便
使用方法:将脚本放至/etc/init.d/目录下并执行
- ll /etc/init.d/nginx
- chkconfig --add nginx
- chkconfig --list | grep nginx
- service nginx restart
文章底部附脚本下载地址!(注意脚本中的变量NGINX_HOME,修改为自己环境中的nginx安装目录)
- #!/bin/bash
- #
- # nginx.sh This shell this use to crontal nginx.
- #
- # chkconfig: 345 85 15
- #
- # description: this shell this use to crontal nginx. E.g nginx start stop restart reload..
- #
- #write by clairelume@gmail.com QQ:30879223
- #Date:20110425
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "$NETWORKING" = "no" ] && exit 0
- NGINX_HOME=/data/soft/nginx
- NGNIX_CONF=${NGINX_HOME}/conf/nginx.conf
- NGINX_PID_FILE=${NGINX_HOME}/logs/nginx.pid
- NGINX_BIN=${NGINX_HOME}/sbin/nginx
- NGINX_NAME=$(basename ${NGINX_BIN})
- lockfile=/var/lock/subsys/nginx
- function start(){
- echo -n "start Nginx ..."
- [ -x $nginx ] || echo "Nginx no permit"
- daemon ${NGINX_BIN}
- RETVAL=$?
- [ $RETVAL -eq 0 ] && touch $lockfile
- echo
- return $RETVAL
- }
- function stop(){
- echo -n "stop Nginx..."
- killproc $NGINX_NAME
- RETVAL=$?
- [ $RETVAL -eq 0 ] && (rm -f $lockfile ; rm -f ${NGINX_PID_FILE})
- echo
- return $RETVAL
- }
- function restart(){
- stop
- start
- }
- function checkconfig(){
- echo "checking Nginx config ..."
- ${NGINX_BIN} -t
- }
- function reload(){
- echo "reload the Nginx config..."
- killproc ${NGINX_NAME} -HUP
- RETVAL=$?
- return $RETVAL
- }
- function _ngstatus(){
- status -p ${NGINX_PID_FILE} ${NGINX_NAME}
- }
- function showhelp(){
- echo "Usage: /etc/init.d/nginx {start|stop|restart|status|checkconfig|reload}"
- }
- case $1 in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- restart
- ;;
- reload)
- reload
- ;;
- status)
- _ngstatus
- ;;
- checkconfig)
- checkconfig
- ;;
- *)
- showhelp
- ;;
- esac
效果如下图:
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog