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

Solution 1:

I created a file called [email protected] 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.