Skip to content

Recipe: Find out why a service keeps dying

James Conway edited this page Oct 28, 2026 · 1 revision

app-billing.service falls over every so often, the journal says Permission denied, and ausearch hands you a few hundred denials from the last hour. Most of them have nothing to do with it. This recipe gets you the ones that do.

1. Watch the unit

Drop this in /etc/sentry-v2/policies.d/50-app-billing.toml:

[[policy]]
name = "app-billing-failed"

[policy.when]
signal = "unit_failed"
units = ["app-billing.service"]

[[policy.do]]
action = "notify"

notify changes nothing on the host. Strictly, you don't need the policy at all, because every failure gets a bundle anyway. What it adds is a decision with this policy's name in the bundle, so you can filter on it downstream.

# sentry-v2ctl policy validate
# systemctl reload sentry-v2

2. Wait for it to fail, then read the bundle

# sentry-v2ctl incidents --unit app-billing.service
# sentry-v2ctl show <ID> | jq '.incident.correlations[] | {confidence, reasons, domain: .avc.scontext_type, perms: .avc.perms, target: .avc.tcontext, class: .avc.tclass}'

Each correlation is a denial Sentry-v2 thinks belongs to this failure, with a score and the reasons. Look at the reasons before the score:

  • pid in unit cgroup means the denied process was inside this unit when the kernel refused it. That's as close to proof as the audit log gets.
  • scontext type matches unit domain and comm matches ExecStart without the cgroup reason are a lead. Something running the same binary in the same domain was denied. Usually it's this unit; on a host with template units it might be a sibling.

A denial from a process that was in another unit's cgroup when it arrived stays out of the bundle, however loud it is.

3. Ask SELinux why, before you change anything

Pull exactly those denials out of the audit log and let audit2allow explain them:

# sentry-v2ctl show <ID> | jq -r '.incident.correlations[].avc.serial' \
    | while read -r id; do ausearch --input-logs -a "$id" --raw; done \
    | audit2allow -w

Read what it says. More often than not, the answer is a label or a boolean, not a new policy module:

  • A file in the wrong place, or with the wrong label. restorecon -v on it, or semanage fcontext if it lives somewhere non-standard.
  • A feature that's off. audit2allow -w names the boolean; check it with getsebool and set it with setsebool -P.
  • Something the policy really doesn't allow. That's when a local module is the answer, and you'll know exactly what's in it.

Sentry-v2 won't load policy for you, from the CLI or from Cockpit. audit2allow -M output loaded unread is how a mislabelled file becomes a permanent hole.

See also