Nginx and PHP-FPM Start, restart, stop script sharing _linux shell

Source: Internet
Author: User
Tags chmod fpm stop script

The Nginx and PHP on the server are compiled and installed by source code, unlike Ubuntu, which has its own service startup script, so it does not support similar previous nginx (Start|restart|stop|reload). Get plenty of hands on yourself. The script should be in Rhel, Fedora, CentOS under all applicable.

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

Copy Code code as follows:

#!/bin/bash
#
# Startup script for Nginx-this script starts and stops the Nginx daemon
#
# Chkconfig:-85 15
# Description:nginx is a HTTP (s) server, HTTP (s) reverse proxy and IMAP/POP3 proxy server
# Processname:nginx
# config:/usr/local/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] | | Exit 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:"
Killproc $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)
$
;;
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 2
Esac

Save after editing and execute the following command
Copy Code code as follows:

sudo chmod +x/etc/init.d/nginx
Sudo/sbin/chkconfig Nginx on
# Check it out #
Sudo/sbin/chkconfig--list Nginx
Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Complete! You can use the following command to manage Nginx
Copy Code code as follows:

Service Nginx Start
Service Nginx Stop
Service Nginx Restart
Service Nginx Reload

/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx Reload

Second, php-fpm startup script/etc/init.d/php-fpm
Copy Code code as follows:

#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig:345 85 15
# description:php is a html-embedded scripting language
# PROCESSNAME:PHP-FPM
# config:/usr/local/php/etc/php.ini

# Source function library.
. /etc/rc.d/init.d/functions

Php_path=/usr/local
desc= "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 (set in php-fpm.conf)
pidfile= $PHP _path/php/var/run/$NAME. pid
Scriptname=/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
;;
Esac
Exit 0

Save after editing and execute the following command
Copy Code code as follows:

sudo chmod +x/etc/init.d/php-fpm
Sudo/sbin/chkconfig PHP-FPM on
# Check it out #
Sudo/sbin/chkconfig--list PHP-FPM
PHP-FPM 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Complete! You can use the following command to manage PHP-FPM
Copy Code code as follows:

Service PHP-FPM Start
Service PHP-FPM Stop
Service PHP-FPM Restart
Service 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

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.