Anatomy of an instance of the online multi-service management tool

Source: Internet
Author: User

The service management scripts for the Java applications of Nginx, Tomcat, and jar packages on the company's line are separated separately, which makes it very inconvenient for operations personnel to manage their services on a springboard machine. In particular, when these service management frameworks are incorporated into an automated management platform, there is no unified service management interface to use.

So, when it was empty, I fused the management scripts of multiple services together and made him a tool that reduced the clutter of service management.

Nonsense not to say, the following is the script content, the end of the article I will briefly introduce the idea of the script.

#!/bin/bash##  This script is used to manage multiple services on the system #  currently only supports Nginx, Tomcat, and Jar package class Java applications for administrative operations # written by  Sunsky# mail : [email protected]# date : 2014-11-26 15:00:00#function  USAGE {    echo -e  "\033[31m script name:  \033[37m"      echo  "    $0"     echo -e  "\033[31M syntax structure:  \033 [37m "    echo "     $0 {nginx|tomcat|*service} {start| Stop|restart|status} "    echo -e " \033[31m use example:  \033[37m "     echo  "    $0 nginx start"     echo  "     $0 tomcat restart "    echo "     $0  vin-service status "    echo -e " \033[31m Precautions:  \033[37m "     echo&nbsP; "     1.  the directory managed by the script must follow the following rules: "    echo "         A)  nginx  The deployment path must be accessible through  /usr/local/nginx  to the     echo   "       B"  tomcat  deployment path must be able to pass  /usr/local/tomcat  Access to "    echo "        c)  service  The deployment path of the class service must be accessible through the  /home/apps/service class project name/current/  to the     echo       2. \$1 (service type) and \$2 (operation) parameters must exist "    exit 2}function cat_fuwu {        if [ -z  $PID  ];then            case  $SIGNAL  in            start|restart)                 echo  "PositiveAt startup   $FUWU   Services            ;;            stop)                 echo  "$FUWU   service is turned off"                 exit            ;;            status)                 echo  $FUWU   Service is off             ;;            esac        else           case  $SIGNAL  in            start)                echo  "$FUWU   service is turned on"                 exit 0            ;;            stop|restart)                 echo  "You are going to kill   $FUWU   service corresponding process number is  $ PID "           ;;            status)                 echo  "$FUWU   service is currently running with the corresponding process number   $PID"             ;;            esac        fi}function kill_fuwu {    if [[  $PID  !=  ""  ]];then        for  i in  $PID;d o            kill  $PID  >/dev/null 2>&1             sleep 3            kill -9 $ pid >/dev/null 2>&1        done     fi}function START_NGINX {    /usr/local/nginx/sbin/nginx     pid= ' ps -ef|awk   ' $0~ "Nginx" &&$0~ "master" &&$0!~ "awk" {print $2} '     echo  "$FUWU   service has started, it corresponds to the process number   $PID"}function start_tomcat {     /bin/bash /usr/local/tomcat/bin/startup.sh >& /dev/null     pid= ' ps aux|awk   ' $0~ "java" &&$0~ "Tomcat" &&$0!~ "awk" {print $2} '      echo  "$FUWU   service has started, it corresponds to the process number   $PID"}function start_service {         /bin/bash /home/apps/$FUWU/current/startup.sh &         pid= ' ps -ef|awk  ' $0~ "' $FUWU '" &&$0~ "Jar" &&$0!~ "awk" { print $2} '         echo  ' $FUWU   service has been started, it corresponds to the process number  $ PID "}function fuwu_list {    case  $SIGNAL  in     Start)         CAT_FUWU         $1    ;;     stop)         CAT_FUWU         KILL_FUWU    ;;     restart)         CAT_FUWU        KILL_FUWU         $1    ;;     status)         CAT_FUWU     ;;     *)         USAGE    ;;     esac}function nginx {    pid= ' ps -ef|awk    ' $0~ ' Nginx "&&$0~" master "&&$0!~" awk "{print $2}"     fuwu_list  start_nginx}function tomcat {    pid= ' ps aux|awk   ' $0~ "Java "&&$0~" Tomcat "&&$0!~" awk "{print $2}"     fuwu_list start_tomcat} function service {    if [ ! -f /home/apps/$FUWU/current/ Startup.sh ];then       &nBsp Usage    fi    pid= ' ps -ef|awk  ' $0~ "' $FUWU '" &&$0~ " Jar "&&$0!~" awk "{print $2}"     fuwu_list start_service}if [ $#  -lt 2 ];then     usagefifuwu=$1signal=$2case $1 innginx)     NGINX;; Tomcat)     TOMCAT;; *service)     SERVICE;; *)     USAGE;; Esac

Above all, that is the content of the entire script.

In this script, I'll look at the service status information, kill the service and service management actions into reusable functions, and create a separate module for the actions that start each application. While the Java applications of Nginx, Tomcat, and JAR package classes are now integrated, it is also very convenient to have other services to add to it later in the future.

Here's a quick introduction to each module:

USAGE # Help Module Cat_fuwu # is used to determine the current state of the service and give the correct corresponding Kill_fuwu # to the public module responsible for killing the service when receiving the user Action # Start_nginx # responsible for launching NGINX applications Module Start_tomcat # module responsible for launching the TOMCAT Application Start_service # module responsible for launching the Java application of the Jar package class Fuwu_list # The Common list Nginx # collection that responds to a single service operation Nginx Management Operation Module Tomcat # Collection Tomcat Management Operation Module Service # Collection Jar Package class Java Application Management operations module

The following is a script execution:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/0B/wKioL1R2pOzxhkxjAAVYJ89jQ2o448.jpg "title=" Qq20141127120915.png "alt=" Wkiol1r2pozxhkxjaavyj89jq2o448.jpg "/>

Ok! The above is the content of the script, hope to be able to help 51 Bo Friends

This article is from the "not only Linux" blog, so be sure to keep this source http://nolinux.blog.51cto.com/4824967/1583156

Anatomy of an instance of the online multi-service management tool

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.