Skip to content

fix(asterisk): create the run directory on every start - #36

Merged
MarkProminic merged 2 commits into
mainfrom
fix/asterisk-runtime-directory-35
Oct 28, 2026
Merged

MarkProminic merged 2 commits into
mainfrom
fix/asterisk-runtime-directory-35

Conversation

@solaechea

@solaechea solaechea commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Written with Claude Opus 5.5

Fixes #35.

Change

roles/asterisk/templates/asterisk.service.j2 now sets RuntimeDirectory=asterisk, which was already in the template but commented out. systemd then creates /run/asterisk, owned by the unit's asterisk user, on every start.

It also sets RuntimeDirectoryPreserve=yes. Without that, systemd deletes the directory every time the unit stops, including restarts. The role's "Creating Asterisk runtime directories" task then had to recreate it, which broke molecule's idempotence check.

Before this, the directory existed only until the first reboot: /run is a tmpfs, and Asterisk runs as asterisk, which can't recreate it. Asterisk then started without its control socket, so asterisk -rx and systemctl reload asterisk failed.

Testing

On a Debian 12 EC2 instance provisioned with this role:

  • Without the change: after a reboot, /run/asterisk was owned by root and empty, and asterisk -rx "core show uptime" failed with Unable to connect to remote asterisk.
  • With the change (unit updated, daemon-reload, then a reboot): /run/asterisk was owned by asterisk and held asterisk.ctl and asterisk.pid. asterisk -rx "core show uptime" and systemctl reload asterisk both worked.
  • RuntimeDirectoryPreserve: checked on a throwaway unit in a Debian 12 systemd container, the same image molecule uses.
    • Without it, /run/asterisk was gone after systemctl stop.
    • With it, the directory stayed asterisk:asterisk 755 across stop, start and restart.
    • The EC2 reboot test above was run before this line was added.
  • prettier --check passes.

/run is a tmpfs, so the directory the role creates during the play is
gone after a reboot. Asterisk runs as the asterisk user, which can't
recreate it, so it started without a control socket and asterisk -rx
and the unit's reload failed. RuntimeDirectory has systemd create it,
owned by the unit's user, on each start.
Without RuntimeDirectoryPreserve, systemd deletes /run/asterisk every
time the unit stops, including restarts, so the role's runtime
directories task recreated it and reported a change on the next run.
@MarkProminic
MarkProminic merged commit 26c5526 into main Oct 28, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asterisk: no control socket after a reboot (RuntimeDirectory is commented out)

2 participants