Manage an application
This example installs a systemd service with a JSON config file. The config is checked before it replaces the old one, and the service restarts when the config changes. The files are in the repository at examples/service/: main.hcl, config.json, and rivet-example.service. The validator needs Python 3 on the host.
source paths are relative to the configuration directory. Their content is copied into the bundle, so the host doesn’t need the original files.
Compile and apply
On the disposable Ubuntu host from the first walkthrough:
The directory already exists from the first walkthrough. You can also compile on another machine: copy facts.json there, compile, and copy the bundle back.
What happened
- Validation before replacement. Rivet wrote the new JSON to a temporary file next to its destination and ran the validator on it, replacing
{candidate}with that file’s path. Only after the validator succeeded was the file moved into place. If validation fails, the old file stays untouched. - Daemon reload. Because the unit file lives in
/etc/systemd/systemand the service usesdaemon_reload = "auto", Rivet ordered the unit file before the service and ransystemctl daemon-reloadonce before starting it. That’s theAction: daemon_reloadline. - No redundant restart. The config change queued a restart, but the service was starting for the first time, so the start satisfied it. Later config changes restart the service.
If the run had been interrupted after the config changed but before the restart, the next apply would still restart the service. See recovery.
Extend it
Add a package for the application’s dependencies, and a user and group for a service account. Add depends_on where order matters, for example a service that needs an installed package. Naming an account in a command’s user field does not by itself order the command after the account. See relationships.