/var/run/asterisk owner keeps changing

Hello!

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:

  1. Are there any Ubuntu processes that could be changing this permission that I should stop?
  2. 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?

Thank you so much!

A few questions…

How are you installing asterisk? From packages or from source? Is the reset happening when you re-install?

What user is asterisk run as and how is it being set? From the service file using 'User=" and “Group=” or from asterisk.conf “runuser” and “rungroup”?

Is “RuntimeDirectory=” specified in the service file?

I don’t think so.

Not directly. In an emergency or for one-time requests, you can issue CLI commands via the AMI “Command” action.

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

It is, but it’s commented out:

#RuntimeDirectory=asterisk

Thanks for the help!

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.

Sounds good! I’m following that PR now.

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.

Thanks for the help!

I had the same problem but fixed it with the service section like this:

[Service]
User=your-user
Group=your-user
Restart=always
Type=forking
RuntimeDirectory=asterisk
PIDFile=/run/asterisk/asterisk.pid
ExecStart=/usr/sbin/asterisk -C ${AST_CONFIG} $ASTERISK_OPTS
ExecReload=/usr/sbin/asterisk -rx ‘core reload’
ExecStop=/usr/sbin/asterisk -rx ‘core stop now’
Environment=‘AST_CONFIG=/etc/asterisk/asterisk.conf’ ‘AST_USER=your-user’

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

In most modern distros, /var/run is a symlink to /run

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.