关闭

CentOS6.5启停脚本例子

312人阅读 评论(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

0
0
查看评论

date +%F-%T-%N

date +%F-%T-%N 2016-03-24-14:40:13-997433641   %%   a literal %   %a   locale's abbreviated weekday name (e.g....
  • drcwr
  • drcwr
  • 2016-03-24 14:41
  • 2748

xmanager 图形界面安装设置进入CentOS6.5系统--crazychao

首先下载安装xmanager(完整安装) 设置阶段: 1.打开xshell 2.新建文件的旁边选中文件夹进入 3.选择一个主机点击右键属性(前提是有新建的主机) 4.进行隧道设置 5.安装xmanager点击确定 6.敲入指令gnome-panel进入图形界面(在这之前打开...
  • superman_xxx
  • superman_xxx
  • 2015-11-25 23:37
  • 2126

linux 重写Tomcat启停脚本

#!/bin/bash # # description: Tomcat start/stop/status script #Location of JAVA_HOME export JAVA_HOME=/opt/extp/tpc/jdk1.7 # 根据情况更改自己的jdk地址...
  • Liqinghai058
  • Liqinghai058
  • 2017-04-27 10:38
  • 482

Java服务部署上linux主机及shell脚本启停

今天在工作中需要将自己写的http服务端和客户端代码分别打包部署上linux主机并以shell脚本形式启停,如下为操作流程及总结。 1,java程序打包: 选择项目–>Export–>Runnable JAR file 2,将jar包放上linux主机 3,编写启动和停止脚本st...
  • u010564366
  • u010564366
  • 2017-09-07 18:10
  • 318

Memcached启停脚本小结

编写配置文件 vim/etc/memcached.conf 内容如下: -m128-d-p11211-c1024 编写启动脚本 vim /etc/rc.d/init.d/memcached #!/bin/bash # # memcache...
  • elesos
  • elesos
  • 2016-08-26 18:12
  • 722

weblogic启停脚本

weblogic启动 使用端口是否打开来判定服务是否启动。 #!/bin/bash #author:wjf #date:2015/05/19 #测试环境为wls1036水平集群 v_curr_user=`whoami` #------------实际was和代码安装的用户,比如用ufida,就直...
  • wang1016612067
  • wang1016612067
  • 2015-05-19 19:13
  • 2042

Onsql和MySQL的启停脚本

启停onesql,总共四个参数{start|stop|restart|status},只要稍微改一下头部的三个文件路径,即可完成mysql单实例的启停。 [#9(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 ...
  • Rookie_CEO
  • Rookie_CEO
  • 2015-08-30 13:21
  • 830

Nginx服务的启停控制

nginx 服务的启停控制  使用kill命令发送信号   如:kill -QUIT 主进程号   注:平缓停止 nginx服务在运行时,会保存一个主进程和一个或多个worker process工作进程。我们通过给nginx 服务的主进程发送信号就可以控制...
  • aiXiang001
  • aiXiang001
  • 2016-10-09 15:11
  • 684

Linux下启停数据库服务

1、启动数据库服务su - oraclesqlplus "/as sysdba"startupexit2、启动oracle监听 $lsnrctl lsnrctl>status (查状态) lsnrctl>start 3、关闭数据库服务shutdown immediat...
  • 00081168
  • 00081168
  • 2007-01-19 14:55
  • 2101

编写Redis启停服务脚本

脚本内容如下; #!/bin/bash## redis - this script starts and stops the redis-server daemon## chkconfig: - 80 12# description: Redis is a persistent ke...
  • elesos
  • elesos
  • 2016-10-08 10:06
  • 295
    个人资料
    • 访问:53878次
    • 积分:1050
    • 等级:
    • 排名:千里之外
    • 原创:92篇
    • 转载:3篇
    • 译文:0篇
    • 评论:9条
    文章分类
    最新评论