this post was submitted on 29 Aug 2023
14 points (93.8% liked)

Linux

47993 readers
1194 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[–] gammarays@lemm.ee 1 points 1 year ago (1 children)

Are you able to docker attach to the container?

[–] GlassHalfHopeful@beehaw.org 0 points 1 year ago* (last edited 1 year ago) (2 children)

This looked so promising.

Via SSH, I can indeed use docker attach and from within I can issue a stop for MC server. Works fine.

However, the Synology task scheduler via DSM doesn't seem to be able to similarly attach and then issue the stop command. I get this back via email (for when a scheduled task fails):

Task Scheduler has completed a scheduled task.

Task: MC Graceful Restart Start time: Tue, 29 Aug 2023 17:19:41 -0500 Stop time: Tue, 29 Aug 2023 17:19:42 -0500 Current status: 127 (Interrupted) Standard output/error:

the input device is not a TTY /bin/bash: line 1: stop: command not found

[–] gammarays@lemm.ee 2 points 1 year ago* (last edited 1 year ago)

If you aren't starting your container with the -it options (for docker run), try setting them so that it allocates a tty. The fact that it works with SSH however makes me think that perhaps the Synology task runner can't run interactive commands like docker attach because it has no stdin. In that case you'll need to do something like this: https://serverfault.com/questions/885765/how-to-send-text-to-stdin-of-docker-container/947763#947763 to pipe the stop command into the stdin of the bedrock server.

[–] gammarays@lemm.ee 1 points 1 year ago* (last edited 1 year ago)

If you aren't starting your container with the -it options, try setting it so that it allocates a tty. The fact that it works with SSH however makes me think that perhaps the Synology task runner can't run interactive commands like docker attach because it has no stdin. In that case you'll need to do something like this: https://serverfault.com/questions/885765/how-to-send-text-to-stdin-of-docker-container/947763#947763 to pipe the stop command into the stdin of the bedrock server.