Page 1 of 1

Minecraft Server (Auto start scripts)

Posted: Wed Dec 06, 2023 6:13 pm
by Kosmito
This script allow to send message when you restart or shutdown the server warning the users

this script on ubuntu server go on

Code: Select all

bash#: /etc/systemd/system
make a file with the name what ever you like

Code: Select all

bash#: /etc/systemd/system/nano chooseyourname.service
copy this code and change the parts you need

Code: Select all

[Unit]
Description=Minecraft Dedicated Server
Documentation=https://yourwebsite
After=network.target

[Service]
RemainAfterExit=yes
WorkingDirectory=/home/youruser/Server
User=kosmito
# Start Screen, Java, and Minecraft
ExecStart=screen -s mc -d -m java -Xms3196M -Xmx5396M -jar server.jar nogui  # change the memory depending of your server ( delete this )
# Tell Minecraft to gracefully stop.
# Ending Minecraft will terminate Java
# systemd will kill Screen after the 60-second delay. No explicit kill for Screen needed
ExecStop=screen -p 0 -S mc -X eval 'stuff "say SERVER SHUTTING DOWN OR MAYBE RESTART?. Saving map..>
ExecStop=screen -p 0 -S mc -X eval 'stuff "save-all"\015'
ExecStop=screen -p 0 -S mc -X eval 'stuff "stop"\015'
ExecStop=sleep 60

[Install]
WantedBy=multi-user.target
save the file with the keys CTRL + X confirm with Y and enter

for make the server autostart when you turn on put this

Code: Select all

bash#: systemctl enable yournamefile.service
and start the server or restart the server and the minecraft server start automatically