I compiled Asterisk 11 from source as user root on CentOS. Now I want Asterisk to run as user asterisk group asterisk. I have uncommented

#AST_USER="asterisk" #AST_USER="asterisk" 

in

/etc/sysconfig/asterisk 

I have also tried uncommenting the same variables in

/usr/local/src/asterisk-11.17.1/contrib/init.d/etc_default_asterisk 

I restart service asterisk and even reboot the server with the referred condition and when I ps ax | grep [a]sterisk, I still get

4457 pts/0 S 0:00 /bin/sh /usr/sbin/safe_asterisk 4459 pts/0 Sl 0:01 /usr/sbin/asterisk -f -vvvg -c 

instead of

 4457 pts/0 S 0:00 /bin/sh /usr/sbin/safe_asterisk -U asterisk -G asterisk 4459 pts/0 Sl 0:01 /usr/sbin/asterisk -f -vvvg -c -U asterisk -G asterisk 

I obviously added user asterisk and added group asterisk.

How to proceed to get asterisk running as asterisk in group asterisk? If you add directions on which files and directories to change permissions on, to get asterisk running as I need, would be great.

3

4 Answers

Stop Asterisk

First you need to create the asterisk user if not there(mostly its automatically created on install) Then

# useradd -d /var/lib/asterisk/ asterisk 

Next give ownership of the following dirs(spool,lib and run) to asterisk

#chown -R asterisk /var/spool/asterisk/ /var/lib/asterisk/ /var/run/asterisk/ 

copy this file form the contrib/init.d/ directory of you asterisk download

~contrib/init.d#cp etc_default_asterisk /etc/default/asterisk 

Edit the file /etc/default/asterisk by uncommenting the asterisk user

AST_USER="asterisk" AST_GROUP="asterisk" 

Lastly edit the file /etc/asterisk/asterisk.conf uncomment the runuser and rungroup as asterisk

runuser = asterisk rungroup = asterisk 

restart asterisk

#/etc/init.d/asterisk start 

This should be fine

In /etc/asterisk/asterisk.conf you can specify any user

Note: you have change permission of /var/run/asterisk/ and /var/spool/asterisk/ folder, also change permission on log folder.

0

i got the same issue. it's a bug into contrib script /etc/rc.d/init.d/asterisk

The original line to start safe_asterisk daemon is

 if [ "x$COLOR" = "xyes" ]; then                 export TERM=linux               daemon sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 & 

This line doesn't pass any supplied argument, even if $ASTARGS contains all required stuff. Even -c isn't passed correctly

If you replace this line by :

 daemon $DAEMON -U asterisk -G asterisk 

It will do the job to bypass the problem.

Saw on CentOS 7/ Asterisk 13

Note: you have change permission of /var/run/asterisk/ and /var/spool/asterisk/ folder

On reboot, the /var/run/asterisk permissions will be reset to 755 root asterisk and the daemon will be unable to write the PID file to that folder. Add the following line: d /var/run/asterisk 0775 root asterisk - to the systemd file in /usr/lib/tmpfiles.d/var.conf so that the run folder has the correct permissions after a reboot.