Last night while doing some performance testing that involved compiling a very large package (LibreOffice, to be exact) my desktop decided it wanted to reboot for security patches. This caused the terminal window I had opened for the build task to close, and thus stopped the build before completion, and thus caused me to have to restart the entire build process from scratch when I brought the terminal back up. This may be a common problem when moving your business practices to the cloud - loss of power, a cat on the keyboard, smartphone falling out of your private helicopter… Is there any way to alleviate the frustration this can cause?

Luckily, the answer is yes, and quite simple! If the cloud server in question is running Windows, you’re already safe, because Remote Desktop being accidentally terminated doesn’t stop processes/applications from running in the background until you can log back in. However, if you’re running Linux or Unix, you have to install an additional application to accomplish the same thing for the terminal. The application you want is called “screen” and it is available for virtually any flavor of operating system that uses a terminal. Here’s how to install it on Ubuntu, which is one of the main distributions on AWS, and Gentoo (one of the distributions we use here at Dowd and Associates.) Keep in mind that you need to be root to run most package managers’ install commands (generally sudo will work)

Console - user@hostname ~ $

1
sudo apt-get install screen

This will install on Ubuntu distros, after asking for your password.

Console - user@hostname ~ $

1
sudo emerge -av screen

This will install on Gentoo OS after asking for your password.

What screen does is provide a “virtual terminal” within a terminal. Everything looks and operates the same after you type “screen” for the first time and read the information it shows you. You get your normal shell prompt, and can run commands as you want. However, now you have the ability to switch computers, lose power to your desktop, whatever and screen will happily plug along, keeping your terminal session open and active in the background. When you want to get back in to the screen session you made before, you type:

Console - user@hostname ~ $

1
screen -raAd

and that will resume your prior screen session. To temporarily close an existing screen session you have in the foreground, you can press Ctrl + A, and then Ctrl + D. You can resume it by typing the above command. To close a screen session (when your compile job is done, or you’re sure you don’t need it open anymore) you just type “exit” at the command line, and it will drop you back to your original terminal session again. Typing “exit” again should close your terminal window or connection from the cloud.

Hope this saves you some frustration!

Comments