-
Notifications
You must be signed in to change notification settings - Fork 11
/
minecraft_bootstrap
executable file
·102 lines (79 loc) · 2.63 KB
/
minecraft_bootstrap
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
#!/bin/bash
set -e
set -x
# For testing builds
TRAVIS=$1
# Minecraft server quick-installer
#
# Stephen Wood
# www.heystephenwood.com
# https://github.com/stephen-mw/vagrant_minecraft
# Some default variables to get the ball started
VERSION='https://s3.amazonaws.com/Minecraft.Download/versions/1.8/minecraft_server.1.8.jar'
WORK_DIR='/opt/minecraft'
# The only required package is openjdk-6
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y --no-install-recommends openjdk-6-jre-headless
# We want to save persistent files, so we'll symlink over that directory
if [[ -z "${TRAVIS}" ]]; then
ln -s /vagrant/persistent_files ${WORK_DIR}
fi
test -d ${WORK_DIR}/logs || mkdir -p ${WORK_DIR}/logs
pushd ${WORK_DIR}
# Download the jar if it doesn't already exist
HEADER='Referer: https://github.com/stephendotexe/vagrant_minecraft_auto_launch'
test -f "${VERSION}" || wget --header=${HEADER} --quiet "${VERSION}"
# Upstart manages the server process
cat > /etc/init/minecraft.conf <<MINECRAFT_CONF
# Minecraft upstart script
start on (local-filesystems and net-device-up IFACE!=lo)
stop on [!12345]
respawn
chdir ${WORK_DIR}
exec java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.jar nogui > /opt/minecraft/logs/service.log 2>&1
MINECRAFT_CONF
# A logrotate script to keep the minecraft server log from getting too large
cat > /etc/logrotate.d/minecraft <<MINECRAFT_LOGROTATE
${WORK_DIR}/logs/service.log {
rotate 24
weekly
compress
notifempty
copytruncate
}
MINECRAFT_LOGROTATE
# Always accept the eula
cat > ${WORK_DIR}/eula.txt <<EULA
# By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
eula=TRUE
EULA
initctl reload-configuration
service minecraft start
# Delete the useless vagrant MOTD and install our own
test -f /etc/motd.tail && rm /etc/motd.tail
test -f /etc/update-motd.d/* && rm -r -- /etc/update-motd.d/*
cat > /etc/update-motd.d/00-header <<'DONE'
#!/bin/bash
GREEN='\e[0;32m'
LBLUE='\e[1;34m'
RESET='\e[0m'
echo -e "
${LBLUE}WELCOME TO MINECRAFT!
To stop, start, restart or check the status of the the minecraft server
process, simply run:${RESET}
${GREEN}
$ service minecraft <stop|start|restart|status>${RESET}
${LBLUE}
The runtime logs are available at /opt/minecraft/logs
To change the min or max server memory values, make the change in:${RESET}
${GREEN}
/etc/init/minecraft.conf${RESET}
${LBLUE}
And then restart the server proces.
Status of minecraft server:${RESET}
${GREEN}$(service minecraft status)${RESET}
${LBLUE}Have fun!${RESET}"
DONE
chmod +x /etc/update-motd.d/00-header
chmod 755 /etc/update-motd.d/00-header