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