Home >Backend Development >PHP Tutorial >php-fpm自启脚本

php-fpm自启脚本

WBOY
WBOYOriginal
2016-06-20 12:44:111124browse

觉得手动操作php-fpm挺麻烦的,自己试着写一个脚本实现开机自启,实现了自己想要的效果。


1、脚本

#!/bin/bash#chkconfig: 2345 80 80 #description: auto start php-fpmdaemon=/usr/local/php/sbin/php-fpmcase $1 in    'start')     proc_id=`echo $(netstat -lnutp | grep php-fpm) | gawk '{print $7}' | gawk 'BEGIN{FS="/"}{print $1}'` >/dev/null 2>&1     if [ ! "$proc_id" = "" ]     then         echo "php-fpm is running!"     else         if [ `$daemon` ]         then             echo "php-fpm not stard."         else             echo "php-fpm stard."         fi     fi     ;;     'stop')     proc_id=`echo $(netstat -lnutp | grep php-fpm) | gawk '{print $7}' | gawk 'BEGIN{FS="/"}{print $1}'` >/dev/null 2>&1     if [ ! "$proc_id" = ""  ]     then         kill -TERM $proc_id         echo "php-fpm stopd."     else         echo "php-fpm not running,do not anything."     fi     ;;     'restart')     proc_id=`echo $(netstat -lnutp | grep php-fpm) | gawk '{print $7}' | gawk 'BEGIN{FS="/"}{print $1}'` #>/dev/null 2>&1     if [ ! "$proc_id" = ""  ]     then         kill -TERM $proc_id         echo "php-fpm stopd."     else         echo "php-fpm not running,do not anything."     fi     sleep 5     proc_id=`echo $(netstat -lnutp | grep php-fpm) | gawk '{print $7}' | gawk 'BEGIN{FS="/"}{print $1}'` #>/dev/null 2>&1     if [ "$proc_id" = "" ]     then         if [ `$daemon` ]         then             echo "php-fpm not stard."         else             echo "php-fpm stard."         fi     fi     ;;     *)     echo "Usage: $0 start|stop|restart"     ;;esac


2、复制脚本到启动目录

cp php-fpm.sh /etc/init.d/php-fpm


3、添加自启

chkconfig php-fpm on


4、查看效果

chkconfig --list


[root@localhost fonts]# chkconfig --list


注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 

      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。

      欲查看对特定 target 启用的服务请执行

      'systemctl list-dependencies [target]'。


httpd           0:关    1:关    2:关    3:开    4:关    5:开    6:关

mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关

netconsole      0:关    1:关    2:关    3:关    4:关    5:关    6:关

network         0:关    1:关    2:开    3:开    4:开    5:开    6:关

nginx           0:关    1:关    2:开    3:开    4:开    5:开    6:关

php-fpm         0:关    1:关    2:开    3:开    4:开    5:开    6:关

zabbix_agentd   0:关    1:关    2:开    3:开    4:开    5:开    6:关

zabbix_server   0:关    1:关    2:开    3:开    4:开    5:开    6:关



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn