-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconanexiles.init
154 lines (150 loc) · 4.18 KB
/
conanexiles.init
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
### BEGIN INIT INFO
# Provides: conanexiles
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Conan Exiles Dedicated Server
### END INIT INFO
# I suppose I should put the variables in a /etc/default/conanexiles file
USERNAME=steam
SERVER_DIR="/home/steam/conanexiles"
SERVER_PORT=7778
QUERY_PORT=14001
MAX_PLAYERS=10
SCRIPTNAME=/etc/init.d/conanexiles
# If you want to the server to only listen on a specific IP address, then uncomment it below.
#IP_ADDRESS=127.0.0.1
##############################################################################
### BEGIN SCRIPT
PATH=/usr/sbin:/usr/bin:/sbin:/bin
NAME=conanexiles-${USERNAME}-${SERVER_PORT}
SERVER_LISTEN_ADDRESS="*:${SERVER_PORT}"
QUERY_LISTEN_ADDRESS="*:${QUERY_PORT}"
OPTIONS="-log -MaxPlayers=$MAX_PLAYERS -Port=$SERVER_PORT -QueryPort=$QUERY_PORT"
if [ ! -z $IP_ADDRESS ]; then
OPTIONS="$OPTIONS -Multihome=$IP_ADDRESS";
SERVER_LISTEN_ADDRESS="${IP_ADDRESS}:${SERVER_PORT}"
QUERY_LISTEN_ADDRESS="${IP_ADDRESS}:${QUERY_PORT}"
fi
DESC="Conan Exiles in $SERVER_DIR as $USERNAME on server port ${SERVER_LISTEN_ADDRESS}, and query port ${QUERY_LISTEN_ADDRESS}"
function get_pid() {
PID=$(lsof -i -n | grep $USERNAME | grep UDP | grep "${SERVER_LISTEN_ADDRESS}" | grep ConanSand | awk '{print $2}')
if [ ! -z ${PID} ]; then
echo $PID
else
return 1
fi
}
case "$1" in
start)
echo -n "Starting ${DESC}: " "$NAME"
screen -S $NAME -d -m su - $USERNAME -s /bin/bash -c "xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' /opt/wine-staging/bin/wine64 ${SERVER_DIR}/ConanSandboxServer.exe $OPTIONS" || exit 1
until get_pid > /dev/null; do sleep 1; done
PID=$(get_pid)
echo $PID > /run/${NAME}.pid
echo "."
;;
stop)
PID=$(get_pid)
if [ -z $PID ]; then
echo "$NAME isn't running"
exit 1
else
echo -n "Stopping $DESC" "$NAME"
kill $PID || exit 1
rm -f /run/${NAME}.pid
while get_pid > /dev/null; do sleep 1; done
echo "."
fi
;;
restart)
$0 stop
$0 start
;;
status)
PID=$(get_pid)
if [ -z $PID ]; then
echo "$NAME is not running"
else
echo "$NAME is running"
fi
;;
connect)
screen -r $NAME
;;
update)
PID=$(get_pid)
if [ ! -z $PID ]; then
echo "$NAME is still running"
exit 1
fi
echo "Updating ..."
su - $USERNAME -s /bin/bash -c "steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir ${SERVER_DIR} +login anonymous +app_update 443030 validate +quit"
;;
backup)
PID=$(get_pid)
if [ ! -z $PID ]; then
echo "$NAME is still running"
exit 1
fi
echo "Backing up server files"
if [ ! -d "${SERVER_DIR}/backup" ]; then
su - $USERNAME -s /bin/bash -c "mkdir -p ${SERVER_DIR}/backup"
fi
BACKUP_FILE="${SERVER_DIR}/backup/$(date +%Y%m%d-%H%M).tar.gz"
printf "creating backup archive $BACKUP_FILE"
su - $USERNAME -s /bin/bash -c "tar -zcf $BACKUP_FILE -C ${SERVER_DIR} ConanSandbox/Saved"
echo .
;;
restore)
if [ -z $2 ]; then
echo "USAGE: $0 restore <archive>"
exit 1
fi
if [ ! -f "$2" ]; then
echo "$2 doesn't exist"
exit 1
fi
PID=$(get_pid)
if [ ! -z $PID ]; then
echo "$NAME is still running"
exit 1
fi
if $(lsof | grep ${SERVER_DIR}/ConanSandbox/Saved > /dev/null ); then
echo "still running"
sleep 5
fi
DATE=$(date +%Y%m%d-%H%M)
printf "renameing ${SERVER_DIR}/ConanSandbox/Saved ${SERVER_DIR}/ConanSandbox/Saved.${DATE}"
su - $USERNAME -s /bin/bash -c "mv ${SERVER_DIR} ConanSandbox/Saved ConanSandbox/Saved.${DATE}"
echo .
printf "restoring backup archive $BACKUP_FILE"
su - $USERNAME -s /bin/bash -c "tar -zxf $BACKUP_FILE -C ${SERVER_DIR}"
echo .
$0 start
;;
checkgamedb)
if ! $(which sqlite3 > /dev/null); then
echo "ABORTING: sqlite3 is not installed";
exit 1;
fi
PID=$(get_pid)
if [ ! -z $PID ]; then
echo "ABORTING: $NAME is still running"
exit 1
fi
echo "checking saved game files"
cd ${SERVER_DIR}/ConanSandbox/Saved
for a in game*.db; do
echo "$a"
sqlite3 $a "pragma integrity_check"
done
;;
*)
echo "usage: $0 <start|stop|restart|status|connect|update|backup|restore <archive>|checkgamedb>"
exit 1
;;
esac
exit 0