CentOS under Nginx startup script and Chkconfig management

Source: Internet
Author: User
After installing Nginx, restarting requires "kill-hup Nginx process number" to reload, obviously very inconvenient. It's much easier to manage it directly from a script, just like Apache.

Nginx official long thought, also provided this script, address: Http://wiki.nginx.org/RedHatNginxInitScript. Here are the management scripts that are included here:

#!/bin/sh## nginx-this script starts and stops the Nginx daemon## chkconfig:-15# Description:nginx is an HTTP (S ) server, HTTP (S) Reverse \# Proxy and imap/pop3 proxy server# processname:nginx# config:/etc/nginx/n ginx.conf# config:/etc/sysconfig/nginx# pidfile:/var/run/nginx.pid # Source function library. /etc/rc.d/init.d/functions # Source Networking configuration: /etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit0 nginx= "/usr/sbin/nginx" prog=$ (Basename$nginx) nginx_c/etc/nginx/nginx.conf "[ -f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx Lockfile=/var/lock/subsys/nginx Make_dirs () {# Make required directories user= ' $nginx-v 2> &1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-' if[-Z ' grep $user/etc/passwd ']; Then useradd-m-s/bin/nologin$user fi opti-v 2>&1 | grep ' Configure arguments: ' foropt in$options; Do if['echo$opt | grep '. *-temp-path ']; Then value= ' echo$opt | Cut-d "="-F 2 ' if[!-d "$value"];       Then # echo "Creating" $value mkdir-p $value && chown-r $user $value fi Fi done} start () {[-X $nginx] | | exit5 [-f $NGINX _conf_file] | | exit6 make_dirs echo-n $ "Starting $p    Rog: "Daemon $nginx-C $NGINX _conf_file retval=$? echo [$retval-eq0] && touch$lockfile return$retval} stop () {echo-n $ "stopping $prog:" Killproc $    Prog-quit retval=$?    echo [$retval-eq0] && rm-f $lockfile Return$retval} restart () {configtest | | return$?    Stop SLEEP1 Start} reload () {configtest | | return$?    Echo-n $ "Reloading $prog:" Killproc $nginx-hup retval=$? echo} force_reload () {restart} configtest () {$nginx-T-c $NGINX _conf_file} rh_status () {Status $prog} Rh_st Atus_q () {rh_status >/dev/null2>&1} case "$" in StART) rh_status_q && exit0 $;; Stop) rh_status_q | |    Exit0 $;;    Restart|configtest) \ n; Reload) Rh_status_q | |    Exit7 $;;    Force-reload) force_reload;;    status) Rh_status;; Condrestart|try-restart) rh_status_q | |    Exit0;; *) echo$ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" Exit2 Esac

Save the above script to the/etc/init.d/nginx file and modify the two places:

  • nginx= "/usr/sbin/nginx" to modify the path of the Nginx execution program.
  • Nginx_c/etc/nginx/nginx.conf "modifies the path to the configuration file.
  • Once saved, the Nginx service can be managed by this script:

    $/etc/init.d/nginx start$/etc/init.d/nginx stop$/etc/init.d/nginx Reload ... Using Chkconfig for Management

    The above method has completed the function of using script to manage Nginx service, but it is still not very convenient, such as setting nginx boot up and so on. You can use Chkconfig to set this.

    Add Nginx service to Chkconfig management list first:

    Chkconfig--add/etc/init.d/nginx After adding this, you can use the service to start, restart, and so on Nginx operation.

    $ service Nginx start$ service nginx stop$ service Nginx reload ... set terminal mode boot:

    $ chkconfig--level 3 nginx on

    From:http://www.01happy.com/centos-nginx-shel l-chkconfig/

    Above describes the CentOS startup script and Chkconfig management, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.