1
votes

I'm trying to setup a minecraft server for my kid and screen is giving me fits. I've been following this tutorial and I've already consulted this AskUbuntu answer. I'm running on Ubuntu 16.04.5 x64. I have created the following Service file and linked it to /etc/systemd/system/minecraft.service.

[Unit]
Description=Minecraft Server
Documentation=

Wants=network.target
After=network.target

[Service]
User=minecraft
Group=minecraft
Nice=5
EnvironmentFile=-/var/minecraft/unit.conf
KillMode=none
SuccessExitStatus=0 1

ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
PrivateTmp=true
InaccessibleDirectories=/root /sys /srv -/opt /media -/lost+found
ReadWriteDirectories=/var/minecraft/server /usr/bin/screen
WorkingDirectory=/var/minecraft/server
#ExecStartPre= /usr/bin/screen -dmS Minecraft
ExecStart= /usr/bin/screen -dm -S Minecraft '/usr/bin/java -Xmx1500M -Xms1024M -jar /var/minecraft/server/craftbukkit-1.13.jar'
ExecStop=/usr/bin/screen -S minecraft -p 0 -X stuff "stop^M"

[Install]
WantedBy=multi-user.target

When I monitor the service startup, I get the following in the journalctl logs:

Aug 05 14:55:41 spigot-1 systemd[1]: Started Minecraft Server.
Aug 05 14:55:41 spigot-1 screen[9869]: No screen session found.

Per the SO post I referenced, I already changed the permissions in /var/run/screen. This is the current setup:

root@spigot-1:/var/minecraft/server# ls -alR /var/run/screen/
/var/run/screen/:
total 0
drwxrwxrwx  4 root      root       80 Aug  5 14:12 .
drwxr-xr-x 23 root      root      860 Aug  5 14:11 ..
drwx------  2 minecraft minecraft  40 Aug  5 14:55 S-minecraft
drwx------  2 root      root       40 Aug  5 14:50 S-root

/var/run/screen/S-minecraft:
total 0
drwx------ 2 minecraft minecraft 40 Aug  5 14:55 .
drwxrwxrwx 4 root      root      80 Aug  5 14:12 ..

/var/run/screen/S-root:
total 0
drwx------ 2 root root 40 Aug  5 14:50 .
drwxrwxrwx 4 root root 80 Aug  5 14:12 ..

** Debug Notes ** You'll see the commented ExecStartPre command in there... all that happens if I try to start the screen session with that command is I get a second 'No screen session found' error.

I can launch the server from the command line using 'screen -dmS Minecraft [..]' and reattach. I can do this both as root and as the 'minecraft' user.

Any help would be greatly appreciated

1
Judging from the close votes, you should probably have posted this on unix.stackexchange.com, but see my answer anyway.meuh
Why do you use screen? You will find program output in the journal.Jürgen Hötzel

1 Answers

2
votes

I don't have Ubuntu to hand, but I tried something similar on Fedora 24 and had a similar error. To investigate I added an strace to the screen command and removed PrivateTmp so that I could get the trace output.

ExecStart=/bin/strace -o /tmp/s -f screen -dm -S me bash -c 'sleep 999'

In the output I found that at the end, screen was trying to open a pseudo-tty and failed to do so:

open("/dev/ptmx", O_RDWR)         = -1 EACCES (Permission denied)
...
write(1, "No more PTYs.\r\nSorry, could not "..., 52) = 52

I added some ls -l /dev commands to the Unit to see what the effect of the PrivateDevices=true option had been. There was indeed a /dev/ptmx file, but unlike my real /dev it was a symbolic link to /dev/pts/ptmx, instead of just being the special character device. For some reason on my system I have:

$ ls -l /dev/ptmx /dev/pts/ptmx
crw-rw-rw- 1 root tty  5, 2 Aug  6 14:29 /dev/ptmx
c--------- 1 root root 5, 2 Jun 27 08:29 /dev/pts/ptmx

(This is probably a bug depending on the version of systemd and udev.) So when /dev/ptmx is replaced in the private namespace by a symbolic link to /dev/pts/ptmx, you can no longer open a new pty. A simple fix for testing was sudo chmod a+rw /dev/pts/ptmx which indeed made the Unit work and start the screen process.

This may not be the case for you, but you could undertake a similar debug method to try to find the problem.