Init.d/asterisk not passing parameters to safe_asterisk!

I wanted to run asterisk as user asterisk and group asterisk instead of root. I read in a post that the way to do this is to add the following two lines to /etc/init.d/asterisk:


which makes sense since the script check those values and set $ASTARG accordingly, but it did not work!

After much debugging, not being that familiar with the bash shell, I discover that the line invoking safe_asterisk was not passing the parameters properly, so the following line:

            daemon sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &

needs to be changed to

            daemon sh -c \"$DAEMON $ASTARGS -c\" >/dev/null </dev/null 2>&1 &

else, the double quotes gets removed from the parameter list when the daemon is called, so the “-c” option of the “sh” command sees only the $DAEMON parameter, and not the $ASTARG -c .

I am surprised to see such a bug in a so important script, am I missing something???

Maybe I am not using the proper way to run asterisk as the user asterisk???

BTW, the safe_asterisk script adds the “-c” option by default unless the $CONSOLE variable is set to “no” by a script in /etc/asterisk/startup.d In other words, I do not beleive that the “-c” option should be specified in the init.d script, it could prevent someone from not setting it.

This is with Asterisk running on CentOS 6
This was from a net install as root, and I compiled the code, it was ot a binary install.

Some logging

“ps” without escaping the double quotes

1 S root 3765 1 0 80 0 - 1254 - 14:48 pts/0 00:00:00 /bin/sh /usr/sbin/safe_asterisk
4 S root 3767 3765 15 80 0 - 8480 - 14:48 pts/0 00:00:00 /usr/sbin/asterisk -f -vvvg -c

“ps” with the backslash to escape the double quote

1 S root 3850 1 0 80 0 - 1254 - 14:50 pts/0 00:00:00 /bin/sh /usr/sbin/safe_asterisk -U asterisk -G asterisk -c
4 S asterisk 3852 3850 20 80 0 - 8476 - 14:50 pts/0 00:00:00 /usr/sbin/asterisk -f -U asterisk -G asterisk -c -vvvg -c

It is not as simple as setting those options. You need to understand how the Linux startup logic and LInux permissions work. I believe some things, like differentiated service settings, are impossible.

I haven’t tried it and wouldn’t advise it for anyone who doesn’t have a deep understanding fo the above issues. It is normally easier just to sacrifice the system, if the worst comes to the worst. There is not a lot of data that should be stored on it.