All help articles

Deploy scripts

On this page

A deploy script runs once on a new server, as root, the first time it starts. You can use one to install your software, add users or turn on a firewall, so the server is ready when you sign in. Choose one when you order a server, finish setting it up or reinstall it from one of our images. Each run, and what it printed, shows on the server's Deploy tab.

Your organization keeps its own scripts. There is also a public library of basic ones that we keep.

The public library

Anyone can choose these. Each one works on Debian, Ubuntu, AlmaLinux, Rocky and Fedora, and most work on openSUSE too.

ScriptWhat it doesValues
Update the systemUpdates every package, then restarts a minute later if the update needs itREBOOT: yes, always or no
Add a sudo userAdds a user who may use sudo and signs in with your SSH keyUSERNAME, SSH_KEY, PASSWORD (secret, optional)
Swap fileAdds a swap file that is on at every bootSIZE_MB, SWAPPINESS
Firewall: SSH and webLets in SSH and the ports you list, and nothing else (ufw or firewalld)PORTS (80 443)
Automatic security updatesInstalls security updates by itself every daynone
fail2ban for SSHBlocks addresses that fail to sign in too oftenMAXRETRY, BANTIME
Docker EngineInstalls Docker with the compose plugin, from Docker's own repositoryDOCKER_USER (optional)
nginx with Let's EncryptServes your domain over HTTPS with a free certificate that renews by itselfDOMAIN, EMAIL
Time zoneSets the time zone and keeps the clock in stepTIMEZONE

Before you choose nginx with Let's Encrypt, point the domain's A (and AAAA) record at the server's address, and use a domain you control. Choosing it agrees to Let's Encrypt's subscriber agreement for the email you give.

To read any script before you choose it, open Show the script.

Your own scripts

You need to be an owner or admin of the organization. On your account page:

  1. Go to Compute → Deploy scripts and choose New script.
  2. Give it a name and paste the script. The first line must start with #!, such as #!/bin/sh, #!/bin/bash or #!/usr/bin/env python3. A script can be up to 64 KB.
  3. Add fields for the values you want to be asked for when you choose the script. Each field becomes an environment variable in the script, named in capitals (such as DOMAIN). For each field you can:
    • give it a label, some help text and a default;
    • make it needed: the server isn't ordered without a value;
    • make it secret: for a password or token (see below).
#!/bin/sh
set -eu
apt-get update && apt-get install -y nginx
echo "<h1>$GREETING</h1>" > /var/www/html/index.html

When you change or remove a script, servers it was already chosen for keep the copy they were given. Each organization can keep up to 100 scripts.

How it runs

The script runs once, as root, after the server's system is set up: its network, your SSH keys and its user are already in place. It runs from /root, with nothing on its input, and can run for as long as it needs. It runs only once, even if the server restarts.

Within about a minute of the script ending, its Deploy tab shows:

A script that hasn't started or ended within a day shows No result. That happens if the server wasn't built in time, or if its guest agent doesn't answer. Choosing a script again, or reinstalling without one, cancels a script that is still waiting.

A script that fails doesn't undo anything: the server is still built, and you can sign in to see what went wrong. Start a script with set -eu so it stops at the first error.

Secret values

A secret value, such as a password or an API token:

On the server it reaches the script only through its environment. The copy of the runner that holds your values deletes itself after the script runs. The server's own cloud-init keeps its settings in /var/lib/cloud, which only root can read. Don't print a secret from your script, because what the script prints is kept and shown.

Where it works

Scripts run on servers installed from one of our images, in locations with our metadata service, which hands the script to the server. If the image you chose can't run a script, we say so when you choose it. A server that boots an installer, or is installed later, has no script. Run the script yourself once it is installed.

Through the API

Back to top