Skip to content

Post-install scripts beta ​

A server or container can run a script of yours once, as root, right after the installation - order attribute post_install_script - or after a reinstall (post_install_script of the reinstall call). An earlier script is never run again.

Post-install scripts are being rolled out: while they are not available for the token's user or team, a script is refused with 422 ("not available"), post_install is missing from GET, and …/post-install answers 404.

Where to pass a script ​

CallField
Order a serverattributes.post_install_script
Order a containerattributes.post_install_script
Reinstall a serverpost_install_script
Reinstall a containerpost_install_script
json
{"family": "server", "product_id": "01JC…", "attributes": {
  "location_id": "bon1", "operating_system_id": "01JC…", "vlan_id": "01JC…",
  "post_install_script": "#!/bin/bash\nset -e\napt-get update\napt-get install -y nginx\n"
}}

Limits ​

Sizeat most 32 KB (32768 bytes) of text; Windows line endings are converted
Run timeat most one hour (the catalog's options.post_install_script.timeout_seconds), then it is stopped (timed_out)
Output keptthe last 64 KB of stdout and stderr together

The catalog's options.post_install_script tells you available, max_bytes and timeout_seconds.

How it runs ​

  • A script starting with #! runs with its shebang interpreter, otherwise with bash, else sh.
  • Working directory /root, DEBIAN_FRONTEND=noninteractive, no stdin.
  • Exit code 0 = succeeded, anything else failed.
  • The script file is removed afterwards; its log stays in /root/.anikeen-post-install.log.

Servers ​

The script runs through the QEMU guest agent - the image needs qemu-guest-agent. It starts after cloud-init has finished.

Containers ​

Containers need a template with supports_post_install_script (catalog options.locations[].templates[]; e.g. Debian and Ubuntu, not Alpine - another template answers 422 on post_install_script). The Console puts a one-time SSH key into the container, connects as root to its primary address, runs the script and removes the key again.

WARNING

In a container, do not disable sshd or root key logins before the script has finished. Do not reboot from the script (on servers neither): the run loses its process and ends as failed.

Good to know ​

  • The script and the output are stored encrypted. Still, don't put more secrets into them than needed.
  • A product that is deleted or suspended for an unpaid invoice before the script ran does not run it (failed with the reason).

Reading the result ​

post_install on GET /servers/{server} and GET /containers/{container} (null without a run):

json
{
  "id": "01JC…",
  "trigger": "install",
  "status": "succeeded",
  "exit_code": 0,
  "error": null,
  "created_at": "…", "started_at": "…", "finished_at": "…"
}
FieldValues
triggerinstall, reinstall
statuspending, running, succeeded, failed, timed_out
errorexplains a failure that was not the script's own (guest not reachable after the boot timeout of 15 minutes, product deleted, reinstall failed, …)

GET /servers/{server}/post-install and GET /containers/{container}/post-install return the latest run with script, output (the last 64 KB) and output_limit_bytes added; 404 without a run.

Anikeen Console documentation