Search code examples
linuxubunturaspberry-piminecraftsystemd

Setting up minecraft server service on usb hard drive problem


I'm trying to set up a minecraft server to play with my friends. It's my first time doing this on linux, so I have a (I believe) small problem. I can't figure out how to set up it on my usb hard drive.

Here's my minecraft.service

  GNU nano 2.9.3                                                                 minecraft.service

[Unit]
Description=Minecraft Server
After=network.target

[Service]
WorkingDirectory=/media/main/ALL/.minecraft-server

User=minecraft

Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xms512M -Xmx3584M -jar -DIReallyKnowWhatIAmDoingISwear spigot*.jar nogui

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

small edit - I removed -%i, because it's to make multi-server I believe

and here is status of service after start

● minecraft.service - Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-10-19 11:30:25 CEST; 17min ago
  Process: 1462 ExecStart=/usr/bin/screen -DmS mc- /usr/bin/java -Xms512M -Xmx3584M -jar -DIReallyKnowWhatIAmDoingISwear spigot*.jar nogui (code=exited, status=1/FAILURE)
 Main PID: 1462 (code=exited, status=1/FAILURE)

Oct 19 11:30:25 ubuntu systemd[1]: minecraft.service: Service hold-off time over, scheduling restart.
Oct 19 11:30:25 ubuntu systemd[1]: minecraft.service: Scheduled restart job, restart counter is at 5.
Oct 19 11:30:25 ubuntu systemd[1]: Stopped Minecraft Server.
Oct 19 11:30:25 ubuntu systemd[1]: minecraft.service: Start request repeated too quickly.
Oct 19 11:30:25 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Oct 19 11:30:25 ubuntu systemd[1]: Failed to start Minecraft Server.

user was created by "useradd minecraft" with no password

Distro is Ubuntu Server 18.04.3 LTS

I need it on usb hard drive because I have small sd card. In future I want to replace it with ssd on adpter


Solution

  • Ok. Thank you all for not helping me. After hours I found solution(s).

    1. I re-created user minecraft with --system
    2. Created group minecraft with --system
    3. added user to group
    4. Set home folder of minecraft user to .../.minecraft-server (when i did it on create it throwed error)

    This fixed my problem with server not starting at all, but then i cannot attach to screen. I tried -c with custom config and editing /etc/screenrc (second option totally broke screen, so I needed to reinstall it). Finally i created .screenrc in /.minecraft-server with options multiuser on and added users that can attach.

    Now it's working, but I spend about 10 hours straight to fix it...

    Creating user and group:

    adduser --system minecraft
    addgroup --system minecraft
    usermod -a -G minecraft minecraft
    usermod --home /home_folder minecraft
    

    .screenrc in minecraft's home directory:

    multiuser on
    addacl root
    addacl user1
    

    Finall version of minecraft.service in systemd:

    
    [Unit]
    Description=Minecraft Server
    After=network.target
    
    [Service]
    WorkingDirectory=/media/main/ALL/.minecraft-server
    
    User=minecraft
    Group=minecraft
    Type=forking
    
    Restart=on-failure
    #RestartSec=20 5
    
    ExecStart=/usr/bin/screen -dmS mc /usr/bin/java -Xms512M -Xmx3584M -jar -DIReallyKnowWhatIAmDoingISwear spigot-1.14.4.jar nogui
    
    ExecStop=/usr/bin/screen -p 0 -S mc -X eval 'stuff "say SERVER SHUTTING DOWN IN 15 SECONDS..."\015'
    ExecStop=/bin/sleep 5
    ExecStop=/usr/bin/screen -p 0 -S mc -X eval 'stuff "say SERVER SHUTTING DOWN IN 10 SECONDS..."\015'
    ExecStop=/bin/sleep 5
    ExecStop=/usr/bin/screen -p 0 -S mc -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS..."\015'
    ExecStop=/bin/sleep 5
    ExecStop=/usr/bin/screen -p 0 -S mc -X eval 'stuff "save-all"\015'
    ExecStop=/usr/bin/screen -p 0 -S mc -X eval 'stuff "stop"\015'
    
    [Install]
    WantedBy=multi-user.target
    
    

    To attach to screen: screen -x minecraft/mc where minecraft is user, and mc is screen name