Share a PHP startup shutdown script

Source: Internet
Author: User
Tags case statement fpm

Tag: Init executes multi-branch net date led mail span--

Write your own simple PHP service startup script and share it with everyone

Idea (principle of realization):

1:function Module +case Statement multi-branch judgment

2: by adding # chkconfig:2345 43 89 Note To enable Boot (provided the script is placed in the/etc/init.d/directory and then chmod to the executable, then Chkconfig--add phpd (script Name))

3: does each command execute successfully with $? give feedback for zero

#!/bin/bash# PHP-FPM Start/stop php-fpm## chkconfig:2345  +  the#author andy#Date 20161218#functionphp-fpm manager#email [email protected]126. Com#version1.0#check Service Status#usage./etc/init.d/functions#defineVarCheck= ' netstat-lnutp|grepphp-fpm|WC-l 'functionusage () {Echo "usage:$0 {start|stop|restart|status}"exit}functionstart () {if[" $"="Start"-a $check-ne0]; thenAction"PHP is already started!"/bin/falseExitelif[" $"="Start"-a $check-eq0]; then Sleep 1/usr/local/sbin/php-FPMif[ $? =0]; thenAction"php start successfully!"/bin/true  ElseAction"php start failed!"/bin/falseExitfifi}functionStop () {if[" $"="Stop"-a $check-eq0]; thenAction"php is not running!"/bin/falseExitelif[" $"="Stop"-a $check-ne0]; then   Killallphp-FPMSleep 1  if[ $? =0]; thenAction"php stoped successfully!"/bin/true  ElseAction"php stoped failed!"/bin/falseExitfifi}functionRestart () {if[" $"="Restart"-a $check-eq0]; thenAction"php is not running!"/bin/false  Sleep 1/usr/local/sbin/php-FPMif[ $? =0]; thenAction"php start successfully!"/bin/true  ElseAction"php start failed!"/bin/falseExitfi elif[" $"="Restart"-a $check-ne0]; then   Killallphp-FPMif[ $? =0]; thenAction"php stoped successfully!"/bin/true  ElseAction"php stoped failed!"/bin/false  fi  Sleep 1/usr/local/sbin/php-FPMif[ $? =0]; thenAction"php start successfully!"/bin/true  ElseAction"php start failed!"/bin/falseExitfifi}functionstatus () {if[" $"="Status"-a $check-eq0]; then  Echo "php is not running!"Exitelif[" $"="Status"-a $check-ne0]; then  Echo "PHP is running"Exitfi} case " $" inchstart) Start $1    ;; Stop) Stop $1    ;; Restart) Restart $1    ;; Status) Status $1    ;; *) Usage $1Esac

If there is something wrong, please correct Me.

Share a PHP startup shutdown script

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.