Skip to content

Commit

Permalink
Added redis backup and change launch options.
Browse files Browse the repository at this point in the history
Added ability to backup redis using: atlasmanager redis --backup
Changed method of working with redis to: redis --start, redis --stop, redis --restart, redis --status, and redis --backup.
This allows for more commands to be added in the future with less clutter.
  • Loading branch information
BoiseComputer authored Feb 8, 2019
1 parent 3a3327b commit dbd6bb0
Showing 1 changed file with 101 additions and 7 deletions.
108 changes: 101 additions & 7 deletions tools/atlasmanager
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ set +o allexport

# Script version
atlasstVersion='1.8'
atlasstTag='v1.8.4.3'
atlasstCommit='79e062e63eed0994bd0b451a9b525a80630de11d'
atlasstTag='v1.8.4.4'
atlasstCommit='0d683ea82e0c7f367e0992f0211e07f6f5b45b7c'
atlasstGithubRepo="BoiseComputer/atlas-server-tools"
atlasstRootUseEnv=''
atlasstGlobalCfgFile='/etc/atlasmanager/atlasmanager.cfg'
Expand Down Expand Up @@ -772,10 +772,10 @@ function getSavedATLASsDirectory(){
cisavedir="$(find "${atlasserverroot}" -ipath "${savedir}" | head -n1)"

if [ -n "$cisavedir" ]; then
echo -e " ${NORMAL}[ ${YELLOW}WARN${NORMAL} ] Saved atlass directory capitalization is inconsistent" >&2
echo -e " ${NORMAL}[ ${YELLOW}WARN${NORMAL} ] Saved ATLAS directory capitalization is inconsistent" >&2
savedir="${cisavedir}"
else
echo -e " ${NORMAL}[ ${RED}ERROR${NORMAL} ] Saved atlass directory does not exist" >&2
echo -e " ${NORMAL}[ ${RED}ERROR${NORMAL} ] Saved ATLAS directory does not exist" >&2
echo ""
return 1
fi
Expand Down Expand Up @@ -1274,6 +1274,58 @@ doRun() {
done
}
#
# redis function
#
doRedis() {
local redisStart=
local redisStop=
local redisRestart=
local redisStatus=
local redisBackup=
for arg in "$@"; do
case "$arg" in
--start) redisStart=1; ;;
--stop) redisStop=1; ;;
--restart) redisRestart=1; ;;
--status) redisStatus=1; ;;
--backup) redisBackup=1; ;;
*)
echo "Unrecognized option $arg"
echo "Try 'atlasmanager -h' or 'atlasmanager --help' for more information."
exit 1
esac
done
if [ -n "$redisStart" ]; then
doRedisStart
fi
if [ -n "$redisStop" ]; then
doRedisStop
fi
if [ -n "$redisRestart" ]; then
doRedisStop
doRedisStart
fi
if [ -n "$redisStatus" ]; then
doRedisStatus
fi
if [ -n "$redisBackup" ]; then
doRedisBackup
fi
}
#
# redis start function
#
doRedisStart() {
if ! $redis_local; then
echo "Redis is not hosted locally."
Expand All @@ -1295,6 +1347,9 @@ else
fi
}
#
# redis stop function
#
doRedisStop() {
if ! $redis_local; then
echo "Redis is not hosted locally."
Expand All @@ -1309,6 +1364,9 @@ else
fi
}
#
# redis status function
#
doRedisStatus() {
if ! $redis_local; then
if isTheRedisServerRunning ;then
Expand All @@ -1328,6 +1386,35 @@ else
fi
}
#
# redis backup function
#
doRedisBackup() {
if ! $redis_local; then
echo "Redis is not hosted locally."
else
if [ -f "$redis_config_file" ]; then
local datestamp=`date +"%Y-%m-%d_%H.%M.%S"`
local daystamp=`date +"%Y-%m-%d"`
cd "${redis_config_file%/*}"
local redisBackupPath=$(sed -n 's/\r//g;s/^dir //p' "$redis_config_file"); #sed 's/\r//g' is being used to remove a line carriage in the redis.conf file.
local redisDBFilename=$(sed -n 's/\r//g;s/^dbfilename //p' "$redis_config_file"); #sed 's/\r//g' is being used to remove a line carriage in the redis.conf file.
local redisPassword=$(sed -n 's/\r//g;s/^requirepass //p' "$redis_config_file"); #sed 's/\r//g' is being used to remove a line carriage in the redis.conf file.
redis-cli -a "$redisPassword" bgsave
echo -ne "${NORMAL} Compressing Backup "
tar -jcf "${atlasbackupdir}/${daystamp}/${redisDBFilename}.${datestamp}.tar.bz2" "${redisBackupPath}/${redisDBFilename}"
if [ -f "${atlasbackupdir}/${daystamp}/${redisDBFilename}.${datestamp}.tar.bz2" ]; then
echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]"
else
echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]"
fi
echo -e "${NORMAL} Created Backup: ${GREEN} ${redisDBFilename}.${datestamp}.tar.bz2${NORMAL}"
else
logprint "Verify that the path is set correctly to your redis.conf and redis_atlas.pid file in atlasmanager.cfg."
fi
fi
}
doRunBG(){
for fd in $(ls /proc/$BASHPID/fd/); do
[[ $fd -gt 2 && $fd != 255 ]] && exec {fd}<&-
Expand Down Expand Up @@ -3366,9 +3453,6 @@ showUsage() {
Command Description
upgrade-tools Check for a new ATLAS Server Tools version and upgrades it if needed
uninstall-tools Uninstall the ATLAS Server Tools
redis-start Attempts to start Redis
redis-stop Stops Redis
redis-status Dispays the status and pid of Redis process
useconfig <name> Sets the default instance for the commands that follow
remove-mods <modid> Remove one or more mods from the steamcmd workshop directory
list-instances Lists all available instances
Expand Down Expand Up @@ -3403,6 +3487,13 @@ showUsage() {
getpid Gets the running server PID
update Check for a new ATLAS server version, if needed, stops the server, updates it, and starts it again
Redis command takes the following options:
--start Start the Redis server.
--stop Stop the Redis server.
--restart Restart the Redis server.
--status Shows if Redis is online or offline along with the pid file.
--backup Backup current Redis database to the ATLAS backup directory.
Commands which invoke steamcmd take the following options:
--verbose Show steamcmd output
--spinner Use a spinner for progress (default)
Expand Down Expand Up @@ -3714,6 +3805,9 @@ main(){
doUninstallMod "${args[@]}"
doInstallMod "${args[@]}"
;;
redis)
doRedis "${options[@]}"
;;
list-mods)
listMods
;;
Expand Down

0 comments on commit dbd6bb0

Please sign in to comment.