#!/bin/sh
# Create by Gxy
# Save this shell script to autorestart.sh file.
# Use "nohup autorestart.sh &" to add jobs.
# Use "exit" to exit terminal.
# Restart time
RESTART_TIME="2018-06-26 06:00:00"
# Pomelo admin username
USERNAME="yrny23214mgkpw"
# Pomelo admin password
PASSWORD="z0cx6e6f1nho44512os2y9eckrqbql7j"
# Full path of game-server
SERVER_PATH="/pomelo-servers/game-server/"
# Master port
MASTER_PORT=3005
# Calculate interval seconds for sleep
time_secs=`date -d "-0 day $RESTART_TIME" +%s`
now_secs=`date +%s`
interval_secs=`expr $time_secs - $now_secs`
echo "Interval seconds is " $interval_secs
sleep $interval_secs
# Stop pomelo servers
echo "--> Begin stop servers"
cd $SERVER_PATH
pomelo stop -u $USERNAME -p $PASSWORD -P $MASTER_PORT
sleep 10
echo "--> End stop servers"
# Backup logs
echo "--> Begin move logs"
mv logs `date "+%Y-%m-%d_%H:%M:%S"`
mkdir logs
echo "--> End move logs"
# Start pomelo servers
echo "--> Begin start servers"
pomelo start -e production -D
echo "--> End start servers"
- 将脚本保存为autorestart.sh脚本文件,使用chmod +x autorestart.sh给予执行权限
- 修改脚本里的重启时间、账号密码、端口与game-server路径
- 使用nohup /path/autorestart.sh &添加后台执行
- 先Ctrl+C,然后exit退出终端!
ps:
- 脚本需要放到master所在服务器上