If you are a coder/developer sometimes we need to write scripts which should be running 24*7 so that other services related to that script will have high availability & reliability at same time. For more clear understanding let’s take an example of Python script which i created in previous IOT with Firebase series for sending automated push-notifications, script checks for changes in values of Real-time database if value of a variable named Status changes from 0 to 1, script triggers push-notification to Android App. So, this type of script should be running on a computer which have high internet availability and 24*7 power on.Which can be done through Google Cloud.
Issues while Running on Local Machine :
- 24*7 Power on Machine : Unnecessary Power loss.
- High Internet Availability : Need of good internet connection with No downtime, otherwise not reliable
So, as of now we have a clear idea that these type of programs/scripts can’t be executed on a local machine. Here Google Cloud comes in picture having both high availability & reliability, leaving further chit chat let’s see a step by step guide to configure Google cloud console for executing Python scripts.
Why Google Cloud Platform :
- One of best Platform having no downtime .
- For new Signup you will get $300 free for 12 months .
- Have access to all google cloud products with easy integration. (Firebase, Google Maps, Cloud vision etc.)
- No Auto-charge deduction after trial period over.
Step below follows the video to help :
1. Go to Google Cloud and login with your Google account, on the upper right side click on SIGN UP FREE TRIAL , here you need to fill simple details and click accept and continue.
2. Now you will be navigated to form in which you need to fill your details and as well as need to do online payment of 2 Indian Rupees (very cheap), it’s just for user verification.
3. After successful payment you will be redirected to Google cloud console dashboard.
4. Here you need to create a new project, after project creation On the left side of dashboard navigate to Compute Engine and select Vm instances.
5. Now Create a Vm instance (Vm instance is like creating a virtual machine in cloud).
6. Give instance name , in Boot disk select any Debian based O.S. like latest Ubuntu 17.04 LTS and click create button.
7. Now your instance will be created with by default starting mode.
8. On instance click on SSH option, and that’s it you will get remote access to Vm instance.
9. Here we need to setup environment for executing our script.
Setting Up Python Environment :
- As we have selected Ubuntu 17.04 while creating Vm instance, Python3 will installed by default.
# python3 # mkdir python # sudo apt-get update # sudo apt-get install vim # vim push.py // now here vim opened in commandline mode here press i for editing mode // here copy paste your whole code and save you vim file : press esc key and type :wq # nohup python3 push.py // that's it you python script has been executed in backgroud mode