forked from thmhoag/arkserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·140 lines (116 loc) · 5.33 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPODIR="$(dirname "$SCRIPTDIR")"
# always fail script if a cmd fails
set -eo pipefail
echo "###########################################################################"
echo "# Ark Server - " `date`
echo "###########################################################################"
echo "Ensuring correct permissions..."
sudo chown steam:steam -R /ark
sudo chown steam:steam -R /home/steam
# Remove arkmanager tracking files if they exist
# They can cause issues with starting the server multiple times
# due to the restart command not completing when the container exits
echo "Cleaning up any leftover arkmanager files..."
[ -f /ark/server/ShooterGame/Saved/.ark-warn-main.lock ] && rm -rf /ark/server/ShooterGame/Saved/.ark-warn-main.lock
[ -f /ark/server/ShooterGame/Saved/.ark-update.lock ] && rm -rf /ark/server/ShooterGame/Saved/.ark-update.lock
[ -f /ark/server/ShooterGame/Saved/.ark-update.time ] && rm -rf /ark/server/ShooterGame/Saved/.ark-update.time
[ -f /ark/server/ShooterGame/Saved/.arkmanager-main.pid ] && rm -rf /ark/server/ShooterGame/Saved/.arkmanager-main.pid
[ -f /ark/server/ShooterGame/Saved/.arkserver-main.pid ] && rm -rf /ark/server/ShooterGame/Saved/.arkserver-main.pid
[ -f /ark/server/ShooterGame/Saved/.autorestart ] && rm -rf /ark/server/ShooterGame/Saved/.autorestart
[ -f /ark/server/ShooterGame/Saved/.autorestart-main ] && rm -rf /ark/server/ShooterGame/Saved/.autorestart-main
# Create directories if they don't exist
[ ! -d /ark/config ] && mkdir /ark/config
[ ! -d /ark/log ] && mkdir /ark/log
[ ! -d /ark/backup ] && mkdir /ark/backup
[ ! -d /ark/staging ] && mkdir /ark/staging
echo "Creating arkmanager.cfg from environment variables..."
echo -e "# Ark Server Tools - arkmanager config\n# Generated from container environment variables\n\n" > /ark/config/arkmanager.cfg
if [ -f /ark/config/arkmanager_base.cfg ]; then
cat /ark/config/arkmanager_base.cfg >> /ark/config/arkmanager.cfg
fi
echo -e "\n\narkserverroot=\"/ark/server\"\n" >> /ark/config/arkmanager.cfg
printenv | sed -n -r 's/am_(.*)=(.*)/\1=\"\2\"/ip' >> /ark/config/arkmanager.cfg
if [ ! -d /ark/server ] || [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ]; then
echo "No game files found. Installing..."
mkdir -p /ark/server/ShooterGame/Saved/SavedArks
mkdir -p /ark/server/ShooterGame/Saved/Config/LinuxServer
mkdir -p /ark/server/ShooterGame/Content/Mods
mkdir -p /ark/server/ShooterGame/Binaries/Linux/
fi
if [ ! -f /ark/config/crontab ]; then
echo "Creating crontab..."
cat << EOF >> /ark/config/crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# Examples for Ark:
# 0 * * * * arkmanager update # update every hour
# */15 * * * * arkmanager backup # backup every 15min
# 0 0 * * * arkmanager backup # backup every day at midnight
*/30 * * * * arkmanager update --update-mods --warn --saveworld
10 */8 * * * arkmanager saveworld && arkmanager backup
15 10 * * * arkmanager restart --warn --saveworld
EOF
fi
# If there is uncommented line in the file
CRONNUMBER=`grep -v "^#" /ark/config/crontab | wc -l`
if [ $CRONNUMBER -gt 0 ]; then
echo "Starting cron service..."
sudo service cron start
echo "Loading crontab..."
# We load the crontab file if it exist.
crontab /ark/config/crontab
else
echo "No crontab set."
fi
# Create symlinks for configs
[ -f /ark/config/AllowedCheaterSteamIDs.txt ] && ln -sf /ark/config/AllowedCheaterSteamIDs.txt /ark/server/ShooterGame/Saved/AllowedCheaterSteamIDs.txt
[ -f /ark/config/Engine.ini ] && ln -sf /ark/config/Engine.ini /ark/server/ShooterGame/Saved/Config/LinuxServer/Engine.ini
[ -f /ark/config/Game.ini ] && ln -sf /ark/config/Game.ini /ark/server/ShooterGame/Saved/Config/LinuxServer/Game.ini
[ -f /ark/config/GameUserSettings.ini ] && ln -sf /ark/config/GameUserSettings.ini /ark/server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini
if [[ "$VALIDATE_SAVE_EXISTS" = true && ! -z "$am_ark_AltSaveDirectoryName" && ! -z "$am_serverMap" ]]; then
savepath="/ark/server/ShooterGame/Saved/$am_ark_AltSaveDirectoryName"
savefile="$am_serverMap.ark"
echo "Validating that a save file exists for $am_serverMap"
echo "Checking $savepath"
if [[ ! -f "$savepath/$savefile" ]]; then
echo "$savefile not found!"
echo "Attempting to notify via Discord..."
arkmanager notify "Critical error: unable to find $savefile in $savepath!"
# wait on failure so we don't spam docker logs
sleep 5m
exit 1
else
echo "$savefile found."
fi
else
echo "Save file validation is not enabled."
fi
if [[ $BACKUP_ONSTART = true ]]; then
echo "Backing up on start..."
arkmanager backup
else
echo "Backup on start is not enabled."
fi
function stop {
arkmanager broadcast "Server is shutting down"
arkmanager notify "Server is shutting down"
arkmanager stop
exit 0
}
# Stop server in case of signal INT or TERM
trap stop INT
trap stop TERM
# TODO: Provide IF statement here with ENV variable
# to allow server logs to be scraped from RCON to stdout
# bash -c ./log.sh &
arkmanager start --no-background --verbose &
arkmanpid=$!
wait $arkmanpid