#!/bin/bash
#luohongjiang
#2012/3/19
#qq:123769752
#version 1.2
main()
{
. InfoData #导入变量文件
#####################################################
echo -e "$ys_green back file $ys_o"
waring
if (( $? == 1 ));then
f_bakfile #备份文件
fi
####################################################
echo -e "$ys_green send file $ys_o"
waring
if (( $? == 1 ));then
f_active #传送文件
fi
#######################################################
echo -e "$ys_green stop program $ys_o"
waring
if (( $? == 1 ));then
stopTandB #停程序
fi
#########################################################
if (( $? == 4 ));then
echo -e "package_file:\E[31m $_package \E[0m to dst_path:\E[31m $_re_patch \E[0m"
read -p 'are you sure[Y/n]:' _sure
if [[ $_sure == 'Y' ]];then
echo "update program"
doing #更新程序
fi
fi
#################################################################
echo -e "$ys_green start program $ys_o"
waring
if (( $? == 1 ));then
startTandB #开始启动脚本
fi
##################################################################
echo -e "$ys_green check program $ys_o"
waring
if (( $? == 1 ));then
chkTandb #检测程序状态
fi
#########################################################################
if [[ $_clearpackage == "Y" ]];then #清理垃圾
echo -e "$ys_green clear update package $ys_o"
cleanpackage
fi
}
#########################################################################
waring() #交互模块
{
read -p 'are you sure[y/n]:' _sure
if [[ $_sure == 'y' ]];then
return 1
else
return 0
fi
}
f_bakfile() #备份功能
{
_bmd=`date +%m-%d`
if [[ -e $_bakfile-${_bmd} ]];then
echo '+----------------------------+'
echo ' bak file is exist! '
echo " Name: $(ls -ltr $_bakfile-${_bmd}|awk '{print $9" "$6 " " $7" "$8}')"
echo " Szie: $(du -hs "$_bakfile-${_bmd}"|awk '{print $1}')"
echo '+----------------------------+'
return 0
else
cp $_bakfile $_bakfile-${_bmd} -r
echo '+-----------------------------+'
echo " Name: $(ls -ltr $_bakfile-${_bmd}|awk '{print $9" "$6 " " $7" "$8}')"
echo " Szie: $(du -hs "$_bakfile-${_bmd}"|awk '{print $1}')"
echo 'backup Success!'
echo '+-----------------------------+'
return 2
fi
}
f_active() #发送文件功能
{
for i in ${IP[*]}
{
ssh $username@$i "mkdir -p $_envpath" #username 默认是root _envpath默认在 /var/update/package
rmPath=$username@$i:$_envpath
echo "********************[$(date +%T)]"
scp -r $_package $rmPath
echo -e "********************[$i]\n"
}
return 3
} #函数结束
stopTandB() #停程序
{
for i in ${IP[*]}
{
for k in ${_kill_pro[*]}
{
ssh $username@$i "(
ps -ef|grep -v grep|grep $k >/dev/null
if (( $? == 0 ));then
(pkill -9 $k)
echo '**************************$k kill ok'
else
echo '>>>>>>>>>>>>>>>>>>>>>>>>>$k kill fail!'
fi
)"
}
echo "++++++++++++++++++++++++++$i"
}
return 4
}
doing() #更新程序
{
for i in ${IP[*]}
{
ssh $username@$i "(
if [[ -e $_envpath/$_package ]];then
if [[ -e $_re_patch ]];then
tar -xvf $_envpath/$_package -C $_re_patch
echo '**************************[$i] Extra $_package file ok'
else
echo '**************************[$i] $_re_patch no exist!'
fi
else
echo '**************************[$i] $_envpath/$_package no exist!'
fi
)"
}
}
startTandB() #启动脚本程序
{
for i in $IP
{
start_ktop_name=${_start_ktop##*/}
start_ktop_path=${_start_ktop%/`echo ${_start_ktop##*/}`}
ssh $username@$i "(
cd $start_ktop_path
nohup ./$start_ktop_name &
)>/var/tmp/start.log"
echo "**************************$i is start ok!"
}
}
chkTandb() #检测程序状态
{
sleep 5
for i in ${IP[*]}
{
for k in ${_kill_pro[*]}
{
ssh $username@$i "(
ps aux|grep -v grep|grep $k
)"
}
echo "**************************$i status"
}
return 5
}
cleanpackage() #清理更新的包文件
{
for i in $IP
{
ssh $username@$i "(rm -rf $_envpath)"
echo "**************************$i clear $_envpath over"
}
}
main
阅读(2606) | 评论(2) | 转发(0) |