Update for new AWS image style
Support old minecraft versions
This commit is contained in:
11
README.md
11
README.md
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
|
||||||
Assuming user is `ubuntu`. Extract in `/home/ubuntu/minecraft`
|
Assuming user is `ubuntu`. Extract in `/home/ubuntu/control`
|
||||||
|
|
||||||
# Install systemd services
|
# Install systemd services
|
||||||
```
|
```
|
||||||
mkdir -p /home/ubuntu/.config/systemd/user
|
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/control/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/ensure_running.service /home/ubuntu/.config/systemd/user/ensure_running.service
|
||||||
|
|
||||||
systemctl --user enable set_initial_ttl
|
systemctl --user enable set_initial_ttl
|
||||||
systemctl --user enable ensure_running
|
systemctl --user enable ensure_running
|
||||||
@@ -18,5 +18,8 @@ loginctl show-user ubuntu --property Linger
|
|||||||
# Setup user linger and crontab
|
# Setup user linger and crontab
|
||||||
```
|
```
|
||||||
loginctl enable-linger ubuntu
|
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
|
||||||
|
|||||||
@@ -3,10 +3,14 @@
|
|||||||
# If exists tmux session
|
# If exists tmux session
|
||||||
# If Responds to queries
|
# If Responds to queries
|
||||||
|
|
||||||
SERVER_DIR='/home/ubuntu/minecraft/servers/kincls'
|
SERVER_DIR='/home/ubuntu/minecraft'
|
||||||
TMUX_NAME='minecraft kincls server'
|
TMUX_NAME='minecraft server'
|
||||||
LIVE_UNTIL="/home/ubuntu/minecraft/live_until.txt"
|
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() {
|
json_parse() {
|
||||||
cat - | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])"
|
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
|
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)"
|
n_logins="$(w -h | wc -l)"
|
||||||
echo "$(date) [$n_logins logins]"
|
echo "$(date) [$n_logins logins]"
|
||||||
|
|
||||||
@@ -67,7 +81,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if server_responsive; then
|
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"
|
echo "Server responsive. $n_players players online"
|
||||||
if [ "$n_players" -gt 0 ]; then
|
if [ "$n_players" -gt 0 ]; then
|
||||||
# Keep alive as players are online
|
# Keep alive as players are online
|
||||||
|
|||||||
4
crontab
4
crontab
@@ -1,2 +1,2 @@
|
|||||||
* * * * * /home/ubuntu/minecraft/autoshutdown.sh
|
* * * * * /home/ubuntu/control/autoshutdown.sh
|
||||||
* * * * * /home/ubuntu/minecraft/load.sh
|
* * * * * /home/ubuntu/control/load.sh
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd /home/ubuntu/minecraft/servers/kincls
|
cd /home/ubuntu/minecraft
|
||||||
tmux new-session -Ad -s "minecraft kincls server" "java -Xmx1024M -Xms1024M -jar server.jar nogui"
|
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
|
||||||
|
|||||||
2
load.sh
2
load.sh
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
export TZ="Europe/Stockholm"
|
export TZ="Europe/Stockholm"
|
||||||
|
|
||||||
LOGPATH="/home/ubuntu/minecraft/logs"
|
LOGPATH="/home/ubuntu/control/logs"
|
||||||
LOGFILE="$LOGPATH/$(date "+%F").log"
|
LOGFILE="$LOGPATH/$(date "+%F").log"
|
||||||
|
|
||||||
timestamp() {
|
timestamp() {
|
||||||
|
|||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
mcstatus
|
||||||
Reference in New Issue
Block a user