Repository navigation
fix(asterisk): create the run directory on every start - #36
Merged
Merged
Conversation
/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written with Claude Opus 5.5
Fixes #35.
Change
roles/asterisk/templates/asterisk.service.j2now setsRuntimeDirectory=asterisk, which was already in the template but commented out. systemd then creates/run/asterisk, owned by the unit'sasteriskuser, 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:
/runis a tmpfs, and Asterisk runs asasterisk, which can't recreate it. Asterisk then started without its control socket, soasterisk -rxandsystemctl reload asteriskfailed.Testing
On a Debian 12 EC2 instance provisioned with this role:
/run/asteriskwas owned byrootand empty, andasterisk -rx "core show uptime"failed withUnable to connect to remote asterisk.daemon-reload, then a reboot):/run/asteriskwas owned byasteriskand heldasterisk.ctlandasterisk.pid.asterisk -rx "core show uptime"andsystemctl reload asteriskboth worked.RuntimeDirectoryPreserve: checked on a throwaway unit in a Debian 12 systemd container, the same image molecule uses./run/asteriskwas gone aftersystemctl stop.asterisk:asterisk 755across stop, start and restart.prettier --checkpasses.