An interesting challenge this. It’s half term and I’ve offered to start a Minecraft server for the children while I’m in the office. There’s no great distraction – start the Azure server, run the Minecraft server startup script and off we go. The trouble is I can’t really leave the PuTTY window running. Just in case the boss wanders over and looks closely enough to read the text. But if I close the PuTTY window the server dies as well.
The screen utility is the solution. It lets you start the server and leave it running while you close PuTTY. Later on, you reconnect to the server and the Minecraft game.
The office Ubuntu documentation is on the Ubuntu Community site, but here’s my guide.
- Start the server and connect via PuTTY in the normal way
- Type screen and then press enter
- The terminal will return to normal. This might be disconcerting but, don’t worry, it’s running in the background.
- Start your server in the normal way.
- Once it’s all running well, press Ctrl+a and then d. This will detach the screen app and return you to the normal terminal. As you can tell from the lack of angry shouting, the server is still running.
- At this point you can close the PuTTY session (and get on with some work if you feel so inclined).
Getting back on the server (because let’s face it, at some point someone is going to empty a bucket of lava over someone else) is straightforward.
Connect to the server again and type screen -r to restart screen with the last session. At this point you’ll see the Minecraft server text again, just as you left it!
You can use screen with more than one screen. For example there’s rarely opportunity to say “Hang on, I’ll start the server in a mo, just got to run some updates”. This can end up with a screen full of different PuTTY windows.
- Connect to your server, type screen, press Enter and then Enter again
- Start your Minecraft server
- Press Ctrl+a and then c to create a new screen
- Start updates or different server.
- Repeat from 3 as required
Now you have lots of screen consoles, the challenge is to find them again. Press Ctrl+a and n or p to move to the next or previous screen. If that’s not enough press Ctrl+a then “ to show a list of all the consoles in screen. Use the up and down arrows to pick a screen and press Enter to switch to it.
This could get a little confusing after a while but the clever people behind screen have thought of this – you can name screens! Press Ctrl+a then A, enter a name for the screen and press Enter.
Use the arrow keys to move up and down or press a number to select a screen