Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make a startup service for a Minecraft server that has a start.sh file?

I installed a modded FTB server to my Ubuntu Server, created a user and group called "ftb", and gave it its own directory /opt/ftb/ that contains a folder with the server files. In the server folder, there is a start.sh file to start the server. How do I make a system service file so I can use commands such as systemctl status ftbacademy.service, systemctl start ftbacademy.service, and systemctl stop ftbacademy.service. Upon stopping the server I wish for it to save and then close the server. What would the .service file look like? I know it has to be placed in /etc/systemd/system/, but I don’t know how to write the file that would make the ftb user open it’s own virtual terminal or whatever to be able to save the world and then stop the server.

Ubuntu Server Version 20.04.3

FTB Academy 1.16 Server Files Download Site Used: https://feed-the-beast.com/modpacks/88/server/2077 I selected the Linux download option then ran the install file to automatically download the server files.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am also using a different version of JDK to run the server file so I changed the start.sh file to this:

#!/bin/bash
if ! grep -q "eula=true" eula.txt; then
    echo "Do you agree to the Mojang EULA available at https://account.mojang.com/documents/minecraft_eula ?"
    read -N 1 -p "[y/n] " EULA
    if [ "$EULA" = "y" ]; then
        echo "eula=true" > eula.txt
        echo
    fi
fi
/usr/lib/jvm/java-11-openjdk-amd64/bin/java -javaagent:log4jfix/Log4jPatcher-1.0.0.jar -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -Xmx5000M -Xms4000M -jar forge-1.16.5-36.2.2.jar nogui

>Solution :

I created a file called ftb@.service at the location /etc/systemd/system/. The file contains the following:

[Unit]
Description=FTB Server: %i
After=network.target

[Service]
WorkingDirectory=/opt/ftb/%i

User=ftb
Group=ftb

Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i bash start.sh

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 15 SECONDS..."\015'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 10 SECONDS..."\015'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS..."\015'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\015'

[Install]
WantedBy=multi-user.target

Then I used systemctl enable ftb@academy and systemctl start ftb@academy to enable and start the server. I also realized that when I initially created the ftb user and gave it ownership of the folder that I didn’t give it permission of the subfolders, so it was denied permission to start the server.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading