Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a startup script in Google Cloud Platform (GCP)?
A startup script is a set of commands that automatically run when a virtual machine (VM) instance starts. It helps automate setup tasks like installing software or configuring settings.
Click to reveal answer
beginner
Where do you specify a startup script for a VM in GCP?
You specify a startup script in the VM instance's metadata under the key 'startup-script'. This script runs every time the VM boots.
Click to reveal answer
beginner
Why use startup scripts instead of manual setup on VMs?
Startup scripts automate repetitive tasks, ensure consistency across VMs, save time, and reduce human errors during setup.
Click to reveal answer
intermediate
How can you debug a startup script if it fails on a GCP VM?
Check the serial port output logs of the VM in the GCP Console. Logs often show errors from the startup script to help identify issues.
Click to reveal answer
beginner
What is a common format for startup scripts in GCP VMs?
Startup scripts are usually shell scripts (bash) for Linux VMs or PowerShell scripts for Windows VMs.
Click to reveal answer
Where do you add a startup script for a GCP VM?
AIn the IAM permissions
BIn the VM's firewall rules
CIn the Cloud Storage bucket
DIn the VM's metadata under 'startup-script'
✗ Incorrect
Startup scripts are added in the VM's metadata with the key 'startup-script' to run automatically on boot.
What happens when a startup script runs on a VM?
AIt runs commands automatically when the VM starts
BIt deletes the VM
CIt changes the VM's machine type
DIt pauses the VM
✗ Incorrect
Startup scripts run commands automatically during the VM's boot process to configure or install software.
Which log helps you debug startup script errors on a GCP VM?
ACloud DNS logs
BCloud Audit logs
CSerial port output logs
DBilling logs
✗ Incorrect
Serial port output logs show the VM's boot messages including startup script errors.
What scripting language is commonly used for Linux VM startup scripts?
APython
BBash shell script
CPowerShell
DJavaScript
✗ Incorrect
Bash shell scripts are commonly used for Linux VM startup scripts in GCP.
Why automate VM setup with startup scripts?
ATo save time and ensure consistent setup
BTo increase VM cost
CTo disable VM networking
DTo manually configure each VM
✗ Incorrect
Startup scripts automate setup tasks, saving time and ensuring all VMs are configured the same way.
Explain what a startup script is and how it helps automate VM setup in GCP.
Think about what happens automatically when a VM starts.
You got /4 concepts.
Describe how you would troubleshoot a startup script that is not working on a GCP VM.
Where does the VM show boot messages and errors?
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a startup script in a Google Cloud VM instance?
easy
A. To automate tasks when the VM boots
B. To manually start the VM
C. To create a new VM instance
D. To delete files from the VM
Solution
Step 1: Understand startup script role
Startup scripts run automatically when a VM starts to perform tasks without manual intervention.
Step 2: Identify correct purpose
Among the options, only automating tasks at boot matches the startup script function.
Final Answer:
To automate tasks when the VM boots -> Option A
Quick Check:
Startup script = automate tasks at boot [OK]
Hint: Startup scripts run automatically at VM boot time [OK]
Common Mistakes:
Confusing startup scripts with manual commands
Thinking startup scripts create or delete VMs
Assuming startup scripts run after user login
2. Which command correctly adds a startup script to a new VM instance using gcloud CLI?
easy
A. gcloud compute instances create my-vm --metadata startup='echo Hello'
B. gcloud compute instances create my-vm --script-startup='echo Hello'
C. gcloud compute instances create my-vm --startup='echo Hello'
D. gcloud compute instances create my-vm --metadata startup-script='echo Hello'
Solution
Step 1: Recall correct flag for startup script
The correct metadata key to add a startup script is 'startup-script'.
But nginx is not installed after VM boots. What is the likely problem?
medium
A. The script lacks 'sudo' before commands
B. The script is missing the shebang line
C. The script runs before network is ready
D. The script should use 'yum' instead of 'apt-get'
Solution
Step 1: Check script commands and environment
The script uses apt-get which requires network access to update and install packages.
Step 2: Identify timing issue
Startup scripts may run before network is fully ready, causing apt-get to fail silently.
Final Answer:
The script runs before network is ready -> Option C
Quick Check:
Network must be ready before package install [OK]
Hint: Ensure network is ready before package installs in startup scripts [OK]
Common Mistakes:
Adding sudo unnecessarily (scripts run as root)
Ignoring network readiness in startup timing
Using wrong package manager for Debian-based VM
5. You want to automate VM setup to install Apache, create a website folder, and start the service on boot. Which startup script snippet correctly achieves this?
For Debian-based VMs, apt-get is correct. Apache package is apache2. Creating /var/www/html is needed.
Step 2: Check service management commands
#!/bin/bash
apt-get update
apt-get install apache2 -y
mkdir /var/www/html
systemctl enable apache2
systemctl start apache2 uses 'systemctl enable' to start Apache on boot and 'systemctl start' to start immediately, which is best practice.
Step 3: Compare other options
#!/bin/bash
apt-get update
apt-get install apache2 -y
mkdir -p /var/www/html
systemctl start apache2 misses enabling service on boot. #!/bin/bash
apt-get install apache2
mkdir /var/www/html
service apache2 stop stops service instead of starting. #!/bin/bash
yum update -y
yum install apache2 -y
mkdir /var/www
systemctl restart apache2 uses yum (wrong for Debian).