Note: Still trying to navigate communities here on Lemmy to replace those from Reddit. If there is a better place such a question, I would welcome the suggestion.
I'm running a Synology NAS, which uses some flavor of Linux distribution. From there, among everything else running, I have a docker container hosting a Minecraft Bedrock Server. The MCBE server is great for fun, but not so great for resource usage. To handle this, most folks setup something to schedule the server to restart.
Within Synology, there is a task scheduler where I can run a user-defined script to restart the whole container:
docker restart mcbe-world
This works, but it's a dirty reboot though. I worried about corrupting the world (which I do regularly backup). From within the Minecraft server terminal, the /stop
command will gracefully shut it down.
I can't update the container with another application, like screen, because each MCBE update means replacing the entire container (and so destroying the changes). I am looking to somehow redirect a command to the server if possible.
Using docker exec -it mcbe-world
, I can execute what I want within the container.
The person here said, one can "inject commands by running the command as the appropriate account and redirecting it into the server" and they gave the example sudo su -s /bin/bash -c "echo say foobar > /run/service@name"
Unfortunately, this isn't so clear and straight forward to me.
Would anyone here be able to articulate this more clearly for me or have an idea as to how I might issue that /stop command from the Synology scheduled script BEFORE restarting the container?
Thanks!
UPDATE: Solution here: https://beehaw.org/comment/1088961
Check this out: https://stackoverflow.com/a/62142025
So adapted for your requirements:
YEEEESSS!!!! THIS!!! Thank you! I've been able to hobble together a script now that I have a Synology automated task calling early each morning after world backups are complete. I'm so very grateful to you all. I've learned a lot. A proper "stop" is being issues now which reduces the chance of world corruption which would make my family very very grumpy.
Here's the script just in case someone finds themselves in a similar situation as me. This is not my wheelhouse and it's not pretty. I know it can be better, but I've spent too much time on this as it is and need to go fix a washing machine now. Ugh...
P.S. I really need to figure out how to get the RCON solution working because that would be a more elegant way to handle things.
P.P.S Example run (yes, the timing and spelling were updated after this screenshot 😁)
Nice, glad to help!
As for the automatic restarting, the whole Docker container exits, if the main process (specified as CMD in the Dockerfile) exits (in this case the minecraft server) and Synology probably auto-restarts the containers on exit by default.
Good to know about the main proc. I wasn't aware. And it is indeed set to auto restart. I just hadn't realized the stop alone would trigger that. I had figured I would need to take the additional step.