Php-fpm self-starting script-php Tutorial

Source: Internet
Author: User
The php-fpm self-starting script finds it very troublesome to manually operate php-fpm. I tried to write a script to realize self-starting upon startup and achieve the desired effect.


1. Script

#!/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. copy the script to the Startup directory.

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


3. add self-start

Chkconfig php-fpm on


4. View Results

Chkconfig -- list


[Root @ localhost fonts] # chkconfig -- list


Note: The output result only shows the SysV service and does not contain the native systemd service. The SysV configuration data may be overwritten by the native systemd configuration.

To list the systemd service, run 'systemctl list-unit-files '.

To view the services enabled for a specific target, run

'Systemctl list-dependencies [target] '.


Httpd 0: off 1: Off 2: Off 3: on 4: Off 5: on 6: Off

Mysqld 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

Netconsole 0: off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off

Network 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

Nginx 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

Php-fpm 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

Zabbix_agentd 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

Zabbix_server 0: off 1: Off 2: Open 3: Open 4: Open 5: Open 6: Off

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.