Update for new AWS image style

Support old minecraft versions
This commit is contained in:
2020-12-07 19:50:30 +00:00
parent 1b6ec8682f
commit 9e0b04afdc
6 changed files with 36 additions and 12 deletions

View File

@@ -2,13 +2,13 @@
## Installing
Assuming user is `ubuntu`. Extract in `/home/ubuntu/minecraft`
Assuming user is `ubuntu`. Extract in `/home/ubuntu/control`
# Install systemd services
```
mkdir -p /home/ubuntu/.config/systemd/user
ln -s /home/ubuntu/minecraft/services/set_initial_ttl.service /home/ubuntu/.config/systemd/user/set_initial_ttl.service
ln -s /home/ubuntu/minecraft/services/ensure_running.service /home/ubuntu/.config/systemd/user/ensure_running.service
ln -s /home/ubuntu/control/services/set_initial_ttl.service /home/ubuntu/.config/systemd/user/set_initial_ttl.service
ln -s /home/ubuntu/control/services/ensure_running.service /home/ubuntu/.config/systemd/user/ensure_running.service
systemctl --user enable set_initial_ttl
systemctl --user enable ensure_running
@@ -18,5 +18,8 @@ loginctl show-user ubuntu --property Linger
# Setup user linger and crontab
```
loginctl enable-linger ubuntu
crontab -l /home/ubuntu/minecraft/crontab
crontab -l /home/ubuntu/control/crontab
```
# Install pip dependencies
sudo pip install -r /home/ubuntu/control/requirements.txt

View File

@@ -3,10 +3,14 @@
# If exists tmux session
# If Responds to queries
SERVER_DIR='/home/ubuntu/minecraft/servers/kincls'
TMUX_NAME='minecraft kincls server'
SERVER_DIR='/home/ubuntu/minecraft'
TMUX_NAME='minecraft server'
LIVE_UNTIL="/home/ubuntu/minecraft/live_until.txt"
json_has() {
cat - | python3 -c "import sys, json; sys.exit(0 if '$1' in json.load(sys.stdin) else 1)"
}
json_parse() {
cat - | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])"
}
@@ -51,6 +55,16 @@ server_responsive() {
silent_exitcode /usr/local/bin/mcstatus localhost ping
}
get_nplayers() {
json="$(/usr/local/bin/mcstatus localhost json)"
if `echo $json | json_has player_count`; then
echo $json | json_parse player_count
return
fi
status="$(/usr/local/bin/mcstatus localhost status)"
echo "$status" | grep players: | sed 's/.*\([0-9]\+\)\/.*/\1/g'
}
n_logins="$(w -h | wc -l)"
echo "$(date) [$n_logins logins]"
@@ -67,7 +81,7 @@ else
fi
if server_responsive; then
n_players=$(/usr/local/bin/mcstatus localhost json | json_parse player_count)
n_players=$(get_nplayers)
echo "Server responsive. $n_players players online"
if [ "$n_players" -gt 0 ]; then
# Keep alive as players are online

View File

@@ -1,2 +1,2 @@
* * * * * /home/ubuntu/minecraft/autoshutdown.sh
* * * * * /home/ubuntu/minecraft/load.sh
* * * * * /home/ubuntu/control/autoshutdown.sh
* * * * * /home/ubuntu/control/load.sh

View File

@@ -1,4 +1,10 @@
#!/bin/bash
cd /home/ubuntu/minecraft/servers/kincls
tmux new-session -Ad -s "minecraft kincls server" "java -Xmx1024M -Xms1024M -jar server.jar nogui"
cd /home/ubuntu/minecraft
if [ -f "start.sh" ]; then
cmd="/bin/bash start.sh"
else
cmd="java -Xmx1024M -Xms1024M -jar server.jar nogui"
fi
tmux new-session -Ad -s "minecraft server" $cmd

View File

@@ -2,7 +2,7 @@
export TZ="Europe/Stockholm"
LOGPATH="/home/ubuntu/minecraft/logs"
LOGPATH="/home/ubuntu/control/logs"
LOGFILE="$LOGPATH/$(date "+%F").log"
timestamp() {

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
mcstatus