CentOS6.5启停脚本例子

344人阅读 评论(0) 收藏 举报
分类:
#!/bin/bash
# The next lines are for chkconfig on RedHat systems.
# chkconfig: 35 98 02# description: Starts and stops Server

# The next lines are for chkconfig on SuSE systems.
# /etc/init.d/xxx
#
### BEGIN INIT INFO
# Provides: Chinge_Yang
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start: 2 3 5# Default-Stop: 0 6# Short-Description: Starts and stops Server
# Description: Starts and stops Server
### END INIT INFO

#获取脚本所存放目录
cd `dirname $0`
bash_path=`pwd`
#脚本名
me=$(basename $0)

#定义输出颜色函数
function red_echo () {
#用法:  red_echo "内容"
        local what=$*
        echo -e "$(date +%F-%T) \e[1;31m ${what} \e[0m"
}

function green_echo () {
#用法:  green_echo "内容"
        local what=$*
        echo -e "$(date +%F-%T) \e[1;32m ${what} \e[0m"
}

function yellow_echo () {
#用法:  yellow_echo "内容"
        local what=$*
        echo -e "$(date +%F-%T) \e[1;33m ${what} \e[0m"
}

function twinkle_echo () {
#用法:  twinkle_echo $(red_echo "内容")  ,此处例子为红色闪烁输出
        local twinkle='\e[05m'
        local what="${twinkle} $*"
        echo -e "$(date +%F-%T) ${what}"
}

function return_echo () {
        [ $? -eq 0 ] && green_echo "$* 成功" || red_echo "$* 失败"
}

function return_error_exit () {
        [ $? -eq 0 ] && local REVAL="0"
        local what=$*
        if [ "$REVAL" = "0" ];then
                [ ! -z "$what" ] && green_echo "$what 成功"
        else
                red_echo "$* 失败,脚本退出"
                exit 1
        fi
}

#定义确认函数
function user_verify_function () {
        while true;do
                echo ""
                read -p "是否确认?[Y/N]:" Y
                case $Y in
                                        [yY]|[yY][eE][sS])
                                                echo -e "answer:  \\033[20G [ \e[1;32m是\e[0m ] \033[0m"
                                                break  
                                                ;;
                    [nN]|[nN][oO])
                                echo -e "answer:  \\033[20G [ \e[1;32m否\e[0m ] \033[0m"         
                                                exit 1
                                                ;;
                                        *)      continue        ;;
                esac
        done
}

#定义跳过函数
function user_pass_function () {
        while true;do
                echo ""
                read -p "是否确认?[Y/N]:" Y
                case $Y in
                        [yY]|[yY][eE][sS])
                                                echo -e "answer:  \\033[20G [ \e[1;32m是\e[0m ] \033[0m"
                                                break  
                                                ;;
                        [nN]|[nN][oO])
                                echo -e "answer:  \\033[20G [ \e[1;32m否\e[0m ] \033[0m"         
                                                return 1
                                                ;;
                                        *)      continue        ;;
                esac
        done
}

 

#cd到程序目录
program_path=$(dirname $bash_path)
program_name="play"

function start () {
                #cd $bash_path/../logfile/
                #判断程序是否运行
                program_pid=$(pidof $program_path/$program_name)
                if [[ -z "$program_pid" ]];then
                        cd $program_path
                        nohup ./$program_name &
                else
                        yellow_echo "This program $program_path/$program_name is running,no need to start"
                        exit 0
                fi
                program_pid=$(pidof $program_path/$program_name)
                [[ ! -z "$program_pid" ]] && green_echo "This program start successed" || return_error_exit "This program start failed."
        }

function stop(){
                #判断pid存在情况
                program_pid=$(pidof $program_path/$program_name)
                [[ -z "$program_pid" ]] && yellow_echo "This program $program_path/$program_name is not running." || { kill -9 $program_pid && red_echo "This program $progra
m_path/$program_name be end."; }

}

function status(){
                program_pid=$(pidof $program_path/$program_name)
                [[ -z "$program_pid" ]] && yellow_echo "This program is not running" || green_echo "This program $program_path/$program_name is running"
}
case $1 in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status
                ;;
        restart)
                stop
                start
                ;;
          *)echo "$0 {start|stop|restart|status}"
                exit 4;
                ;;
esac

查看评论

CSDN总经理蒋涛亲临会场

  • foxfly
  • foxfly
  • 2004-04-17 10:17:00
  • 769

DB2学习总结(1)——DB2数据库基础入门

DB2的特性 完全Web使能的:可以利用HTTP来发送询问给服务器。 高度可缩放和可靠:高负荷时可利用多处理器和大内存,可以跨服务器地分布数据库和数据负荷;能够以最小的数据丢失快速地恢复,...
  • u012562943
  • u012562943
  • 2016-03-15 16:43:28
  • 7432

DB2基础知识

1.        新加一个数据库实例  db2icrt [-a AuthType]            [-p PortName]            [-s InstType]        ...
  • Anthony88
  • Anthony88
  • 2008-05-15 15:17:00
  • 3718

db2常用操作总结

DB2数据库常用操作总结
  • blusyangjiwen
  • blusyangjiwen
  • 2017-01-22 11:11:18
  • 416

HACMP切换启停DB2的脚本

1、编辑DB2_start.sh和DB2_stop.shDB2_start.shsu - db2inst1 -c 'db2start' DB2_stop.shsu- db2admin -c 'db2 ...
  • honghu79
  • honghu79
  • 2013-09-26 20:06:43
  • 1412

DB2数据库的基础学习

DB2的特性 完全Web使能的:可以利用HTTP来发送询问给服务器。 高度可缩放和可靠:高负荷时可利用多处理器和大内存,可以跨服务器地分布数据库和数据负荷;能够以最小的数据丢失快速地恢复,提供多种备份...
  • limingzhong198
  • limingzhong198
  • 2012-04-27 02:03:08
  • 15776

服务启停调用脚本

#!/bin/bash###############################################################################          ...
  • xiaofeng_rui
  • xiaofeng_rui
  • 2018-04-19 14:17:37
  • 52

tomcat启停脚本

#!/bin/bash#------------------------------------------------------------#功能:tomcat停止#环境:linux#参数:无#返...
  • wfn1131
  • wfn1131
  • 2018-02-24 16:32:37
  • 20

PostgreSQL学习第十二篇 服务的启停和创建

启动一个数据库实例有两种方法: 1. 直接运行postgres进程启动 postgres -D /home/xxxxx & 2. 使用pg_ctl命令启动 pg_ctl -D /xxx ...
  • ghostliming
  • ghostliming
  • 2017-01-17 17:06:31
  • 736

oracle 12C RAC 服务的启停

单节点数据库起停 srvctl stop instance -d vmtoradb -i vmtoradb1 srvctl stop instance -d vmtoradb -i vmtoradb...
  • jiajingshan
  • jiajingshan
  • 2016-07-06 13:32:38
  • 1776
    个人资料
    持之以恒
    等级:
    访问量: 6万+
    积分: 1195
    排名: 4万+
    最新评论