-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame-server-start.sh
executable file
·165 lines (165 loc) · 5.56 KB
/
game-server-start.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
#
# ----------------------------------------------------------------------------
# Start game-server(s) as disconnected background 'screen' processes
# ============================================================================
# Created: 2024-03-25, by [email protected]
# Last modified: 2024-06-13, by [email protected]
# ----------------------------------------------------------------------------
#
# Purpose:
#
# Run a dedicated game-server instance in the backgound using GNU "Screen" utlity.
# Does NOT check if the instance may already be latest version.
# DOES stop any instance with the same name already running in the background.
# Accepts multiple gameserverids in the same command-line.
#
# Usage / command-line parameters:
#
# gameserverid
#
# The game-server identifier(s) for the game-server(s) to start.
#
# Example:
#
# ./game-server-start.sh gameserverid1 gameserverid2 gameserveridN;
#
# ----------------------------------------------------------------------------
#
# Figure-out where the scripts folder is located ...
#
SCRIPTS_FOLDER="$( dirname -- "$( readlink -f -- "$0"; )"; )";
#
# Include the base script dependancies ...
#
source $SCRIPTS_FOLDER/include/include-base.inc;
#
# Process command-line parameters ...
#
# Check how many parameters were passed ...
#
GAMESERVERIDCOUNT="$#";
if [ $GAMESERVERIDCOUNT -lt 1 ]; then
MESSAGE="${ANSI_REDLT}$(figlet "Error:")${ANSI_OFF}\n";
MESSAGE+="${ANSI_WHITE}At least one (1) gameserverid must be specified!${ANSI_OFF}";
echo -e "$MESSAGE";
if [[ $SCRIPT_LOG_FILE ]]; then
echo -e "$MESSAGE" | ansi2txt >> "$SCRIPT_LOG_FILE";
fi;
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
exit 1;
fi;
#
# Loop throuch each gameserverid and process it ...
#
while [ $# -gt 0 ]; do
#
# Set gameserverid to current parameter ...
#
GAMESERVERID=$1;
#
# Determine script log file ...
#
SCRIPT_LOG_FILE="$LOGS_FOLDER/$GAMESERVERID-start.log";
#
# Display start of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputbegin.inc;
#
# Process/validate parameter GAMESERVERID ...
#
source $SCRIPTS_FOLDER/include/include-gameserverid.inc;
#
# Retrive data from game-types table for specific GAMESERVERID ...
#
source $SCRIPTS_FOLDER/include/include-gameserverfields.inc;
#
# Process/validate parameter GAMETYPEID ...
#
source $SCRIPTS_FOLDER/include/include-gametypeid.inc;
#
# Retrive data from game-types table for specific GAMETYPEID ...
#
source $SCRIPTS_FOLDER/include/include-gametypefields.inc;
#
# Define some variables ...
#
INSTALL_FOLDER="$SERVERS_INSTALL_FOLDER/$GAMESERVERID";
BASE_FOLDER="$INSTALL_FOLDER/$MODSUBFOLDER";
SCREEN_LOG_FILE="$LOGS_FOLDER/$GAMESERVERID-screen.log";
GAME_SERVER_STOP_COMMAND="$SCRIPTS_FOLDER/game-server-stop.sh $GAMESERVERID";
GAME_SERVER_RUN_COMMAND="$SCRIPTS_FOLDER/game-server-run.sh $GAMESERVERID";
#
# Display what server is being started ...
#
echo "Game-server selected: [ID=$GAMESERVERID] $SERVERDESC";
echo "Game-server selected: [ID=$GAMESERVERID] $SERVERDESC" >> "$SCRIPT_LOG_FILE";
#
# Check if the game-server is already started under GNU 'screen'
#
SCREEN_LIST_CAPTURE=$(screen -ls | grep $GAMESERVERID);
if [[ $SCREEN_LIST_CAPTURE == *"$GAMESERVERID"* ]]; then
SCREEN_RUNNING_CHECK=true;
else
SCREEN_RUNNING_CHECK=false;
fi;
#
# If in verbose mode, display and log some extra stuff ...
#
if [ "$SCRIPTS_VERBOSE" == true ]; then
echo "Install folder: $INSTALL_FOLDER";
echo "Install folder: $INSTALL_FOLDER" >> "$SCRIPT_LOG_FILE";
echo "Script log file: $SCRIPT_LOG_FILE";
echo "Script log file: $SCRIPT_LOG_FILE" >> "$SCRIPT_LOG_FILE";
echo "Screen log file: $SCREEN_LOG_FILE";
echo "Screen log file: $SCREEN_LOG_FILE" >> "$SCRIPT_LOG_FILE";
echo "Stop command: $GAME_SERVER_STOP_COMMAND";
echo "Stop command: $GAME_SERVER_STOP_COMMAND" >> "$SCRIPT_LOG_FILE";
echo "Run command: $GAME_SERVER_RUN_COMMAND";
echo "Run command: $GAME_SERVER_RUN_COMMAND" >> "$SCRIPT_LOG_FILE";
echo "Related screen already started?: $SCREEN_RUNNING_CHECK";
echo "Related screen already started?: $SCREEN_RUNNING_CHECK" >> "$SCRIPT_LOG_FILE";
fi;
#
# Stop an existing game-server, if is already started under GNU 'screen'
#
if [ "$SCREEN_RUNNING_CHECK" == true ]; then
echo "Stopping background instance of this game server ... ";
echo "Stopping background instance of this game server ... " >> "$SCRIPT_LOG_FILE";
$GAME_SERVER_STOP_COMMAND;
echo "Stopped background instance of this game server. ";
echo "Stopped background instance of this game server. " >> "$SCRIPT_LOG_FILE";
else
echo "No background instance of this game server detected.";
echo "No background instance of this game server detected." >> "$SCRIPT_LOG_FILE";
fi;
#
# Starting this server in the background using the GNU "screen" utility ...
#
echo "Starting game with the 'screen' utility ... ";
echo "Starting game with the 'screen' utility ... " >> "$SCRIPT_LOG_FILE";
screen -L -Logfile "$SCREEN_LOG_FILE" -A -m -d -S $GAMESERVERID $GAME_SERVER_RUN_COMMAND;
#
# Display list of screen sessions ...
#
echo "Displaying list of 'screen' processes, AFTER start attempt ...";
echo "Displaying list of 'screen' processes, AFTER start attempt ...">> "$SCRIPT_LOG_FILE";
screen -list 2>&1;
screen -list 2>&1 >> "$SCRIPT_LOG_FILE";
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
#
# Use 'shift' to move to next parameter passed ...
#
shift;
echo "";
echo "" >> "$SCRIPT_LOG_FILE";
done;
#
# ... thats all folks!
#