Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65840
  • 博文数量: 13
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-08 10:49
个人简介

做一个努力的程序猿

文章分类

全部博文(13)

文章存档

2016年(11)

2014年(2)

我的朋友

分类: LINUX

2016-04-19 09:11:57

#!/bin/bash
now=$(date '+%Y-%m-%d %H:%M:%S')
 
# the time interval between watchdog.sh monitorings
sleepTime=5
 
# log of watchdog.sh monitorings
watchdogLog="./watchdoglog.txt"
 
# current path
curDir=$(pwd)
# echo "current path is: \"$curDir\""
 
# the path of the monitored process
#baseDir="/home/admin/release/server/"  # intranet
baseDir="/usr/local/src/ftp/release/server/"    # extranet
 
if [[ $# -ne 1 && $# -ne 2 ]]; then
    echo "$0 parameter number is error!"
    exit
fi
 
# process name of watchdog.sh monitorings
procName=$1
echo "procName is: \"$procName\""
 
# parameter of process
paramName=$2
echo "paramName is: \"$paramName\""
 
user=$(whoami)
# echo "user is \"$user\""
if [[ "$user" != "root" ]]; then
    echo "this tool must run as *root*"
    exit
fi
 
while [[ 0 -lt 1 ]]
do
    now=$(date '+%Y-%m-%d %H:%M:%S')
    if [[ "$paramName" == "" ]]; then
        ret=$(ps aux | grep "$procName$" | grep -v "grep" | grep -v "$0 $procName$" | wc -l)
    else
        ret=$(ps aux | grep "$procName $paramName$" | grep -v "grep" | grep -v "$0 $procName $paramName$" | wc -l)
    fi
    # echo "$procName $paramName ret = $ret"
 
    if [[ $ret -lt 1 ]]; then
        echo "$now process $procName $paramName is not exists..." >> "$watchdogLog"
        # send email to notice administrator
        echo "$now process $procName $paramName is not exists..." | mail -s "server status change notice" youremail@qq.com
        cd "$baseDir"
        # echo "./$procName $paramName"
        if [[ "$paramName" == "" ]]; then
            nohup ./"$procName" > /dev/null 2>&1 &
        else
            nohup ./"$procName" "$paramName" > /dev/null 2>&1 &
        fi
        cd "$curDir"
        echo "$now restart process(pid=$!) $procName $paramName done..." >> "$watchdogLog"
    fi
    sleep $sleepTime
done
阅读(1815) | 评论(0) | 转发(1) |
0

上一篇:mysql语法总结

下一篇:驱动模块makefile

给主人留下些什么吧!~~