I've setup an Ubuntu 18.04 instance, to use as a private Minecraft Bedrock server.
I've downloaded the server itself from https://www.minecraft.net/en-us/download/server/bedrock/
I can run it directly from the shell, and everything works fine. However what I'd like to do, is configure it as a service, so it will start automatically on boot, and stop gracefully etc.
The "bedrock_server" executable runs in the foreground, and waits for various commands from standard in, such as "stop", "kick", "save" etc.
Is there a way I can configure a service script so it can be controlled like so ...
$ service minecraft stop
$ service minecraft restart
It would be even better if I could issue other minecraft specific commands as well, such as...
$ service minecraft kick [player name or xuid]
etc.
I'm not too concerned about this capability though. The main thing I want, is to be able to start it properly at server boot, and gracefully stop.
I'd don't need it fully written for me. If someone could direct me to a tutorial, or a template or something, that would be great.
This is the full command I'm currently using to launch it from the shell...
$ cd /home/[my-user]/bedrock-server-1.14.60.5 && LD_LIBRARY_PATH=. ./bedrock_server
update...
Based on the answer below, and a lot of trial and error, I've come up with this systemd script...
[Unit]
Description=Minecraft Bedrock Service
After=network-online.target
[Service]
User=[my-user]
WorkingDirectory=/home/[my-user]/bedrock-server-1.14.60.5
Type=forking
ExecStart=/usr/bin/screen -dmS UbuntuMinecraft /bin/bash -c "LD_LIBRARY_PATH=. ./bedrock_server"
ExecStop=/usr/bin/screen -Rd UbuntuMinecraft -X stuff "say Stopping server in 10 seconds...\r"
ExecStop=/bin/sleep 10
ExecStop=/usr/bin/screen -Rd UbuntuMinecraft -X stuff "stop\r"
GuessMainPID=no
TimeoutStartSec=600
[Install]
WantedBy=multi-user.target
This seems to work quite well.
If I need to run other commands on the server, I can connect to the screen session like so...
$ screen -R UbuntuMinecraft
Then I can run whatever native commands I need.
I based my solution partially on this code... https://github.com/TheRemote/MinecraftBedrockServer