Control MCServer via Cron Jobs
#1
Hi all.

I'm very new to Minecraft, however I've been persuaded (read bullied) into setting up a server for my daughter and some of her mates to have a blast on without having to worry about the world + dog hurling abuse at them. I had a spare Raspberry Pi, and after some research I came to MCServer. All downloaded, installed and running with a minimum of fuss, so my thanks to all of the devs for their work.

Having had a little experience with servers and Linux over the years, I'm very much of the opinion that regular jobs like backups and updates should be completely automated. I've set up a bash script to back up the MCServer files, tar them up and FTP them from the Raspi to another machine as a backup, and another script to check whether an updated executable is available (on Bearbin's site) and if there is one to download and install it. There are a couple of others for housekeeping stuff. All of that is set up so it can be run on Cron jobs.

In order for this to work the way I'd like it to, I'd prefer the MCServer executable to run in a headless mode, and I'd like to be able to run and terminate it under control of a Cron job so I can shut it down cleanly at (say) 2am, then do my backup/update/housekeeping stuff and then restart the executable at 6am. I've seen some discussion on the forums about detecting the MCServer process and killing it, however that would run the risk of losing data.

Is it possible to issue commands to the MCServer program through Cron jobs?
Reply
Thanks given by:
#2
MCServer *should* catch the kill signal (as long as it is interceptable for an application) and shut down cleanly, provided you give it enough time, though this is not a particularly portable solution as that time is indeterminate. I believe you can just pipe commands into the process and the console will execute them, but now I hand over to someone who knows Linux more for a better opinionTongue
Reply
Thanks given by:
#3
The best way I've found for build jobs is to use screen and then pipe into that.
So you could start up mcserver with
Code:
echo '"./MCServer\n" | screen -S MCServer
and stop it with
Code:
echo "stop\n" | screen -r MCServer

Alternatively you could try to use our RCON support, though I'm not sure how good that is.
Reply
Thanks given by:
#4
Thanks for both of those.

I've seen some bits about the RCON support, but from reading on the forums it only appears to be supported in Windows (though I'm very happy to be corrected). Could you point me to any documentation for it so I can have a read up on it?
Reply
Thanks given by:
#5
I think only our RCON client is Windows-only. The server should work on all operation systems.
Reply
Thanks given by:
#6
I have written my own CLI RCON Client, it's https://github.com/bearbin/mcgorcon-cli

It runs on linux.
Reply
Thanks given by:
#7
Thanks for the help, everyone.

I couldn't get Bearbin's RCON client to work in the setup, so I went with a modification of the screen command proposed by worktycho.

To to start the server:

Code:
screen -d -m -S MCServer /home/minecraft/MCServer/MCServer

To stop the server:

Code:
screen -S MCServer -X eval 'stuff stop\015'

Obviously you can also send other console commands, so for example:

Code:
screen -S MCServer -X eval 'stuff restart\015'

I've only tested this on my Raspberry Pi, but it's all running nicely under Cron control. Hopefully it's of help to someone else.
Reply
Thanks given by:
#8
Did mcgorcon-cli give an error, or did it simply not work?
Reply
Thanks given by:
#9
I think I'm missing some dependencies to run it, and I'm not any kind of programmer so my knowledge of how to fix it is a bit limited. That said, I'll happily give it another go on a separate Pi. Is there a step-by-step on the forums anywhere I can follow to set up?
Reply
Thanks given by:
#10
Oh ok, that's fine. It relies on the Go programming language to work.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)