Asterisk systemd startup script

The systemd startup script “out of the box” (at least up to version 15.5) for Asterisk does not work properly: on rebooting the server the ownership of /run/asterisk (symlink /var/run/asterisk) reverts to root.root instead of asterisk.asterisk

The reason for this is that the o/s removes and re-creates the /run/asterisk directory on reboot. The solution is to place a “RuntimeDirectory=” entry in the systemd service script:

/usr/lib/systemd/system/asterisk.service

The “RuntimeDirectory=” needs a directory name relative to /run so you can’t do this:

RuntimeDirectory=/run/asterisk

nor this:

RuntimeDirectory=/var/run/asterisk

You need to do this:

RuntimeDirectory=asterisk

Here is my fully working script (/usr/lib/systemd/system/asterisk.service):