博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx和PHP-FPM的启动、重启、停止脚本分享(转)
阅读量:6833 次
发布时间:2019-06-26

本文共 4659 字,大约阅读时间需要 15 分钟。

服务器上的Nginx和PHP都是源码编译安装的,不像ubuntu一样有自带service启动脚本,所以不支持类似以前的nginx (start|restart|stop|reload)了。自己动手丰衣足食。以下脚本应该在RHEL, Fedora, CentOS下都适用。

一、Nginx启动脚本/etc/init.d/nginx

 

1 #!/bin/bash  2 #  3 # Startup script for Nginx - this script starts and stops the nginx daemon  4 #  5 # chkconfig:   - 85 15  6 # description:  Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server  7 # processname: nginx  8 # config:      /usr/local/nginx/conf/nginx.conf  9 # pidfile:     /usr/local/nginx/logs/nginx.pid 10   11 # Source function library. 12 . /etc/rc.d/init.d/functions 13   14 # Source networking configuration. 15 . /etc/sysconfig/network 16   17 # Check that networking is up. 18 [ "$NETWORKING" = "no" ] && exit 0 19   20 nginx="/usr/local/nginx/sbin/nginx" 21 prog=$(basename $nginx) 22   23 NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 24   25 [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 26   27 lockfile=/var/lock/subsys/nginx 28   29 start() { 30     [ -x $nginx ] || exit 5 31     [ -f $NGINX_CONF_FILE ] || exit 6 32     echo -n $"Starting $prog: " 33     daemon $nginx -c $NGINX_CONF_FILE 34     retval=$? 35     echo 36     [ $retval -eq 0 ] && touch $lockfile 37     return $retval 38 } 39   40 stop() { 41     echo -n $"Stopping $prog: " 42     killproc $prog -QUIT 43     retval=$? 44     echo 45     [ $retval -eq 0 ] && rm -f $lockfile 46     return $retval 47 } 48   49 restart() { 50     configtest || return $? 51     stop 52     sleep 1 53     start 54 } 55   56 reload() { 57     configtest || return $? 58     echo -n $"Reloading $prog: " 59     killproc $nginx -HUP 60     RETVAL=$? 61     echo 62 } 63   64 force_reload() { 65     restart 66 } 67   68 configtest() { 69   $nginx -t -c $NGINX_CONF_FILE 70 } 71   72 rh_status() { 73     status $prog 74 } 75   76 rh_status_q() { 77     rh_status >/dev/null 2>&1 78 } 79   80 case "$1" in 81     start) 82         rh_status_q && exit 0 83         $1 84         ;; 85     stop) 86         rh_status_q || exit 0 87         $1 88         ;; 89     restart|configtest) 90         $1 91         ;; 92     reload) 93         rh_status_q || exit 7 94         $1 95         ;; 96     force-reload) 97         force_reload 98         ;; 99     status)100         rh_status101         ;;102     condrestart|try-restart)103         rh_status_q || exit 0104             ;;105     *)106         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"107         exit 2108 esac

 

编辑好后保存,执行以下命令

1 sudo chmod +x /etc/init.d/nginx2 sudo /sbin/chkconfig nginx on3 # 检查一下4 sudo /sbin/chkconfig --list nginx5 nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

完成!可以使用以下命令管理Nginx了

1 service nginx start2 service nginx stop3 service nginx restart4 service nginx reload5  6 /etc/init.d/nginx start7 /etc/init.d/nginx stop8 /etc/init.d/nginx restart9 /etc/init.d/nginx reload

 

 

二、PHP-FPM启动脚本/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/localDESC="php-fpm daemon"NAME=php-fpm# php-fpm路径DAEMON=$PHP_PATH/php/sbin/$NAME# 配置文件路径CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf# PID文件路径(在php-fpm.conf设置)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 "$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        ;;esacexit 0

 

编辑好后保存,执行以下命令

1 sudo chmod +x /etc/init.d/php-fpm2 sudo /sbin/chkconfig php-fpm on3 # 检查一下4 sudo /sbin/chkconfig --list php-fpm5 php-fpm           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

完成!可以使用以下命令管理php-fpm了

1 service php-fpm start2 service php-fpm stop3 service php-fpm restart4 service php-fpm reload5  6 /etc/init.d/php-fpm start7 /etc/init.d/php-fpm stop8 /etc/init.d/php-fpm restart9 /etc/init.d/php-fpm reload

 

 

转载地址:http://jetkl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
1.MyBaits 3.2 简介
查看>>
hibernate缓存
查看>>
防火墙侦测一下地址是否有经过
查看>>
Jmeter录制app脚本
查看>>
解决java.lang.RuntimeException: mapped-name is required for xxx.xxx.xxx/xx of deployment xx.war
查看>>
impdp导入数据报错"ORA-39029"处理一例
查看>>
shell脚本--语法篇
查看>>
多态实现原理
查看>>
弱链接和链接期错误
查看>>
CentOS6.3上SSH远程登录实现无密码认证
查看>>
java起源和基本数据类型
查看>>
向Flash传值的两种方式
查看>>
CCNP学习笔记之EIGRP 上
查看>>
九、搭建织梦cms网站
查看>>
我的友情链接
查看>>
linux大于2T的磁盘使用GPT分区方式
查看>>
状态码503 Service Unavailable
查看>>
我的友情链接
查看>>
tshark抓包命令详解
查看>>