radicaled radicaled - 4 months ago 28
Apache Configuration Question

Change apachectl on linux

I have an apache that needs to run with an specific user and specific

httpd.conf
. Anyone would do:

su - test_user -c "/opt/test_server/apache-2.2.31/bin/apachectl -k start/stop -f /opt/test_server/apache-2.2.31/conf2/httpd.conf"


My problem is that I need to do that on the
apachectl
script. So when I do:

apachectl start


Apache will start the specific command and
httpd.conf
file.

So, what apache normally does is:

case $ARGV in
start|stop|restart|graceful|graceful-stop)
$HTTPD -k $ARGV
ERROR=$?


Where
HTTPD='/opt/test_server/apache-2.2.31/bin/httpd'
and
ARGV
is the argument that runs(
start
/
stop
). I tried to change it this way:

ARGV=$ARGV" -f /opt/test_server/apache-2.2.31/conf2/httpd.conf"
COMMAND="su - my_id -c \"${HTTPD} -k ${ARGV}\""
$COMMAND
ERROR=$?


But when I try to run it, I get this error:

[root@thunder bin]# ./apachectl stop
su - test_user -c "/opt/test_server/apache-2.2.31/bin/httpd -k stop -f /opt/test_server/apache-2.2.31/conf2/httpd.conf"
su: invalid option -- k
Try `su --help' for more information.


What I'm doing wrong?

Answer

you might use eval $COMMAND which will execute your command stored in a variable.