forked from yujiod/docker-mineos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.sh
61 lines (51 loc) · 1.45 KB
/
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
#!/bin/sh
SCRIPTPATH=/usr/games/minecraft
SERVER=server.py
CONSOLE=mineos_console.py
CONFIGFILE=/usr/games/minecraft/mineos.conf
DATAPATH=/var/games/minecraft
USER=minecraft
GROUP=minecraft
# Create dooes not exists directories
chown $USER:$GROUP $DATAPATH
if [ ! -d $DATAPATH/ssl_certs ]; then
sudo -u $USER mkdir $DATAPATH/ssl_certs
fi
if [ ! -d $DATAPATH/log ]; then
sudo -u $USER mkdir $DATAPATH/log
fi
if [ ! -d $DATAPATH/run ]; then
sudo -u $USER mkdir $DATAPATH/run
fi
# Changing password
if [ ! -f $SCRIPTPATH/.initialized ]; then
if [ "$PASSWORD" = "" ]; then
PASSWORD=`pwgen 10 1`
echo "Login password is \"$PASSWORD\""
fi
echo "$USER:$PASSWORD" | chpasswd
sudo -u $USER touch $SCRIPTPATH/.initialized
fi
# Generate ssl certrificates
CERT_DIR=$DATAPATH/ssl_certs
if [ ! -f "$CERT_DIR/mineos.pem" ]; then
sudo -u $USER CERTFILE=$CERT_DIR/mineos.pem CRTFILE=$CERT_DIR/mineos.crt KEYFILE=$CERT_DIR/mineos.key ./generate-sslcert.sh
fi
# Starting minecraft servers
sudo -u $USER python $SCRIPTPATH/$CONSOLE -d $DATAPATH restore
sudo -u $USER python $SCRIPTPATH/$CONSOLE -d $DATAPATH start
# Trap function
_trap() {
kill $PID
# Wait for shutdown
ALIVE=1
while [ $ALIVE != 0 ]; do
ALIVE=`pgrep $PID | wc -l`
sleep 1
done
sudo -u $USER python $SCRIPTPATH/$CONSOLE -d $DATAPATH stop
}
trap '_trap' 15
# Starting Supervisor
supervisord -c /etc/supervisor/supervisord.conf & PID=$!
wait $PID