Shell Script-Nginx startup script

Source: Internet
Author: User

Os:centos/redhat Series

and tested properly on CentOS 6.7 and CentOS 7.2

#!/bin/bash## auth:daxin# time:2018/07/10## nginx start Nginx Web server# # chkconfig:-90# Description:start, S Tops and reload Nginx Web server## config:/usr/local/nginx/conf/nginx.conf# config:/usr/local/nginx/conf/vhosts#### BEGIN INIT info# provides:nginx# required-start:# required-stop:# default-start:3# default-stop: # short-description:st Art and Stop Nginx Web server# description:start, stop and reload Nginx Web server### END INIT info# Source function Libr ary. /etc/init.d/functionsnginx_dir= "/usr/local/nginx" nginx= "${nginx_dir}/sbin/nginx" NGINX_CONF= "${NGINX_DIR}/conf/ Nginx.conf "prog=$ (basename $NGINX) lock_file=" ${nginx_dir}/${prog}.lock "# check Command existsif [!-x ${nginx}]; Then echo-n $ "${nginx} does not exists."; Warning    Echo Exit 5fifunction Start () {[-F $NGINX _conf] | | Exit 6 $NGINX-C $NGINX _conf retval=$? If [$retval-eq 0]; Then touch $LOCK _file action "starting $PROG"/bin/true Else Action "Starting $PROG "/bin/false fi return $retval}function stop () {Pkill $PROG retval=$? If [$retval-eq 0];    Then rm-f $LOCK _file action "Stop $PROG"/bin/true else Action "Stop $PROG"/bin/false fi  return $retval}function restart () {configtest_q | | Return 6 STOP start}function reload () {Configtest_q | |     Return 6 nginx_main_process=$ (ps aux | grep $NGINX | grep-v grep | awk ' {print $} ') Kill-hup $nginx _main_process    Retval=$? If [$retval-eq 0]; Then action "Reload $PROG"/bin/true else Action "Reload $PROG"/bin/false fi return $retval}functi  On Configtest_q () {$NGINX-T-C $NGINX _conf}function status () {nginx_main_process=$ (ps aux | grep $NGINX | grep-v grep | awk ' {print $} ') if [-Z $nginx _main_process];    Then action "$PROG are not running"/bin/false else Action "$PROG is runing"/bin/true fi}case "$" in    Start) Start; Stop) stop       ;;    reload) reload;;    restart) restart;;    Configtest) configtest_q;;    status) status;   *) echo $ "Usage: $ Start|stop|reload|configtest|status|restart}" Exit 2esac

  

Shell Script-Nginx startup script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.