A startup script is a shell script or a cloud-config file that runs once, as root, on a new server's first boot. Use it to install packages, create users, write configuration files or join a server to your tooling, so every server you deploy starts the same way. You save scripts in the console and pick one when you deploy.
Write a script
- Click Startup scripts in the sidebar, under Access.
- On the right, in the New script card, give it a Name, for example
harden-ubuntu. - Paste the content into the Script field. The first line must say what it is:
#!/bin/bashfor a shell script, or#cloud-configfor cloud-init configuration. - Click Save script. The console answers "Script created. Pick it when you deploy a server." It now appears in Your scripts on the left.
A shell script example for Ubuntu or Debian:
#!/bin/bash
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install fail2ban unattended-upgrades
timedatectl set-timezone UTC
The same idea as cloud-config:
#cloud-config
package_update: true
package_upgrade: true
packages:
- fail2ban
- unattended-upgrades
runcmd:
- timedatectl set-timezone UTC
Use it when you deploy
- Click Deploy server and fill in the region, size and image.
- In the Access step, choose your script in the Startup script menu. None is the default.
- Finish the form and click Deploy now.
The script runs once, when the new server boots for the first time. You cannot attach a script to a server that already exists: on a running server, connect over SSH and run the commands yourself.
Through the API, send the script's id as script_id in the deploy request. The id is the number at the end of the script's address in the console, for example /console/scripts/12. See the API reference.
Check that it ran
Connect to the server over SSH once it shows Running, then:
cloud-init status --long
tail -n 50 /var/log/cloud-init-output.log
The output of your script goes to /var/log/cloud-init-output.log. A long script can still be running a few minutes after the server is reachable: cloud-init status --wait returns when it is done.
Edit or delete a script
- On the Startup scripts page, click the script in Your scripts. The card on the right becomes Edit script.
- Change the name or the content and click Save script, or click Delete and confirm to remove it.
- To start a new script from there, click New at the top of Your scripts.
Servers that already ran a script keep what it did. Changing or deleting the script later does not touch them.
Limits and errors
- Up to 64 KB per script. A larger one is refused with "Scripts are limited to 64 KB."
- An empty script is refused with "The script is empty."
- Windows line endings are converted when you save, so a script written on Windows still runs.
- If you delete a script while it is selected in an open deploy form, the deploy is refused with "This startup script no longer exists."
Tips
- The server keeps a reference to the script, not a copy. Leave a script unchanged until the servers deployed with it show Running.
- Keep secrets out of scripts. A script is stored as you wrote it, and its beginning shows in your list. Fetch keys and passwords from a secret store at run time instead.
- Make the first line right: a script without
#!/bin/bashor#cloud-configmay not run at all. - Test a new script on an hourly server, read the log, then delete the server.
- SSH keys do not need a script: tick them in the deploy form. See Add and use SSH keys.
- For a ready-made stack, start from a one-click app and add your own steps with a script: Deploy a one-click app.