I have an Ubuntu asterisk server. We run Asterisk using systemd.
For some reason, every so often, the owner of the /var/run/asterisk folder changes from the asterisk user to root. This makes it so that I can’t run sudo asterisk -r to access asterisk’s console without changing the folder owner manually and restarting asterisk:
sudo chown -R asterisk:asterisk /var/run/asterisk
sudo service asterisk stop
sudo service asterisk start
I could change the .service file to change the folder’s permissions before running asterisk, but I don’t like that. It’s a hacky solution, but it may end up being the easiest one.
My questions are:
Are there any Ubuntu processes that could be changing this permission that I should stop?
If Asterisk is run and it doesn’t create that file (giving the error Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?), is there a way to access the Asterisk console without restarting?
We built Asterisk from source. I haven’t found how often the reset is happening, but I do know it’s been done by each time we reboot (less than once a week). I can’t say whether that’s causation or just coincidence.
asterisk/asterisk in both the service file and the asterisk.conf
If you uncomment RuntimeDirectory, then systemd will automatically create the directory and make sure the directory is owned by “asterisk” when the service starts. That’s actually the correct way to do it.
There’s actually a pull request open now where we’re discussing changes to the asterisk.service file we ship in the contrib/systemd directory.
Just to be sure I’m understanding this, this will create a /var/run/asterisk folder on run with permissions/owner set so asterisk has r/w access? Per systemd.exec(5) — Arch manual pages (with my little experience), it looks like it’ll create /run/asterisk, but not /var/run/asterisk (scroll down a bit). It could just be me not understanding properly.
The /run folder is created by the system on restart, that’s why it is owned by root.
Some systems have /var/run deprecated and substitute it with a symlink.
PIDFile is actually what helped