配置itsm服务台后端应用自检并自启脚本

一、背景:

公司的itsm服务台系统的后端应用经常半夜出现问题,java进程经常挂掉,并且该系统也是最近需要下线的,所以需要就配置一个自检和自启脚本,这样的话就提高了工作效率,同时也避免了半夜应用挂掉,需要联系运维人员起来启动应用服务。

二、脚本需求: 

1、脚本需要判断java进程是否存在;

2、需要做循环判断处理;

3、执行的过程需要写入到指定的日志文件中;

4、需要判断脚本执行的用户;

三、脚本撰写: 

vim start_itsm.sh

#!/bin/bash
#aouth:ex-xionghj001
#time:2023/3/9

log_output () {
    if [ ! -f /root/bin/start-log.log ]
    then
        cd /root/bin/
        touch /root/bin/start-log.log
    fi
    echo -e "\e[$1m[$(date +"%F %T")] $2 \e[0m" 
}

start_itsm () {
    user=`whoami`
    if [ $user == root ]
    then
        log_output 31 "[ERROR] The is test" | tee -a /root/bin/start-log.log
        docker-deploycompose -s balancer -a restartall $>> /root/bin/start-log.log
    else
        log_output 31 "[ERROR] The current user is not root,need user is root" | tee -a /root/bin/start-log.log
        exit
    fi
}
for ((i=10;i>0;i--))
do
    itsm=`ps -ef |grep java | grep -v grep| wc -l`
    if [ $itsm -gt 0 ]
    then
        log_output 32 "[INFO] itsm is running" | tee -a /root/bin/start-log.log
        exit
    else
        log_output 31 "[ERROR] itsm is not running, need running" | tee -a /root/bin/start-log.log
        start_itsm
    fi
    log_output 32 "For loop $i" | tee -a /root/bin/start-log.log
done

四、脚本授权并设置定时任务:

# chmod 755 start_itsm.sh

# crontab -e

*/2 * * * * /bin/bash /root/bin/start_itsm.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jiang0615csdn

你对鼓励是我最大的动力来源

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值