Deploy scripts
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.
| Script | What it does | Values |
|---|---|---|
| Update the system | Updates every package, then restarts a minute later if the update needs it | REBOOT: yes, always or no |
| Add a sudo user | Adds a user who may use sudo and signs in with your SSH key | USERNAME, SSH_KEY, PASSWORD (secret, optional) |
| Swap file | Adds a swap file that is on at every boot | SIZE_MB, SWAPPINESS |
| Firewall: SSH and web | Lets in SSH and the ports you list, and nothing else (ufw or firewalld) | PORTS (80 443) |
| Automatic security updates | Installs security updates by itself every day | none |
| fail2ban for SSH | Blocks addresses that fail to sign in too often | MAXRETRY, BANTIME |
| Docker Engine | Installs Docker with the compose plugin, from Docker's own repository | DOCKER_USER (optional) |
| nginx with Let's Encrypt | Serves your domain over HTTPS with a free certificate that renews by itself | DOMAIN, EMAIL |
| Time zone | Sets the time zone and keeps the clock in step | TIMEZONE |
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:
- Go to Compute (the list of your servers, not one server's page) and scroll to the Deploy scripts card, below the servers, reserved addresses and private networks. Or follow Write your own deploy scripts under the Deploy script box when ordering, setting up or reinstalling a server. Choose New script.
- Give it a name and paste the script. The first line must start with
#!, such as#!/bin/sh,#!/bin/bashor#!/usr/bin/env python3. A script can be up to 64 KB. - 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:
- Done when the script exited with 0, or Failed with its exit status;
- the last 16 KB of what it printed. On the server, the whole output is in
/var/lib/zappocity/deploy/RUN-ID/log.
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:
- is kept sealed while the script waits;
- is never shown again, on the Deploy tab or anywhere else;
- is erased once the script has run.
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
GET /api/account/orgs/{orgId}/scriptslists your scripts and the public ones.POST /api/account/orgs/{orgId}/scriptsadds a script, andPUTandDELETEon.../scripts/{scriptId}change or remove one.- Ordering (
.../servers/order), finishing set-up (.../setup) and reinstalling (.../reinstall) take"deploy": {"scriptId": "...", "values": {"DOMAIN": "www.example.com"}}. GET .../servers/{serverId}/deploysshows how the scripts ran.