2

So I have a server that I can run from a bash terminal using e.g.

java -jar spigot.jar

which will send output to stdout (I believe), and thus be printed to the terminal screen. To stop the server from the terminal, one simply sends the "stop" command to the server, at which point the server initiates shutdown (saves current data, etc.).

However, I don't want to have to start the server every time I reboot, or have an extra bash terminal hanging around with the open process, so I've been trying to set up a systemd service to run the server automatically, and take standard input from (anywhere, really), using a .service file like the following:

[Unit]
Description=Spigot Minecraft server daemon

[Service]
Restart=always
WorkingDirectory=*location where spigot.jar is*

StandardInput=tty
TTYPath=/dev/tty2

ExecStart=/usr/bin/java -jar spigot.jar
ExecStop=/bin/sh -c 'echo stop >/dev/tty2'

[Install]
WantedBy=multi-user.target

But I can't figure out why this won't work. What I thought it should do is pipe /dev/tty2 to the server, and when I use the command

systemctl stop *service*

it should send "stop" (indirectly through /dev/tty2) to the server. What am I missing?

But the service doesn't seem to run? If I comment out the StandardInput & TTYPath lines, the server starts, but when issuing

systemctl stop *service*

and then reviewing server logs through

journalctl -u *service*

the proper shutdown sequence never initiated -- the process was just killed (instead of gracefully stopping itself).

So what I want to know is: how do I run this server as a service, with some FIFO/file/tty/something piped into it (so I can still issue server commands)?

1

I'm guessing you are trying too hard. The standard way to shutdown a service is send it a SIGTERM signal (polite) or a SIGKILL signal (forceful). I believe that's the default systemd behavior. So try removing all these lines from your systemd unit file:

StandardInput=tty
TTYPath=/dev/tty2
ExecStop=/bin/sh -c 'echo stop >/dev/tty2'

There are plenty or references on the Spogit site to using SIGTERM and SIGKILL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.