Linux under Nginx start stop restart control script

Source: Internet
Author: User

This is a script file that controls Nginx services, including the control of Nginx startup, restart, stop, smooth restart, and the amount of configuration file checks.

[email protected] ~]# cat nginx.sh

#!/bin/env Bash

# Description:nginx Server # # #必须加描述

# Nginx-this script is used to control Nginx service

# processname Nginx

# Chkconfig:-85 15

# Edit by Sun

# date 2014-07-03

# email address [email protected]


nginx= "/usr/local/nginx/sbin/nginx"

Prog= "Nginx"

Conf_file= "/usr/local/nginx/conf/nginx.conf"


Start () {

If [' Pgrep $prog | wc-l '-eq 0];then

If [-X $nginx] && [-F $conf _file];then

$nginx-C $conf _file

Ret=$?

If [$ret-eq 0];then

echo "$prog start successed"

Else

echo "$prog start Failed"

Fi

Else

echo "$prog config file not exist"

Fi

Else

echo "$prog is already started ... "

Fi

}


Stop () {

If [' Pgrep $prog | wc-l '-ne 0];then

Killall-9 $prog

Ret=$?

If [$ret-eq 0];then

echo "$prog Stop successed"

Else

echo "$prog stop failed"

Fi

Else

echo "$prog is already stopped ..."

Fi

}


Restart () {

Stop

Sleep 2

Start

}


Reload () {

If [' Pgrep $prog | wc-l '-ne 0];then

Pid= ' Ps-ef | grep $prog | grep Master | awk ' {print $} '

If [-X $nginx] && [-F $conf _file];then

Kill-hup $pid

Ret=$?

If [$ret-eq 0];then

echo "$prog Reload successed"

Else

echo "$prog Reload Failed"

Fi

Else

echo "$prog config file is not exist"

Fi

Else

echo "$prog is stopped, please start $prog first ..."

Fi

}


Check () {

If [-X $nginx] && [-F $conf _file];then

$nginx-T-C $conf _file

Ret=$?

If [$ret-eq 0];then

echo "$prog Check successed"

Else

echo "$prog check Failed"

Fi

Fi

}


Case $ in

Start

Start

;;

Stop

Stop

;;

Restart

Restart

;;

Reload

Reload

;;

Check

Check

;;

*)

echo "Usage: $ {Start|stop|restart|reload|check}"

Esac

Run bash nginx.sh start, and so on.

This article from "Personal Feelings" blog, declined reprint!

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.