Question

I have a minecraft server running in screen, and right now, it is just a script that starts java like so:

screen -dmS mc java -Xincgc -Xms1024M -jar craftbukkit-1.6.4-b2882.jar

Basically this just starts minecraft in a screen container in the background, and I can access it with screen -r mc through SSH. However, what I would like to do, is have the process always up on the server monitor, and also accessible through ssh with screen -x mc. Also, I have a restart.sh script that stuffs the stop command to the mc process every two hours, then it executes the start.sh script. The server is at runlevel 3, so I don't think gnome-terminal -e "screen -x mc" will work. Also, it seems like the restart script is starting mc outside of screen. When I SSH into the server, screen -ls turns up nothing, but the minecraft server process is running and I can connect to it. Here's the script:

#!/bin/sh

screen -x mc
screen -s mc stuff "say Server Restarting in 15 minutes."
screen -s mc -X eval "stuff \015"
sleep 600
screen -x mc
screen -x mc -X stuff "say Server restarting in 5 minutes."
screen -s mc -X eval "stuff \015"
sleep 240
screen -x mc
screen -s mc -X stuff "say Server restarting in 1 minute."
screen -s mc -X eval "stuff \015"
sleep 60
screen -S mc -X stuff "say Server restarting."
screen -S mc -X eval "stuff \015"
screen -S -X stuff "kickall Server Restarting, it should be back up in about a minute."
screen -S mc -X eval "stuff \015"
sleep 2
screen -S mc -X stuff "stop"
screen -S mc -X eval "stuff \015"
sleep 30
screen -wipe
sleep 3
cd /minecraft/server/craftbukkit
./start.sh

Any ideas?

Was it helpful?

Solution

screen -dmS mc command

starts a screen, which lives only till <command> completes,
e.g. whenever java quits - screen is also terminated.

Start screen like this instead:

screen -dmS mc bash
screen -s mc -X eval 'stuff "java -Xincgc -Xms1024M -jar craftbukkit-1.6.4-b2882.jar\015"'

and restart correspondingly too:

screen -s mc -X eval 'stuff "cd /minecraft/server/craftbukkit\015"'
screen -s mc -X eval 'stuff "./start.sh\015"'

Hope this helps :)

I don't have java/minecraft here, so I'll use "read" tool as a sample:

screen -dmS mc bash                             # starts screen&bash
screen -s mc -X eval 'stuff "read\015"'         # tells bash to start "read"
screen -s mc -X eval 'stuff "test\015"'         # tells read the input "test"
screen -s mc -X eval 'stuff "echo \$REPLY\015"' # tells bash to echo the $REPLY var
screen -s mc -X eval 'stuff "cd /tmp\015"'      # tells bash to cd into /tmp

As You see - stuff sends the input not into the bash but just generally - into the screen, e.g. into whatever application started under bash and currently reading the stdin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top