Jump to content

Minecraft server systemd service, screen: Error: Empty session-name?

I was following a guide on how to setup a minecraft server as a systemd service here. I followed all the steps to create the user and group and all that good stuff. I had trouble with the script so I got help from someone else, they gave me their script they use, I modified it for my needs and saved it as /etc/systemd/system/minecraft.service. Pastebin. Unfortunately they stopped responding to that thread. When I do "systemctl start minecraft.service" I get growing CPU and RAM usage showing there's something going on, then it dies. "systemctl status minecraft.service" gives me this, and "journalctl -xe" gives me this. I'm kinda stuck, I'm pretty sure this error with screen is the cause, but I can't figure out what's wrong exactly and how to fix it.

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

Well there are some issues, however they are probably not the cause of the problem.

- Remove #!/bin/bash from the service file
- Call

sudo chown root:root /etc/systemd/system/minecraft.service
sudo chmod 644 /etc/systemd/system/minecraft.service

 

I tried the general service file which seem to work, however I don't have a bukkit installation. So what you could try is using this service file:

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

[Service]
WorkingDirectory = /opt/minecraft/bukkit
Type = simple
User = minecraft
Group = minecraft
ExecStart = /usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#ExecStop = /usr/local/bin/mcstop %i
RemainAfterExit=yes

[Install]
WantedBy = multi-user.target

or

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

[Service]
WorkingDirectory = /opt/minecraft/bukkit
Type = simple
User = minecraft
Group = minecraft
ExecStart = /usr/bin/screen -mS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#ExecStop = /usr/local/bin/mcstop %i

[Install]
WantedBy = multi-user.target

If still in trouble post the same logs/outputs you posted before, I would prefer them inside this thread for convenience though (if not too long).

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, lal12 said:

If still in trouble post the same logs/outputs you posted before, I would prefer them inside this thread for convenience though (if not too long).

The first script launched the minecraft server process, seen in htop, then ended in about 5 seconds like usual. The 2nd script failed to launch the process at all. I noticed the second script had "-mS" instead of the usual "-dmS" so I tried it with and without the "d", exact same result, the logs came from the script without the "d".

 

First and 2nd scripts, "journalctl -xe" was too long for this thread.

 
root@ubuntu:/opt/minecraft/bukkit# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Apr 03 21:39:07 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 03 21:39:07 ubuntu systemd[1]: Failed to start Launch Minecraft Server.
Apr 03 21:39:28 ubuntu systemd[1]: Starting Launch Minecraft Server...
Apr 03 21:39:28 ubuntu systemd[1556]: minecraft.service: Changing to the requested working directory failed: No such file or directory
Apr 03 21:39:28 ubuntu systemd[1556]: minecraft.service: Failed at step CHDIR spawning /usr/bin/screen: No such file or directory
Apr 03 21:39:28 ubuntu systemd[1]: minecraft.service: Control process exited, code=exited status=200
Apr 03 21:39:28 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 03 21:39:28 ubuntu systemd[1]: Failed to start Launch Minecraft Server.
Apr 05 01:50:53 ubuntu systemd[1]: Started Launch Minecraft Server.

Apr 05 01:51:12 ubuntu systemd[1]: Stopped Launch Minecraft Server.
 
root@ubuntu:/opt/minecraft/bukkit# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-04-05 01:54:19 CDT; 11s ago
  Process: 2796 ExecStart=/usr/bin/screen -mS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui (code=exited, status=1/FAILURE)
 Main PID: 2796 (code=exited, status=1/FAILURE)

Apr 05 01:54:19 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 01:54:19 ubuntu screen[2796]: Must be connected to a terminal.
Apr 05 01:54:19 ubuntu systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE

Apr 05 01:54:19 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.

 

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

Well let me tell you bit more about what's going on here. What screen does it it will launch a process and creating a virtual terminal for this process.

This process will also run in background and can be detached (what -d) is doing. The whole screen thing comes from the "old days", where you didn't had a fancy process manager like systemd. So what you usually want to do nowadays is not to detach, since systemd is watching the process for you. Systemd has an option for compatibility reason (`Type=forking`), however in certain scenarios this can lead to trouble. That's why I let you try starting without -d and changing to `Type=simple` (in variant 2). Variant 1 used a different trick, there we prevented systemd from tracking the process at all, and just keep pretending that it is running (RemainAfterExit=yes).

 

However keeping the process attached does not seem to really work, since screen expects a full terminal, while systemd only captures the outputs.

 

Enough about the theory. We should focus on Variant 1.

Quote

Changing to the requested working directory failed: No such file or directory

Pretty clearly says that he cannot find your working directory so check if the directory specified in the service File is correct. Also remove all spaces around all equal signs, this seemed to mostly work, but maybe it assumes that the leading space is part of the path. In general systemd files should have the format "ExecStart=/path/to/my/program" instead of "ExecStart = /path/to/my/program"

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, lal12 said:

Enough about the theory. We should focus on Variant 1.

Pretty clearly says that he cannot find your working directory so check if the directory specified in the service File is correct. Also remove all spaces around all equal signs, this seemed to mostly work, but maybe it assumes that the leading space is part of the path. In general systemd files should have the format "ExecStart=/path/to/my/program" instead of "ExecStart = /path/to/my/program"

Major development I'm really excited about! If I run "/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui" manually from my root shell that I'm SSHed into IT WORKS, the process stays open and I can screen -r into it perfectly! I hardly know a thing about bash scripting so...

 

Back to the script nonsense. I removed all the spaces on the sides of the = signs and got "Must be connected to a terminal" screen error(which is what lead me to trying running it manually).

root@ubuntu:~# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Apr 05 12:25:12 ubuntu systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 12:25:12 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 05 12:26:27 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:26:27 ubuntu screen[3187]: Must be connected to a terminal.
Apr 05 12:26:27 ubuntu systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 12:26:27 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 05 12:28:10 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:28:39 ubuntu systemd[1]: Stopped Launch Minecraft Server.
Apr 05 12:28:42 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:28:58 ubuntu systemd[1]: Stopped Launch Minecraft Server.

Edit: I'm focusing on the variant 1 script.

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, TheJooomes said:

Major development I'm really excited about! If I run "/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui" manually from my root shell that I'm SSHed into IT WORKS, the process stays open and I can screen -r into it perfectly! I hardly know a thing about bash scripting so...

 

Back to the script nonsense. I removed all the spaces on the sides of the = signs and got "Must be connected to a terminal" screen error(which is what lead me to trying running it manually).


root@ubuntu:~# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Apr 05 12:25:12 ubuntu systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 12:25:12 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 05 12:26:27 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:26:27 ubuntu screen[3187]: Must be connected to a terminal.
Apr 05 12:26:27 ubuntu systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 12:26:27 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 05 12:28:10 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:28:39 ubuntu systemd[1]: Stopped Launch Minecraft Server.
Apr 05 12:28:42 ubuntu systemd[1]: Started Launch Minecraft Server.
Apr 05 12:28:58 ubuntu systemd[1]: Stopped Launch Minecraft Server.

Edit: I'm focusing on the variant 1 script.

Are you sure? Since last time the missing "-d" option caused the "Must connect to a terminal" error, which makes sense. So please double check that you got that "-d" Option in the service file, maybe just post it again.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, lal12 said:

Are you sure? Since last time the missing "-d" option caused the "Must connect to a terminal" error, which makes sense. So please double check that you got that "-d" Option in the service file, maybe just post it again.

Not a thing has changed since my last reply to this thread.

root@ubuntu:/opt/minecraft/bukkit# cat /etc/systemd/system/minecraft.service
[Unit]
Description=Launch Minecraft Server
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/bukkit
Type=simple
User=minecraft
Group=minecraft
ExecStart=/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#ExecStop=/usr/local/bin/mcstop %i
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

 

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, TheJooomes said:

Not a thing has changed since my last reply to this thread.


root@ubuntu:/opt/minecraft/bukkit# cat /etc/systemd/system/minecraft.service
[Unit]
Description=Launch Minecraft Server
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/bukkit
Type=simple
User=minecraft
Group=minecraft
ExecStart=/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#ExecStop=/usr/local/bin/mcstop %i
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

 

Did you run "systemd daemon-reload" after last changing that file? Since the service file above works for me.

Link to comment
Share on other sites

Link to post
Share on other sites

So I installed bukkit and added a minecraft user, now I can successfully start a bukkit server it with your service file.

I now tried Type=forking again to have better monitoring, and it also works:

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

[Service]
WorkingDirectory=/opt/minecraft/bukkit
Type=forking
User=minecraft
Group=minecraft
ExecStart=/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#ExecStop=/usr/local/bin/mcstop %i

[Install]
WantedBy=multi-user.target

 

1. Copy the above code to your service file.

2. run

sudo systemctl stop minecraft.service

to be sure that nothing is assumed to be running in the background.

2. run

sudo systemctl daemon-reload

to reload the service file

 

3. run

sudo systemctl start minecraft.service

4. run

sudo p_s a_u_x | grep bukkit

to check whether the process is running. (Remove underscores, if I don't type them the forum will block this edit/reply 😕)

5. you now should be able to attach to the bukkit console with

sudo su minecraft -- screen -r bukkit

. You can detach again by pressing Ctrl+a+d.

 

If it still does not work I am pretty sure the problem is not related to systemd or screen anymore

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, lal12 said:

So I installed bukkit and added a minecraft user, now I can successfully start a bukkit server it with your service file.

I now tried Type=forking again to have better monitoring, and it also works:

Ok, weird. Systemd says that it's running, but if I look in htop the process dies after 5 seconds like always. I tried logging into the server with Minecraft and I can't connect, proving the server is not up.

root@ubuntu:/opt/minecraft/bukkit# systemctl stop minecraft.service
root@ubuntu:/opt/minecraft/bukkit# systemctl daemon-reload 
root@ubuntu:/opt/minecraft/bukkit# systemctl start minecraft.service
root@ubuntu:/opt/minecraft/bukkit# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: active (exited) since Sun 2020-04-05 16:23:52 CDT; 1min 9s ago
  Process: 4035 ExecStart=/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui (code=exited, status=0/SUCCESS)
 Main PID: 4035 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/minecraft.service

Apr 05 16:23:52 ubuntu systemd[1]: Started Launch Minecraft Server.

I have a few maybe dumb questions.

-Does it matter that I'm logged in as root on the server?

-Might SSH have something to do with it?

-Would the Ubuntu minimal ISO be missing something critical that all the tutorials skip over?

-Do permissions matter for the service file?

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, TheJooomes said:

-Does it matter that I'm logged in as root on the server?

-Might SSH have something to do with it?

-Would the Ubuntu minimal ISO be missing something critical that all the tutorials skip over?

No, not that I could think of.

 

1 hour ago, TheJooomes said:

-Do permissions matter for the service file?

I think they won't be a problem and just trigger a warning. However to be sure call the commands I wrote:

 

21 hours ago, lal12 said:

sudo chown root:root /etc/systemd/system/minecraft.service		

		sudo chmod 644 /etc/systemd/system/minecraft.service

 

 

You could try to retrieve the log output from screen, use this command instead of the old one:

/usr/bin/screen -dmS bukkit -L -Logfile /tmp/bukkit-screen.log /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui

This should create a log in "/tmp/bukkit-screen.log" where the output of the server should appear for better logging. Maybe this output clarifies what goes wrong.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, lal12 said:

This should create a log in "/tmp/bukkit-screen.log" where the output of the server should appear for better logging. Maybe this output clarifies what goes wrong.

https://pastebin.com/qS2ux68S From what I can tell, it doesn't have permission to access pretty much the entire bukkit folder. So I used chown to change ownership of /opt/minecraft to the minecraft user, and... IT FINALLY WORKS
only one issue

root@ubuntu:/etc/systemd/system# screen -ls
No Sockets found in /run/screen/S-root.

I can login to the server with minecraft all fine and all seems well, except for that part.
 

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, lal12 said:

sudo su minecraft -- screen -r bukkit

That's the command you have to use or

sudo su minecraft -- screen -ls 

in your case. Screen will start this session with the current user (which is minecraft as specified in the service file). screen works on a per user basis, which means you have to run all (related) commands as the same user.

Link to comment
Share on other sites

Link to post
Share on other sites

43 minutes ago, lal12 said:

That's the command you have to use or


sudo su minecraft -- screen -ls 

in your case. Screen will start this session with the current user (which is minecraft as specified in the service file). screen works on a per user basis, which means you have to run all (related) commands as the same user.

Thanks for all that, I learned alot. It seems to be working now, I enabled the service so it would start at boot.

One more thing left to do, autorestart on crash. I've tried putting...

Restart=always
RestartSec=0s

...in different places in the script, like after the ExecStart line, and at the end of everything under [Service]. It acts like it's not even there. Systemd says the service is still running, even after I close the server.

 

Interestingly, that monster script on the wiki tutorial now works perfectly since the permissions for the minecraft user are setup properly, and it has working autorestart. I might use that instead, but I'd prefer to use our script because of simplicity. Do you got any ideas how to do autorestart?

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, lal12 said:

Could you attach the current service file.

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

[Service]
WorkingDirectory=/opt/minecraft/bukkit
Type=simple
User=minecraft
Group=minecraft
ExecStart=/usr/bin/screen -dmS bukkit /usr/bin/java -server -DIReallyKnowWhatIAmDoingISwear -XX:ParallelGCThreads=4 -Xmx3G -Xms3G -jar bukkit-current.jar nogui
#Restart=always
#RestartSec=0s
#ExecStop=/usr/local/bin/mcstop %i
RemainAfterExit=yes
Restart=always
RestartSec=0s

[Install]
WantedBy=multi-user.target

 

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

Yes, currently systemd does not monitor your minecraft service.

That what's I meant here:

14 hours ago, lal12 said:

I now tried Type=forking again to have better monitoring, and it also works:

So rewrite "Type=simple" to "Type=forking" and remove "RemainAfterExit=yes".

I would also increase RestartSec to maybe 5 or 10s (at least 1s). Otherwise if your server is broken and just won't start anymore, systemd will go into a restart loop. This is fine but with RestartSec=0 this could potentionally take a lot of resources and spams your log.

Link to comment
Share on other sites

Link to post
Share on other sites

I got everything working and was able to reproduce it on a fresh OS install. You've been so helpful. If I can't get it working when I deploy it on the real server, maybe a week off, I'll come back, but I don't think I'll need to.

lumpy chunks

 

Expand to help Bunny reach world domination

(\__/)
(='.'=) This is Bunny. Copy Bunny into your signature to
(")_(") help him on his way to world domination.

 -Rakshit Jain

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×