#!bin/sh
#此脚本放在hello文件夹的外面
#查看hello_update文件夹是否存在,如果存在开始更新程序
if [ -e hello_update ]
then
echo "start update hello"
#杀掉正在运行的hello进程
pidlist=`ps -ef |grep "hello" |grep -v "grep"|awk '{print $2}'`
echo "id list:$pidlist"
if [ "$pidlist" = "" ]
then
echo "no app pid alive"
else
for pid in ${pidlist}
do
kill -9 $pid
echo "KILL $pid:"
echo "app stop success"
done
fi
#查看hello_backup文件夹是否存在,如果存在则删除
if [ -e hello_backup ]
then
rm -rf hello_backup
echo "delete hello_back_up"
fi
#将当前hello文件夹改名成hello_backup
if [ -e hello ]
then
mv hello hello_backup
echo "rename hello to hello_backup"
fi
#升级文件放在hello_update中,将hello_update改名成hello
if [ -e hello_update ]
then
mv hello_update hello
echo "rename hello_update to hello"
else
#如果hello_update文件夹不存在,则将hello_backup文件夹拷贝到hello,启动里面的hello程序
cp -r hello_backup hello
cd hello
./hello.bin & #加"&",让hello后台运行
echo "start old hello success"
exit 0 #退出
fi
#启动升级后的hello
cd hello
./hello.bin & #加"&",让hello后台运行
cd ..
echo "start new hello success"
#检查升级后的hello是否正常启动,如果正常启动则生成一个标识升级成功的文件,退出
#如果没有检测到升级后的hello进程,则删除当前hello文件夹,拷贝备份程序为当前hello
updatepid=`ps -ef |grep "hello.bin" |grep -v "grep"|awk '{print $2}'`
if [ "$updatepid" = "" ]
then
#没有检测到升级后的hello进程
rm -rf hello
cp -r hello_backup hello
cd hello
./hello.bin & #加"&",让hello后台运行
exit 0
else
#升级成功,创建update_success空文件
#hello启动后检测时候有此文件,如果有,则发送升级成功消息,并删除此文件;如果没有,则发送升级失败消息
touch update_success
fi
else
exit 0
fi
#此脚本放在hello文件夹的外面
#查看hello_update文件夹是否存在,如果存在开始更新程序
if [ -e hello_update ]
then
echo "start update hello"
#杀掉正在运行的hello进程
pidlist=`ps -ef |grep "hello" |grep -v "grep"|awk '{print $2}'`
echo "id list:$pidlist"
if [ "$pidlist" = "" ]
then
echo "no app pid alive"
else
for pid in ${pidlist}
do
kill -9 $pid
echo "KILL $pid:"
echo "app stop success"
done
fi
#查看hello_backup文件夹是否存在,如果存在则删除
if [ -e hello_backup ]
then
rm -rf hello_backup
echo "delete hello_back_up"
fi
#将当前hello文件夹改名成hello_backup
if [ -e hello ]
then
mv hello hello_backup
echo "rename hello to hello_backup"
fi
#升级文件放在hello_update中,将hello_update改名成hello
if [ -e hello_update ]
then
mv hello_update hello
echo "rename hello_update to hello"
else
#如果hello_update文件夹不存在,则将hello_backup文件夹拷贝到hello,启动里面的hello程序
cp -r hello_backup hello
cd hello
./hello.bin & #加"&",让hello后台运行
echo "start old hello success"
exit 0 #退出
fi
#启动升级后的hello
cd hello
./hello.bin & #加"&",让hello后台运行
cd ..
echo "start new hello success"
#检查升级后的hello是否正常启动,如果正常启动则生成一个标识升级成功的文件,退出
#如果没有检测到升级后的hello进程,则删除当前hello文件夹,拷贝备份程序为当前hello
updatepid=`ps -ef |grep "hello.bin" |grep -v "grep"|awk '{print $2}'`
if [ "$updatepid" = "" ]
then
#没有检测到升级后的hello进程
rm -rf hello
cp -r hello_backup hello
cd hello
./hello.bin & #加"&",让hello后台运行
exit 0
else
#升级成功,创建update_success空文件
#hello启动后检测时候有此文件,如果有,则发送升级成功消息,并删除此文件;如果没有,则发送升级失败消息
touch update_success
fi
else
exit 0
fi