Provisioning the VM
Build vm-nri-www with these steps, in order. They are idempotent and safe to
re-run. They also serve as the rebuild procedure, since there is no VM-level
backup. The Azure-side prerequisites — the NSG rules, the managed identity and
its vault grant — are on the Azure page.
1. Swap
Section titled “1. Swap”fallocate -l 4G /swapfilechmod 600 /swapfilemkswap /swapfileswapon /swapfileecho '/swapfile none swap sw 0 0' >> /etc/fstabprintf 'vm.swappiness=10\n' > /etc/sysctl.d/60-swap.confsysctl -p /etc/sysctl.d/60-swap.confThe VM has 4 GiB of RAM, and the conventional guidance for a 4 GiB server is a
swap file equal to RAM. It exists as a cushion, not as working memory:
Umbraco’s Examine index rebuilds and the Node SSR process are both capable of a
short allocation spike that would otherwise end in the kernel killing the
application. vm.swappiness=10 keeps the kernel from reaching for swap during
normal operation. The VM size has no temporary disk, so the swap file lives on
the OS disk and is covered by its encryption.
2. Package repositories
Section titled “2. Package repositories”Caddy, from Cloudsmith:
apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curlcurl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \ | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpgcurl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \ > /etc/apt/sources.list.d/caddy-stable.listAzure CLI, from Microsoft — needed by the backup job, not by the application:
mkdir -p /etc/apt/keyringscurl -sLS https://packages.microsoft.com/keys/microsoft.asc \ | gpg --dearmor -o /etc/apt/keyrings/microsoft.gpgchmod go+r /etc/apt/keyrings/microsoft.gpgcat > /etc/apt/sources.list.d/azure-cli.sources <<'EOF'Types: debURIs: https://packages.microsoft.com/repos/azure-cli/Suites: resoluteComponents: mainArchitectures: amd64Signed-By: /etc/apt/keyrings/microsoft.gpgEOFBoth repositories are pinned to a signing key. Nothing is installed from a pipe-to-shell installer.
3. Packages
Section titled “3. Packages”apt-get updateapt-get install -y aspnetcore-runtime-10.0 nodejs sqlite3 rsync caddy \ unattended-upgrades git htop azure-cli| Package | Why |
|---|---|
aspnetcore-runtime-10.0 |
Umbraco 17 targets .NET 10 |
nodejs |
Svelte SSR runs as a Node child process of the CMS |
caddy |
Reverse proxy, automatic HTTPS |
sqlite3 |
Used by the backup job to snapshot the databases |
rsync |
Used by make deploy |
azure-cli |
Used by the backup job to upload snapshots |
dpkg -l on the host shows the installed versions; this page does not pin
them.
4. Unattended security upgrades
Section titled “4. Unattended security upgrades”APT::Periodic::Update-Package-Lists "1";APT::Periodic::Unattended-Upgrade "1";Allowed origins are the Ubuntu distribution and -security pockets only.
Automatic reboot is off, so a kernel update needs a scheduled reboot. Check
for one with cat /var/run/reboot-required.
5. Application directory
Section titled “5. Application directory”mkdir -p /var/www/nri-inc.org/umbraco/Logs /var/www/nri-inc.org/umbraco/Datachown -R www-data:www-data /var/www/nri-inc.orgThe whole tree is owned by www-data, and make deploy writes into it as
www-data over rsync. That means the application can modify its own deployed
code. Root-owned code with only umbraco/ writable by www-data would be
tighter, and would need the deploy to write as a different user.
6. systemd units
Section titled “6. systemd units”The unit files are checked into the repository under deploy/. Install them
unchanged:
install -m 644 deploy/nri-inc.service /etc/systemd/system/install -m 644 deploy/backup/nri-inc-backup.service /etc/systemd/system/install -m 644 deploy/backup/nri-inc-backup-daily.timer /etc/systemd/system/install -m 700 deploy/backup/nri-inc-sqlite-backup /usr/local/sbin/systemctl daemon-reloadsystemctl enable nri-inc.servicesystemctl enable --now nri-inc-backup-daily.timernri-inc.service sets User/Group=www-data, UMask=0027 and
NoNewPrivileges=true. It does not set ProtectSystem, PrivateTmp,
ProtectHome or a CapabilityBoundingSet; those would further limit what a
compromised application can touch.
7. Caddy
Section titled “7. Caddy”# cms.nri-inc.org — the only site on this server.cms.nri-inc.org { tls /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.crt /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.key reverse_proxy 127.0.0.1:5019}The certificate is a Cloudflare origin certificate for cms.nri-inc.org,
created in the Cloudflare dashboard under SSL/TLS → Origin Server.
Cloudflare shows the private key only once, at creation. Save both files
before reloading Caddy:
install -d -m 750 -o root -g caddy /etc/caddy/certs# paste the certificate and key into these two fileschown root:caddy /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.*chmod 644 /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.crtchmod 640 /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.keycaddy validate --config /etc/caddy/Caddyfilesystemctl reload caddyCaddy requests no certificate of its own, so the site works as soon as DNS
points at the VM through Cloudflare. The packaged
service unit runs as the caddy user with ProtectSystem=full and the
CAP_NET_ADMIN/CAP_NET_BIND_SERVICE ambient capabilities. To compare the
effective configuration between hosts, compare the adapted JSON rather than the
source text:
caddy adapt --config /etc/caddy/Caddyfile8. Secrets and database
Section titled “8. Secrets and database”Write /etc/nri-inc-backup.env (root:root, mode 600) with the backup
account key; the backup job reads it. Application secrets need nothing on the
host once the VM’s managed identity holds its vault role.
To copy a live database onto the host — from a backup, or from another
machine — use SQLite’s own VACUUM INTO, which produces a consistent copy of
a running database. A plain cp of a database in WAL mode can copy a torn page
and is not safe:
sqlite3 Umbraco.sqlite.db "VACUUM INTO '/var/tmp/nri-xfer/Umbraco.sqlite.db';"sqlite3 Umbraco.Automate.sqlite.db "VACUUM INTO '/var/tmp/nri-xfer/Umbraco.Automate.sqlite.db';"sqlite3 /var/tmp/nri-xfer/Umbraco.sqlite.db 'PRAGMA quick_check;' # okCheck PRAGMA quick_check on both ends of the transfer.
9. Deploy
Section titled “9. Deploy”Release the application with make deploy — see
Deploying on the architecture page.