update_script/function/function.sh

134 lines
3.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
source ../main.sh
show_file(){
filer=$1
#ls /data/update/$filer/ | tr ' ' '\n'
find /data/update/$filer -maxdepth 1 \( -type f -o -type d \) -printf "%-20f\t%TY-%Tm-%Td %TH:%TM:%TS\n"
}
# 判断一个字符串是否是合法的IP地址
is_valid_ip() {
local ip=$1
local pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if [[ $ip =~ $pattern ]]; then
# 检查每个数字是否在0到255之间
local IFS='.'
read -ra octets <<< "$ip"
for octet in "${octets[@]}"; do
if (( octet < 0 || octet > 255 )); then
return 1
fi
done
return 0
else
return 1
fi
}
mod_package(){
ip=${1}
package=${2}
# 源服务器上的tar压缩包路径
source_tar="/data/update/package/"
# 游戏服目标服务器上的目标目录路径
destination_dir="/data/jieling/server"
echo "正在处理服务器 $ip"
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir"
ssh "$ip" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $ip "
}
#正式服发送
send_package_reboot(){
package=${1}.tar.gz
ip_txt=${2}
reboot=${3}
if is_valid_ip "$ip_txt"; then
echo "$ip_txt 开始测试服更新"
mod_package $ip_txt $package
case $reboot in
0)
echo "热更,不需要重启... $i"
;;
1)
ssh $i "bash /data/jieling/server/bin/reboot.sh core1"
echo "重启测试服服务器 $i"
;;
esac
else
echo "$ip_txt 开始正式服更新"
for i in `awk '{print $2}' /data/update/script/txt/$ip_txt`
do
mod_package $i $package
case $reboot in
0)
echo "热更,不需要重启... $i"
;;
1)
ssh $i "supervisorctl restart all"
echo "重启正式服服务器 $i"
;;
esac
done
fi
}
#gm重启
gm_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/gm/gm_reboot.sh"
ssh $ip "ps -ef|grep gm_tw_admin"
echo "gm重启完毕"
}
mod_gm_package(){
ip=${1}
package=gm.tar.gz
# 源服务器上的tar压缩包路径
source_tar="/data/update/project/miduo_gm/gm"
# 游戏服目标服务器上的目标目录路径
destination_dir="/data/jieling/gm"
if [ -e $source_tar ]; then
echo "正在处理服务器 $ip"
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir"
ssh "$ip" "rm -f $destination_dir/$package"
echo "处理完成服务器 $ip "
else
echo "gm.tar.gz 不存在,请先去打包 "
gm
fi
}
#gm 发送包
gm_send_package(){
ip_txt=${1}
if is_valid_ip "$ip_txt"; then
echo "$ip_txt 开始更新gm/ip"
mod_gm_package $ip_txt
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
gm_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
else
echo "$ip_txt 开始更新gm/txt"
for i in `awk '{print $2}' /data/update/script/txt/$ip_txt`
do
mod_gm_package $i
gm_reboot $i
done
fi
}