-
Notifications
You must be signed in to change notification settings - Fork 1
/
start-server
63 lines (52 loc) · 1.51 KB
/
start-server
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
#!/bin/sh
SERVER_PORT_BASEDIR="."
SERVER_RESTARTS=1
SERVER_OUTPUT_LOG_BASENAME="/tmp/server_output"
PLAYER_PORT=7500
BUILDER_PORT=7501
TEST_PORT=7502
# Figure out what port the user wants
case "$1" in
pp*) port_number=$PLAYER_PORT;;
bp*) port_number=$BUILDER_PORT;;
tp*) port_number=$TEST_PORT;;
*) echo "Please select a port: pp, bp, or tp"; exit 0;;
esac
# Make sure we have an executable
if [ ! -x $SERVER_PORT_BASEDIR/bin/server ]
then
echo "Error: Couldn't find the $1 server executable!"
exit 0;
fi
# Change the working directory
cd $SERVER_PORT_BASEDIR
echo "The working directory is now" `pwd`
# Remove the bootlock
if [ -f "$SERVER_PORT_BASEDIR/lib/booting" ]
then
echo "Removing stale boot lock."
rm -v "$SERVER_PORT_BASEDIR/lib/booting"
fi
# Remove stdout logs
if [ -f "$SERVER_OUTPUT_LOG_BASENAME.$port_number-1.txt" ]
then
echo "Removing stale stdout logs."
rm -v $SERVER_OUTPUT_LOG_BASENAME.$port_number-*.txt
fi
# Start the RPI Engine
echo "Starting the Awesome RPI Engine on port: $port_number, will attempt $SERVER_RESTARTS restarts"
for i in 'seq 1 $SERVER_RESTARTS'
do
echo "Logging stdout to $SERVER_OUTPUT_LOG_BASENAME.$port_number-$i.txt"
$SERVER_PORT_BASEDIR/bin/server $port_number 2>&1 | tee "$SERVER_OUTPUT_LOG_BASENAME.$port_number-$i.txt"
if [ -f "$SERVER_PORT_BASEDIR/lib/booting" ]
then
echo "Server quit during boot sequence."
break;
fi
wait
done
# Finish up
echo "The Awesome RPI Engine has shutdown. "
cd - > /dev/null
echo "The working directory is now" `pwd`