Nginx and PHP-FPM start-up, restart, stop script sharing

Source: Internet
Author: User
Tags stop script

This article mainly introduces Nginx and php-fpm start, restart, stop script sharing, the script contains start, stop, reload, restart and other common management methods, and can join the system service and then use SERVICEM command Management, A friend you need can refer to the following

Both Nginx and PHP on the server are compiled and installed by source code, and do not have a service startup script like Ubuntu, so it is not supported like the previous nginx (Start|restart|stop|reload). Get your hands on your own. The following script should be available under Rhel, Fedora, and CentOS.

First, Nginx startup script/etc/init.d/nginx

#!/bin/bash## Startup script for 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:/usr/loc al/nginx/conf/nginx.conf# pidfile:/usr/local/nginx/logs/nginx.pid # Source function library. /etc/rc.d/init.d/functions # Source Networking configuration: /etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit 0 nginx= "/usr/local/nginx/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/ Usr/local/nginx/conf/nginx.conf "[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx Lockfile=/var/lock/subsys/nginx Start () {[-X $nginx] | | Exit 5 [-F $NGINX _conf_file] | | ex    It 6 echo-n $ "Starting $prog:" Daemon $nginx-C $NGINX _conf_file retval=$? echo [$retval-eq 0] && touch $lockfile return $retval} stop () {echo-n $ "stopping $prog:" Killpro C $prog-quit   Retval=$?    echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {configtest | | return $?    Stop sleep 1 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_status        _q () {rh_status >/dev/null 2>&1} case "$" in start) Rh_status_q && exit 0 $    ;; Stop) rh_status_q | |    Exit 0 $;;    Restart|configtest) \ n; Reload) Rh_status_q | |    Exit 7 $;;    Force-reload) force_reload;;    status) Rh_status;; Condrestart|try-restart) rh_status_q | |    Exit 0;;  *) echo $ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2esac

Save after editing, execute the following command

sudo chmod +x/etc/init.d//sbin//sbin/chkconfig--list Nginxnginx           0: Off   1: Off   2: On    3: On    4: On    5: On    6: Off

Complete! You can use the following command to manage Nginx.

Service Nginx startservice nginx stopservice nginx restartservice nginx Reload/etc/init.d/nginx Start/etc/init.d/nginx s Top/etc/init.d/nginx Restart/etc/init.d/nginx Reload

  Second, php-fpm startup script/etc/init.d/php-fpm

#!/bin/bash## Startup script for the php-fpm server.## chkconfig:345-15# description:php is an html-embedded scriptin G language# processname:php-fpm# config:/usr/local/php/etc/php.ini # Source function library. /etc/rc.d/init.d/functions php_path=/usr/localdesc= "php-fpm daemon" name=php-fpm# php-fpm path daemon= $PHP _path/php/ sbin/$NAME # configuration file path configfile= $PHP _path/php/etc/php-fpm.conf# pid file path (in php-fpm.conf settings) pidfile= $PHP _path/php/var/ run/$NAME. pidscriptname=/etc/init.d/$NAME # Gracefully Exit if the package has been Removed.test-x $DAEMON | | Exit 0 Rh_start () {$DAEMON-y $CONFIGFILE | | echo-n "already Running"} rh_stop () {kill-quit ' cat $PIDFILE ' | | echo  -N "not Running"} rh_reload () {kill-hup ' cat $PIDFILE ' | | echo-n "can ' t Reload"} case "$" in start) echo-n        "Starting $DESC: $NAME" Rh_start echo "."  ;;        Stop) echo-n "stopping $DESC: $NAME" Rh_stop echo "."  ;; Reload) echo-n "reloading $DESC Configuration ... "rh_reload echo" Reloaded. "  ;;        Restart) echo-n "Restarting $DESC: $NAME" rh_stop sleep 1 rh_start echo ".  ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3;; Esacexit 0

Save after editing, execute the following command

sudo chmod +x/etc/init.d/php-fpmsudo/sbin/chkconfig php-fpm on# check sudo/sbin/chkconfig--list php-fpmphp-fpm           0:o FF   1:off   2:on    3:on    4:on    5:on    6:off

Complete! You can use the following command to manage PHP-FPM.

Service php-fpm startservice php-fpm stopservice php-fpm restartservice php-fpm reload/etc/init.d/php-fpm start/etc/ INIT.D/PHP-FPM STOP/ETC/INIT.D/PHP-FPM restart/etc/init.d/php-fpm Reload

  

Nginx and PHP-FPM start-up, restart, stop script sharing

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.