Nginx and PHP-FPM restart script on the server Nginx and PHP are source code compilation and installation, does not support class & #20284; the previous nginx (start | restart | stop | reload. Self-help clothes and food. The following scripts are applicable to RHEL, Fedora, and CentOS. I. Nginx startup script etcinit. dnginx #! Binbash # St Nginx and PHP-FPM startup/restart script
Nginx and PHP on the server are both compiled and installed by source code. they do not support nginx (start | restart | stop | reload. Self-help clothes and food. The following scripts are applicable to RHEL, Fedora, and CentOS.
I. Nginx startup script/etc/init. d/nginx
#! /Bin/bash
#
# Startup script for Nginx-this script starts and stops the nginxdaemon
#
# Chkconfig: -8515
# Description:Nginx is an 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 is up.
["$ NETWORKING" = "no"] & exit0
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/null2> & 1
}
Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"
Exit 2
Esac
#===================================================== ======================================
Save the edited file and run the following command:
Sudo chmod + x/etc/init. d/nginxsudo/sbin/chkconfig nginx on # check sudo/sbin/chkconfig -- list nginxnginx 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Done! Run the following command to manage Nginx:
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
2. PHP-FPM startup script/etc/init. d/php-fpm
#! /Bin/bash
#
# Startup script for the PHP-FPM server.
#
# Chkconfig: 345 85 15
# Description: PHP is an 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 (in php-fpm.conf settings)
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 "$1" 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 the edited file and run 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: off 1: off 2: on 3: on 4: on 5: on 6: off! You can use the following command to manage service php-fpm in 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
Note: The program path must be correct. the default path is used here! For php-fpm, the default pid file is not set. to use this file, you must first enable the pid file in the configuration file !~