systemctl cat — verify an env override took effect
Source: Cairn deploy — verifying
CAIRN_DATA_DIRdrop-in Category: Snippet — systemd
systemctl cat — prints the effective unit configuration, merging the base unit with every drop-in. Use it after any edit/override to confirm your change landed. Far more reliable than trusting the editor closed cleanly.
The command
Section titled “The command”sudo systemctl cat <unit-name>Shows every file contributing to the unit, with comments pointing to the file path:
[Unit]Description=Portfolio Web ServerAfter=network.target
[Service]ExecStart=/usr/bin/node /opt/portfolio/ts/src/web-server.tsRestart=on-failure
# /etc/systemd/system/portfolio-web.service.d/cairn-data-dir.conf[Service]Environment="CAIRN_DATA_DIR=/var/lib/cairn"
# /etc/systemd/system/portfolio-web.service.d/port.conf[Service]Environment=WEB_PORT=3000Two drop-ins visible; each in its own file. If either is missing, cat would skip it — immediate confirmation that “did my override take”.
When to use it
Section titled “When to use it”After every one of:
systemctl edit <unit>tee /etc/systemd/system/<unit>.d/override.conf- Editing the base unit file directly
- Package upgrade that might have regenerated a unit
Combined with grep for specific values
Section titled “Combined with grep for specific values”sudo systemctl cat portfolio-web.service | grep CAIRN_DATA_DIREmpty output means the env var isn’t set anywhere. Exactly what you need to confirm when troubleshooting “why isn’t my service picking up this variable”.
Related commands
Section titled “Related commands”| Command | What it shows |
|---|---|
systemctl cat <unit> | merged unit + all drop-ins (this snippet) |
systemctl show <unit> | computed state (every key the system has for this unit, expanded) |
systemctl status <unit> | current status, recent log lines |
systemctl is-enabled <unit> | enabled / disabled / masked / static |
journalctl -u <unit> -f | live log tail |
systemctl show is verbose and often overwhelming; systemctl cat is the pragmatic daily check.
The common failure mode
Section titled “The common failure mode”systemctl edit <unit> opens an editor for override.conf. If you save without adding content (just wrote nothing and closed), the override file is created but empty. systemctl cat shows the empty drop-in — that’s how you notice.
(empty)Fix: write the drop-in directly with tee, skipping the editor:
sudo tee /etc/systemd/system/portfolio-web.service.d/cairn-data-dir.conf <<'EOF'[Service]Environment="CAIRN_DATA_DIR=/var/lib/cairn"EOFsudo systemctl daemon-reloadsudo systemctl cat portfolio-web.service | grep CAIRN_DATA_DIRGotchas
Section titled “Gotchas”daemon-reloadis required after changes.systemctl catshows the file content — if you forgot daemon-reload, the running service still uses the old config even thoughcatshows the new one. Always: edit →daemon-reload→cat(sanity) →restart.catandshowdisagree on purpose.catis textual (unit files).showis runtime state (what systemd parsed and kept). Runtime can differ from files when daemon-reload is skipped.- Permissions.
sudo systemctl catusually works without sudo because unit files are world-readable.systemctl editrequires sudo because it writes to/etc/systemd/. - User units. For
--userservices, the path is~/.config/systemd/user/and you don’t use sudo. - No instance matching. For template units like
[email protected],systemctl cat [email protected]works;systemctl cat foo@doesn’t. - Masked units. If a unit is masked (
ln -s /dev/null ...),catreturns essentially nothing.is-enabledsurfaces “masked”.
See also
Section titled “See also”- snippets/systemd-drop-in-env-var — the pattern this verifies
- patterns/vps-deploy-runbook-shape — where “verify” is a runbook step