Share a php startup/shutdown script (original) and a php shutdown script

Source: Internet
Author: User
Tags case statement

Share a php startup/shutdown script (original) and a php shutdown script

A simple php service startup script to share with you

Idea (implementation principle ):

1: function module + case statement multi-branch judgment

2: add the # chkconfig: 2345 43 89 annotation to enable auto-start upon startup (the premise is to put the script into/etc/init. d/directory, then chmod gives executable permissions, and then chkconfig -- add phpd (Script Name ))

3: Is each command executed successfully $? Whether the value is 0.

#!/bin/bash# php-fpm       Start/Stop php-fpm## chkconfig: 2345 43 89#author andy#date 20161218#function php-fpm manager#email fei1989118@126.com#version 1.0#check service status#usage. /etc/init.d/functions#define varcheck=`netstat -lnutp|grep php-fpm|wc -l`function usage(){ echo "usage:$0 {start|stop|restart|status}" exit}function start(){ if [ "$1" = "start" -a $check -ne 0 ];then action "php is already started!" /bin/false exitelif [ "$1" = "start" -a $check -eq 0 ];then sleep 1 /usr/local/sbin/php-fpm  if [ $? = 0 ];then  action "php start successfully!" /bin/true  else   action "php start failed!" /bin/false  exit  fifi}function stop(){if [ "$1" = "stop" -a $check -eq 0 ];thenaction "php is not running!" /bin/false exitelif [ "$1" = "stop" -a $check -ne 0 ];then   killall php-fpm  sleep 1  if [ $? = 0 ];then   action "php stoped successfully!" /bin/true  else   action "php stoped failed!" /bin/false  exit  fifi}function restart(){if [ "$1" = "restart" -a $check -eq 0 ];then  action "php is not running!" /bin/false  sleep 1  /usr/local/sbin/php-fpm  if [ $? = 0 ];then  action "php start successfully!" /bin/true  else  action "php start failed!" /bin/false  exit  fi elif [ "$1" = "restart" -a $check -ne 0 ];then   killall php-fpm  if [ $? = 0 ];then   action "php stoped successfully!" /bin/true  else   action "php stoped failed!" /bin/false  fi  sleep 1  /usr/local/sbin/php-fpm  if [ $? = 0 ];then   action "php start successfully!" /bin/true  else   action "php start failed!" /bin/false  exit  fifi}function status(){if [ "$1" = "status" -a $check -eq 0 ];then  echo "php is not running!" exitelif [ "$1" = "status" -a $check -ne 0 ];then  echo "php is running"  exitfi}case "$1" in    start) start $1    ;;    stop) stop $1    ;;    restart) restart $1    ;;    status) status $1    ;;    *) usage $1esac

If there is something wrong, please correct me more

Related Article

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.