├── README.md ├── WakeServerOnJoin.sh └── Setup.md /README.md: -------------------------------------------------------------------------------- 1 | # [WoL] Wake a Minecraft Server when player joins 2 | 3 | #### This has to be run on a (ideally low power) PC like a Raspberry Pi that is running 24/7 to detect someone joining! 4 | #### When a player is detected the real Minecraft server PC is then started with "Wake on Lan". 5 | 6 | [How to](https://github.com/4bitFox/Wake-Minecraft-Server-on-Join/blob/master/Setup.md) 7 | -------------------------------------------------------------------------------- /WakeServerOnJoin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### SETTINGS ### 4 | # MAC of PC to be woken. 5 | MAC=XX:XX:XX:XX:XX:XX 6 | # Path to latest.log 7 | LOG=~/PathToServer/logs/latest.log 8 | # String that triggers the WoL command. (This should be fine if you use Bungeecord or Waterfall.) 9 | TRIGGER=connected 10 | # How long to wait between each check in seconds. 11 | T0=0.5 12 | # How long to wait after waking real server in seconds. 13 | T1=300 14 | 15 | 16 | while : 17 | do 18 | # Detect if someone joined (or left if you use connected as trigger, but that dun't matter :P). 19 | if tail -1 $LOG | grep -q $TRIGGER 20 | then 21 | echo "Sending wake signal to $MAC..." >> $LOG # This line just for preventing grep to detect the previous line in latest-log and spamming the WoL command. 22 | # Wake server. 23 | ## If you use wol (Arch Repo)## 24 | #wol $MAC 25 | ## If you use wakeonlan (Debian Repo) ## 26 | wakeonlan $MAC 27 | ## If you use NetCat ## => https://stackoverflow.com/questions/31588035/bash-one-line-command-to-send-wake-on-lan-magic-packet-without-specific-tool 28 | #echo -e $(echo $(printf 'f%.0s' {1..12}; printf "$(echo $MAC | sed 's/://g')%.0s" {1..16}) | sed -e 's/../\\x&/g') | nc -w1 -u -b 255.255.255.255 4000 29 | echo "Sent Wake on Lan signal to $MAC" 30 | sleep $T1 31 | else 32 | sleep $T0 33 | fi 34 | done 35 | 36 | ## Tips: 37 | # Run the script after server generates new latest.log if you have problems. (e.g. "sleep 5") 38 | # Change "fallback_kick" in messages.properties to inform the player to reconnect in a moment. (messages.properties is located in the Bungeecord or Waterfall JAR.) 39 | # You can use "jar uf waterfall-*.jar messages.properties" to inject the file. 40 | 41 | ## On the main server machine: 42 | # You can use crontab to launch the server on boot. 43 | # To turn the server off again, I used this plugin: https://www.spigotmc.org/resources/autostop.72557/ 44 | # Put the command "poweroff" at the bottom of your servers start script. This will make it... power off (obviously :D). 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Setup.md: -------------------------------------------------------------------------------- 1 | # How to: 2 | ### ATENTION! This guide is assuming that you are running the Server on a Linux system! Steps will be different on other OSes. 3 | - You should also already know how to setup a PamerMC/Spigot Minecraft Server and Waterfall/Bungeecord. 4 | - Being somewhat familiar with Linux will also help a lot. 5 | ## Setting up the real server 6 | - Enable WoL on your server PC you plan to wake up. Depends from PC to PC so you are on your own. 7 | - Setup your Server. I'm using Paper in this guide so I'll use it to explain from now on! You can get PaperMC here: https://papermc.io/downloads Instructions to set up: https://paper.readthedocs.io/en/latest/server/index.html 8 | - Make a start script for the server. We'll need it later! 9 | - Now you should have a regular PaperMC Minecraft server. In this guide we will set this Server up to be run automatically when the PC boots up and powers off after a while when no one is connected anymore. 10 | - To do this I use the "AutoStop" Plugin: https://github.com/pmdevita/AutoStop/releases 11 | - Download and install this plugin. Change the config as you desire. 12 | - Now your Server should automatically stop when noone is connected for a while. We want it to power off though! You should have a Shell script to start your Server. You have to add the "poweroff" (or different command dapending on your init system. If you dont know what I'm talking about, you are probably running systemd and can use said previous command.) to the bottom of the file. This should power off the PC when the Minecraft Server stops. 13 | - I recommend adding a delay before powering off so you can cancel it to maintain your PC for example. For this add something like "sleep 15" on a line before the "poweroff" command. Additionally you can use the echo command to print to the console that it's about to power off. 14 | 15 | 16 | ## Editing the Waterfall JAR 17 | - Download the latest release of Waterfall: https://papermc.io/downloads#Waterfall 18 | - Extract the messages.properties from the JAR with an archiver application. 19 | 20 | ![Screenshot_20210629_195612](https://user-images.githubusercontent.com/33175205/123845085-10d68680-d914-11eb-8d09-160bd86f9f3d.png) 21 | 22 | - Open up the extracted messages.properties in a text editor. 23 | - Find the "fallback_kick" option and change the message to make it clear that the player has to reconnect in a bit. Example: 24 | 25 | ![Screenshot_20210629_200353](https://user-images.githubusercontent.com/33175205/123845997-239d8b00-d915-11eb-9e30-c80b66317e56.png) 26 | - Now search for the "ping_cannot_connect" option and change it. This is going to be the MOTD that is displayed, when the server _isn't_ running. (Tipp: You can use an online MOTD generator.) I'd recommend making it clear in the MOTD that the player has to join to start the server. Example: 27 | 28 | ![Screenshot_20210629_200929](https://user-images.githubusercontent.com/33175205/123846635-eb4a7c80-d915-11eb-81d6-e96d74f1229f.png) 29 | - Change other messages if you so desire :) 30 | - Save the file. 31 | - Now we have to put your altered version of "messages.properties" back into the JAR. For that we can use the following command in the terminal: "jar of waterfall-*.jar messages.properties". 32 | 33 | ## Configuring Waterfall (to connect to the real server) 34 | - Now configure waterfall as usual to start and connect to your server. If you don't know how, here's some links that might help you: 35 | - https://paper.readthedocs.io/en/latest/waterfall/index.html 36 | - https://www.spigotmc.org/wiki/bungeecord-configuration-guide/ 37 | 38 | ## Wake the Server when a player joins 39 | - Hopefully you now have a working waterfall configuration which you can join if the real Server PC is already running. 40 | - Now we have to start the real PC automatically when someone joins. Put the WakeServerOnJoin.sh script into the foler you previously setup waterfall in. 41 | - Open the script in a text editor and adjust the values. Put the MAC adress of the PC you want to start when someone joins and the path to waterfalls logfile. Example: 42 | ![Screenshot from 2021-11-21 11-35-47](https://user-images.githubusercontent.com/33175205/142758500-d7a9bfa1-4c16-4baa-abc5-fcac4fc2455b.png) 43 | - Uncomment which command you want to use to send a WoL signal. "wakeonlan" is uncommented by default! 44 | ![Screenshot from 2021-11-21 11-47-49](https://user-images.githubusercontent.com/33175205/142758834-43cec19c-d937-46b7-be87-e271802ffa33.png) 45 | - Save the file and give it permissions to run: "chmod +x WakeServerOnJoin.sh" 46 | - Run it with "./WakeServerOnJoin.sh" (Make sure that Waterfall is already running!) 47 | - If everything worked the real server schould now start. After waiting a short amount of time you should be able to reconnect and be forwarded to the real Server. Bravo! You are done. 48 | --------------------------------------------------------------------------------