TOPICS
Features

Startup Scripts

Startup scripts execute the first time a new virtual machine boots, and can be used to automatically configure software on the VM.

You can first define startup scripts from Startup Scripts in the panel. You'll then be able to select these scripts when creating a new VM.

Types of Scripts

You can define two types of startup scripts: shell scripts and cloud-config scripts.

Shell Scripts

Bash scripts simply run OS commands to execute setup steps. For example, this bash script will update packages on Debian-based operating systems:

#!/bin/bash
apt-get update; apt-get upgrade -y

Here's a more complicated example that sets a root password and removes the default administrative user from our templates. It also reconfigures SSH to accept root logins. If you provision a VM from one of our templates with this script, you'll be able to SSH into your VM as root with the password displayed under Initial Login Details.

#!/bin/bash
password=$(cut -d':' -f2 /etc/shadow | tail -n 1 | sed -e 's/[\/&]/\\&/g')
sed -i 's/root:[^:]*:/root:'"$password"':/' /etc/shadow
username=$(ls /home/)
deluser "$username"
rm -rf /home/"$username"
sed -i 's/.*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
service ssh restart
service sshd restart

Cloud-config Scripts

cloud-config scripts can be used on any image that has cloud-init installed; all of our templates come with cloud-init. cloud-config scripts can more reliably configure operating system parameters than shell scripts, and are generally easier to write.

Get started with several example cloud-config scripts.