Shell's most commonly used service script

Source: Internet
Author: User
Tags fpm

Mission Requirements: Managing/USR/LOCAL/PHP7/SBIN/PHP-FPM-C in the simplest way/usr/local/php7/etc/php.ini This command includes starting a stop restart

Using technology: Shell Scripting Chkconfig Service Management

Implementation process:

1. Create a shell script in the/ETC/INIT.D directory

vim/etc/init.d/php-fpm

2. Write script (write on the blog to manually add a lot of comments very comprehensive all Chinese comment lines deleted is the script content)

#!/bin/bash# Specify run shell# chkconfig:-85 15# Specify Run level-represents default 2345 85 and 15 for start priority and close priority value Smaller priority # processname:php-fpm# specify Service name # Define variable phpfpm=/usr/local/php7/sbin/php-fpmphpini=/usr/local/php7/etc/php.inifpmpid=$ (ps-ef | grep php-fpm | grep-v ' Color ' | Grep-v ' pts ' | awk ' {print $} ') #抓取php the-FPM process excludes rows with color and rows with PTS and fetches the second column  gets the multi-column PID number start () {  If [-Z ' $fpmpid]; then  # If Fpmpid is empty  if you determine non-empty with-n    $phpfpm-C $phpini  #那么就运行这条命令:/usr/local/php7/sbin/php-fpm-c/usr/local/php7/etc /php.ini    fi  echo ' php-fpm starting ... '}stop () {  If [-Z ' $fpmpid];  then #如果fpmpid是空 exit script exit    1  fi  kill-9 $fpmpid  echo ' php-fpm stop ... '}restart () {  stop  start  echo ' php-fpm Restart '}status () {  ps-ef | grep-v ' Color ' | grep-v ' pts ' | grep ' php-fpm '  #查看状态打印出php-fpm ' running process} #判断参数值 based on not The same parameter values go in different branches to perform the corresponding function case "$" instart)  start  ; Stop)  stop  ;; Restart)  Stop
Start ;; Status) status ; Esac

3. Give execution permission

chmod +x/etc/init.d/php-fpm

4. Join the Service

Chkconfig--add PHP-FPM

5. Final operation

Service php-fpm startservice php-fpm statusservice php-fpm restartservice php-fpm Stop

Shell's most commonly used service script

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.