• linux tomcat 快捷起停脚本


    一、安装redhat-lsb

    yum install redhat-lsb

    进入/usr/local/bin
    新建文件tomcat
    添加权限
    chmod +x tomcat

    tomcat

    #!/bin/bash

    . /etc/profile

    if [ -r /lib/lsb/init-functions ]; then
    . /lib/lsb/init-functions
    else
    exit 1
    fi

    NAME="$(basename $0)"

    function usage()
    {
    echo "Usage: $0 {start|stop|restart} {mkt-web|eshop-app}"
    RETVAL="2"
    }

    if [ $# -ne 2 ]; then
    usage
    exit 1
    fi

    APP=$2
    if [ -z $APP -o ! -d "/data/web/$APP" ];then
    echo "Null parameter or $APP not exists"
    exit 1
    fi

    TOMCAT_HOME="/data/tomcats/$APP"

    function start() {
    echo "Starting ${APP}: "
    if [ "$RETVAL" != "0" ];then
    log_failure_msg
    return
    fi

    pid=$(ps aux | grep "${TOMCAT_HOME}" | grep -v "grep" | awk '{print $2}')
    if [ -n "$pid" ];then
    log_success_msg "is running, PID: $pid"
    return
    fi

    "${TOMCAT_HOME}"/bin/startup.sh
    sleep 3
    pid=$(ps aux | grep "${TOMCAT_HOME}" | grep -v "grep" | awk '{print $2}')
    if [ -z "$pid" ];then
    log_failure_msg
    RETVAL=1
    else
    log_success_msg "PID: $pid"
    fi
    }

    function stop() {
    echo -n "Stopping ${APP}: "

    pid=$(ps aux | grep "${TOMCAT_HOME}" | grep -v grep | awk '{print $2}')
    if [ -z "$pid" ];then
    echo -n "not running"
    log_warning_msg
    return
    fi

    count=0
    until [ -z "$(ps aux | grep "${TOMCAT_HOME}" | grep -v grep | awk '{print $2}')" ] || [ $count -gt 3 ];
    do
    kill -9 $pid
    sleep 3
    let count="${count}+1"
    done
    if [ $count -gt 3 ];then
    RETVAL=1
    log_failure_msg "PID: $pid"
    return 1
    else
    rm -rf /data/tomcats/$APP/work/*
    rm -rf /data/tomcats/$APP/temp/*
    log_success_msg "PID: $pid"
    fi
    }

    RETVAL="0"
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    *)
    usage
    ;;
    esac

    exit $RETVAL

     

    起停命令:

    tomcat start/restart/stop 项目名

  • 相关阅读:
    赤羽西二丁目14号
    080520 雨 大风
    游泳的梦
    poj1088 滑雪 解题报告
    sgu 183. Painting the balls 动态规划 难度:3
    POJ 1947 Rebuilding Roads 树形dp 难度:2
    POJ 2566 Bound Found 尺取 难度:1
    hdu4800 Josephina and RPG 解题报告
    POJ 2057 The Lost Home 树形dp 难度:2
    HDU 4791 Alice's Print Service 思路,dp 难度:2
  • 原文地址:https://www.cnblogs.com/Nanaya/p/12162130.html
Copyright © 2020-2023  润新知