0

I'm trying to run a Minecraft server on VM running Debian 10. I've set up the server to run as a service and am attempting to use a socket listening to a FIFO based on this question that last saw activity in 2019: Using systemd's Exec*-command to pass commands to the process

Based on these logs, my understanding is that my commands issued to the FIFO are not actually talking to the right process. Here's some example logs from running systemctl status minecraft-server:

Oct 26 18:33:59 mc-server bash[1589]: [2021-10-26 18:33:59:697 INFO] Game mode: 0 Survival
Oct 26 18:33:59 mc-server bash[1589]: [2021-10-26 18:33:59:697 INFO] Difficulty: 1 EASY
Oct 26 18:33:59 mc-server bash[1589]: [INFO] opening worlds/Bedrock level/db
Oct 26 18:33:59 mc-server bash[1589]: [INFO] IPv4 supported, port: 43885
Oct 26 18:33:59 mc-server bash[1589]: [INFO] IPv6 supported, port: 19133
Oct 26 18:34:00 mc-server bash[1589]: [INFO] Server started.
Oct 26 18:34:00 mc-server bash[1589]: [INFO] IPv4 supported, port: 19132
Oct 26 18:34:00 mc-server bash[1589]: [INFO] IPv6 supported, port: 39935
Oct 26 18:34:44 mc-server systemd[1]: Stopping Minecraft Bedrock Server 1.17.x.x...
Oct 26 18:34:44 mc-server bash[1618]: stop

That last log item is the command issued through systemctl stop minecraft-server, but it does nothing. In fact, based on the proccess IDs, it looks like it might not be getting sent to the right process at all.

Here are my relevant unit files. First, my minecraft-server.service file:

[Unit]
Description=Minecraft Bedrock Server 1.17.x.x
After=network-up.target mnt-minecraft.mount

[Service]
WorkingDirectory=/mnt/minecraft
Environment=LD_LIBRARY_PATH=/mnt/minecraft/
KillSignal=SIGCONT
Sockets=minecraft-server.socket
ExecStart=/bin/bash -c "mkfifo minecraft-server.control; exec /mnt/minecraft/bedrock_server < /mnt/minecraft/minecraft-server.control"
ExecStop=/bin/bash -c "echo stop\n > /mnt/minecraft/minecraft-server.control"

[Install]
WantedBy=multi-user.target

After getting some error messages from the socket startup, I included the mkfifo command in my ExecStart parameter. That may or may not be the issue.

Here is my minecraft-server.socket file:

[Unit]
BindsTo=minecraft-server.service

[Socket]
ListenFIFO=/mnt/minecraft/minecraft-server.control
FileDescriptorName=control
RemoveOnStop=true

Can anyone tell me how I can get my FIFO to correctly input into the server process?

1 Answer 1

0

I solved this so I'm posting an answer here for anyone reading.

After some experimenting with redirecting stdin, I found that a command like echo "stop" < /mnt/minecraft/minecraft-server.control fails (127) because of the space between the operator and the .control file. So echo "stop\n" </mnt/minecraft/minecraft-server.control got me an exit status 0 and got me headed in the right direction.

After that, the server was complaining about the newline character, so I rewrote the ExecStop param and fixed my service unit file a bit:

[Unit]
Description=Minecraft Bedrock Server 1.17.x.x
After=network-up.target mnt-minecraft.mount

[Service]
WorkingDirectory=/mnt/minecraft
Environment=LD_LIBRARY_PATH=/mnt/minecraft/
KillSignal=SIGCONT
Sockets=minecraft-server.socket
ExecStart=/bin/bash -c "mkfifo minecraft-server.control; exec /mnt/minecraft/bedrock_server </mnt/minecraft/minecraft-server.control"
ExecStop=/bin/bash -c "echo \"stop\" >/mnt/minecraft/minecraft-server.control"

[Install]
WantedBy=multi-user.target

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .