Configure shell script for nginx startup in linux

Source: Internet
Author: User

1. Added the shell script vi/etc/rc. d/init. d/nginx.

The code is as follows: Copy code
#! /Bin/bash
# Chkconfig: 35 85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse
Set-e
PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC = "nginx daemon"
NAME = nginx
DAEMON =/usr/local/nginx/sbin/$ NAME
SCRIPTNAME =/etc/init. d/$ NAME
Test-x $ DAEMON | exit 0
D_start (){
$ DAEMON | echo-n "already running"
}
D_stop (){
$ DAEMON-s quit | echo-n "not running"
}
D_reload (){
$ DAEMON-s reload | echo-n "counld not reload"
}
Case "$1" in
Start)
Echo-n "Starting $ DESC: $ NAME"
D_start
Echo "."
;;
Stop)
Echo-n "Stopping $ DESC: $ NAME"
D_stop
Echo "."
;;
Reload)
Echo-n "Reloading $ DESC configuration ..."
D_reload
Echo "reloaded ."
;;
Restart)
Echo-n "Restarting $ DESC: $ NAME"
D_stop
Sleep 2
D_start
Echo "."
;;
*)
Echo "Usage: $ SCRIPTNAME {start | stop | restart | reload}"> & 2
Exit 3
;;
Esac
Exit 0

2. Just add shell to the system service.

The code is as follows: Copy code

Chmod + x/etc/rc. d/init. d/nginx (set executable permissions)

Chkconfig -- add nginx (add system service)

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.