What’s the Best Way to Send Commands to a Background Server?

0
0
Asked By PixelScribe99 On

I'm setting up servers for Minecraft Bedrock and SuperTuxKart, and I've noticed that they take over the terminal when I run them directly. So far, I've been using Tmux to manage this, but I'm curious if there's a more conventional method out there. For Minecraft specifically, I have some Python scripts that handle server commands and I've been scheduling them with cron jobs. Additionally, I've created a systemd service that checks for existing Tmux sessions and starts the server if none exists. However, I'm not entirely satisfied with this solution and I'm looking for a more direct way to handle input to the servers.

3 Answers

Answered By ScriptWizard42 On

Why not just run your Python scripts directly instead of using cron? You might get a cleaner execution without needing long sleep times in your loops, plus it could help avoid time drift issues. It sounds like your scripts are doing a lot with Minecraft, like syncing the day/night cycle and displaying scoreboards from API data, so direct execution could simplify things for you.

CodeNinja77 -

Yeah, just running them on their own might save you some headache! Plus, if they manage the Minecraft server effectively, you wouldn't need cron at all.

Answered By TechieTommy On

You could add an '&' at the end of your command, like `my-minecraft-server --some --options -S &`, to detach the server from the terminal. Just be careful since you'll need a way to send inputs to it afterward.

PixelScribe99 -

That's a good idea! But how do I actually send inputs to that detached process? I've considered named pipes — do you think that would work?

Answered By DevGuru88 On

Have you tried using daemonize? It's a utility that can run your server in the background without tying it to a terminal. That might be more aligned with what you're looking for.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.