This Bash script automates the process of sending scheduled notifications to players and restarting a Minecraft server. It uses screen to interact with the server console and ensures players are informed about the restart in advance.
- Sends countdown messages to players at predefined intervals (1 hour, 30 minutes, 15 minutes, 5 minutes, and 1 minute before the restart).
- Gracefully stops the server after notifying players.
- Customizable message system for easy adjustments.
- Supports scheduling with
crontabfor automated restarts.
- A Minecraft server running in a
screensession. - The
screencommand installed on your system.
- Ensure your Minecraft server is running in a
screensession.
Example:screen -S mc java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
- Download or copy this script to your server environment.
- Make the script executable:
chmod +x restart.sh
- Edit the
SCREEN_NAMEvariable in the script to match the name of your server's screen session (default ismc).
Run the script manually or schedule it using crontab for automatic execution.
To run the script manually:
./restart.sh-
Open your crontab file for editing:
crontab -e
-
Add the following line to schedule the script. For example, to restart the server daily at 3:00 AM:
0 3 * * * /path/to/restart.sh
Replace
/path/to/restart.shwith the full path to your script. -
Save and exit the editor. Your server will now automatically restart at the specified time.
- Modify the
send_messagefunction to change the notification messages. - Adjust the
sleepintervals if needed to fit your server's requirements.
Players will see messages like:
[Server] The server will restart in 1 hour.
[Server] The server will restart in 30 minutes.
[Server] The server will restart in 15 minutes.
[Server] The server will restart in 5 minutes.
[Server] The server will restart in 1 minute.
[Server] The server is now restarting. Please be patient.
This script is provided under the MIT License. Feel free to use, modify, and distribute it.