A Cloud Architect Company
Startup Script in Google Compute Engine?
Google Cloud Platform

How to use the Startup Script in Google Compute Engine?

In this article we are going to learn about how to use the startup script in Google Compute Engine to automatically install the Apache web server and run the HTTP web site in the browser.

However, there are lots of steps in creating a VM and setting up the Apache HTTP web server in an instance. To avoid these kinds of steps we need to write a startup script to automate the things.

It will be a step by step process for running a startup script in Google Compute Engine on Google Cloud Platform. Let’s get into this article and learn about how to use startup script. Stay tuned here, we will keep publishing a lot more articles on Google Cloud.

What is Bootstrapping?

The process of installing any software or installing OS patches when a VM instance is launched is called bootstrapping. Before launching a virtual machine, you want to be sure that it is secure. For that you have to ensure that all the latest OS patches are up to date and one of the options to do that is to use a startup script in the virtual machine.

In the virtual machine you can configure a startup script to bootstrap the application.

What is a Startup Script?

Google Compute Engine has this pretty interesting thing known as startup script. Startup scripts are bash scripts, you can apply this to your virtual machine to occur every single time when your virtual machine begins and they could be used for things like configuring the environment, downloading dependencies, initializing services and downloading updates.

Startup scripts are applied to a running virtual machine as well as a new VM that you create from scratch or you can link a startup script that exists in Google Cloud Storage.

Steps for using the startup script

The first thing you have to do is to login to the Google Cloud Console and create a new project for your testing purpose. In the below screen you need to click on the new project icon at the right.

Selecting a project

After clicking on the new project icon you will get the screen below. Here, you need to enter your project name and click on the create icon to create a new project.

Creating a New Project

Selecting the VM instances

After the successful creation of the project you need to click on the navigation menu and select the VM instances from Compute Engine service. In the below screen you can see how to select the VM instances.

Selecting the VM instances

After selecting the VM instances you will get the screen below. Here, you need to click on the Create instance tab at the center of the console.

UI of VM instances

Creating startup script from instance template

Now, we are going to use a startup script from the instance template which we have already created in the project.

If you want to know about how to create a instance template. Please have a look at our previous blog on “How to create an instance using instance template ” to have a better understanding of Instance templates.

After clicking on the Create instance icon you will get the screen below. Here, you need to click on the New VM instance from the template tab at the left and select the instance template which is already created, and click on the continue icon.

Selecting instance from template

Configuring a Startup script

After clicking on the continue icon you will get the screen below. Here, you need to enter your instance name and by providing the label for your instances select the Region and Zone as well.

Instance details

Then the remaining things include Machine Configuration, Boot disk and Enabling the firewall has already been configured in the instance template. Now, to configure the Startup script you need to click on and expand the Management, security, disks tab in the below screen.

Instance details

 

Preparing the Startup script in the Notepad

Before expanding the Management tab you need to open the Notepad in your system and save the Startup script which is provided in the below screen.Startup Script

In the below screen you can see the expansion of the Management tab. Now, you need to copy the script from the notepad and paste that in the startup script box under the Automation tabEntering the startup script in Automation

Finally, click on the create icon at the last in the below screen to create an instance in the Google Compute Engine.

Creating an Instance

Instance created using startup script

In the below screen you can see that instance has been created successfully by using the startup script. In this you don’t need to install a separate Apache web server. Everything is automated in the startup script itself.

After the instance is ready, it would take a couple of minutes to install all the software because we are installing a few things on the launch of the Virtual machine.

Therefore, you have to click on the external IP address to see the website of your instances.

Instance created

Launched the Startup script

Then finally after clicking on the external IP addresses, you can see the working of the website.

Webserver deployed

Conclusion

Therefore, In this blog we have seen how to use a startup script from an instance template that is already created. And also we have done the Automation of installing a web server in that specific instance by running the simple startup script.

I hope this article will help you in getting started with Startup script. In the next blog, We will publish a lot more articles on Google Cloud. Till that Please Stay tuned with us!!

Happy Learning!!

Join the discussion

  1. Kris

    I don’t see any difference from https://codelabs.developers.google.com/codelabs/cloud-compute-engine#6

    Also it is very very basic and not useful in realtime

    Do you have an article that runs a java application i.e. nohup java -jar ***** from startup script?

Leave a Reply

Your email address will not be published. Required fields are marked *

back to top
advanced-floating-content-close-btn

Contact Us to save your AWS bill by 40%

X