点击(此处)折叠或打开
-
#! /bin/bash
-
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/service/bin:/app/service/bin:/usr/local/java/jdk1.6.0_20/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/service/bin
-
DATETIME=`date +%F`
-
serpath=/app/service/ser/bin
-
serlog=/app/service/serrestart.log
-
serdate=`date +%F.%T`
-
serip=`/sbin/ifconfig |grep 'inet addr'|grep 192 |awk -F: '{print $2}'|awk '{print $1}'`
-
seruser=`whoami`
-
#####mailsend
-
mailtitle="ser information $serdate $serip "
-
mailmessagefile=$HOME/mail.txt #邮件信息内容
-
mailmessage= #邮件信息内容
-
#mailcatcher=noc@test.com
-
mailcatcher=talen.hao@test.com #邮件接收者
-
mailsender=ser@test.com #邮件发送者
-
serPIDFILE=/app/service/ser/user-attributes-database.pid
-
-
-
#####
-
statusser()
-
{
-
ps -ef |grep ser |grep java|grep -v grep |awk '{print $2}'
-
}
-
Uadrestart()
-
{
-
cd $serpath
-
echo ">>>>> $serdate : 当前目录 `pwd`"
-
pidold=`statusser`
-
echo ">>>>> $serdate : Old PID NO. is "
-
#./misctrl.sh stop
-
kill -9 $pidold
-
rm -v $serPIDFILE
-
sleep 1
-
./misctrl.sh start
-
pidnew=`statusser`
-
echo ">>>>> $serdate : New PID NO. is "
-
}
-
-
Status(){
-
if [ -f $serPIDFILE ]
-
then
-
if test -z $pidnew -o $pidnew = $pidold
-
then
-
mailmessage='ser service restarted failure'
-
echo "$serdate : $serip $mailmessage" > $mailmessagefile
-
echo "$serdate : Old PID NO. is " >> $mailmessagefile
-
echo "$serdate : New PID NO. is " >> $mailmessagefile
-
echo "$serdate : restarted faild ==> $mailmessage"
-
isok=failure
-
else
-
mailmessage='ser service restarted success'
-
echo "$serdate : $serip $mailmessage" > $mailmessagefile
-
echo "$serdate : Old PID NO. is " >> $mailmessagefile
-
echo "$serdate : New PID NO. is " >> $mailmessagefile
-
echo "$serdate : restarted ok ==> $mailmessage"
-
isok=success
-
fi
-
else
-
mailmessage='ser service restarted failure'
-
echo "$serdate : $serip $mailmessage" > $mailmessagefile
-
echo "$serdate : Old PID NO. is " >> $mailmessagefile
-
echo "$serdate : New PID NO. is " >> $mailmessagefile
-
echo "$serdate : restarted faild ==> $mailmessage"
-
isok=failure
-
exit 1
-
fi
-
}
-
-
MailSend()
-
{
-
`which mail` -v -s "$mailtitle $isok" $mailcatcher -- -f $mailsender $mailmessagefile
-
}
-
-
vim.mailrc()
-
{
-
cp -v $HOME/.mailrc{,.bak$DATETIME-`echo $RANDOM`}
-
echo 'set from=sender@126.com smtp=smtp.126.com' > $HOME/.mailrc
-
echo 'set smtp-auth-user=sender@126.com smtp-auth-password=sender.com' >> $HOME/.mailrc
-
echo 'set smtp-auth=login' >> $HOME/.mailrc
-
}
-
MAIL()
-
{
-
if test -f $HOME/.mailrc
-
then
-
MailSend
-
else
-
echo ".mailrc文件不存在,将创建此文件"
-
vim.mailrc
-
MailSend
-
fi
-
}
-
if [ $seruser == service ]
-
then
-
echo ">>>>>$serdate : 开始执行重起服务"
-
Uadrestart
-
Status
-
MAIL
-
exit 0
-
else
-
echo ">>>>>$serdate : 严重!!使用service 用户运行此脚本"
-
exit 1
- fi