Compute Engine

Getting Started

Google Cloud has limitations (https://cloud.google.com/shell/docs/limitations) which means that for long running commands you need to find an alternative method. Google Compute Engine allows you to set up a VM, install GAM and run commands as needed, for as long as you want. However, there is a cost involved, but as the VMs can be switched on/off as needed, this cost is 'minimal' (?).

Quick Start Guide

https://cloud.google.com/compute/docs/quickstart-linux

Calculator

Use this guide (https://cloud.google.com/products/calculator/) to select the most cost effective solution for your requirements. As a basic example;-

  1. f1-micro = US$3.88 per month
  2. g1-small = US$13.80 per month
  3. n1-standard-1 = US$24.27 per month

Basic VM Options

Digital Ocean and other providers

Before embarking on Google Compute Engine you may want to check out other Cloud providers. For example Digital Ocean has a basic configuration of 1 CPU and 1Gb of memory for $5 per month.

Basic Commands

Start

Select the VM and click on the Start icon in the top bar

Stop

sudo poweroff

Additional Packages

Add

sudo apt-get install <packagename>

Remove. See https://askubuntu.com/questions/151941/how-can-you-completely-remove-a-package for reasoning

sudo apt-get purge --auto-remove <packagename>

Screen

Use the screen command to create SSH sessions that will remain active after the terminal window is closed.

Start Screen

screen

Detach

Enter the following key command Ctrl + a + d. This allows the terminal session to remain active, when you close the terminal window.

List running sessions

This will show the session(s) running, e.g. 7849.pts-0.<Compute Engine Name>. This can be run from the main terminal window (i.e. you do not need to be logged into a screen session). This session number will also be shown when you detach a session.

screen -ls

Re-attach a session

If only 1 session is running, then screen -r will re-attach the session, otherwise;-

screen -r 7840

Close a Screen session

Exit will close the current screen session and return to the main terminal session. Using exit will prevent you from reconnecting to this session.

exit

Kill a Screen Session

screen -X -S <Session #> quit

More info from

https://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server

Stackdriver Monitoring

This Youtube video is a good introduction into setting up notifications, although the interface is now slightly updated. It also links to this tutorial https://cloud.google.com/monitoring/quickstart-lamp which runs through the set up as well.

I have set up a notification to report when the CPU Load over 5 minutes is lower than 1%, i.e. the command I was running has finished and the VM can be shut down.

Mobile Notifications | Setting Up

Using the Mobile App you can set up mobile alerts. From the App > Incidents click the 3 dots and select 'Register device for incidents'.

Go back to Stackdriver > Alerting > Policy Overview, from the 3 dots at the end of the chosen policy, select edit. Under Notifications choose the Notification Channel Type = Google Cloud Console (mobile) > Notification Chanel = your phone/mobile device and click Add Notification Channel.

Notifications | Viewing

From the Google Cloud Platform ☰ menu select Stackdriver > Monitoring. Then Alerting > Incidents.

Stopping the VM

This can be achieved from the Compute Engine dashboard or via the mobile App.

Mobile App > Resources > VM Instances > select your VM > 3 dots > Stop

Python 3

Installing, if needed

https://cloud.google.com/python/setup

Check Python Version

python3 -V

Python 2

Check version

python -V