Apache config test and send signal to restart apache if syntax check is passed

10 views
Skip to first unread message

Himanshu Maity

unread,
Dec 11, 2018, 1:19:00 PM12/11/18
to Ansible Project
Hi,

I'm trying to run two commands in a single line, which will validate the syntax of apache configuration copied from template file and send a signal to reload the apache if it's passed.

Right now, my configuration looks like as below where I only sending the signal to apache to reload after coping the config from template file and it's working fine.

command: '-consul={{ ansible_host }}:2250 -template="vhosts.ctmpl:vhosts.conf:/bin/docker/docker kill -s USR1 apache"'

But I'm trying to add configtest with this command like,

command: '-consul={{ ansible_host }}:2250 -template="vhosts.ctmpl:vhosts.conf:/bin/docker/docker exec apache /usr/local/apache2/bin/apachectl configtest && /bin/docker/docker kill -s USR1 apache"'


But, the last reload of the apache command is failing as I can't send the signal to reload own process(apache) inside of staying in the container.


Can anyone please guide, you help is truly appreciated. Thanks in advance.


Best Regards

Himanshu Maity

Brian Coca

unread,
Dec 11, 2018, 1:31:56 PM12/11/18
to Ansible Project
First i would make this a script and use the 'script' module, but the
issue you are probably hitting is that 'command' does not support
'shellisms' like &&, so you need to use the shell module




--
----------
Brian Coca

Himanshu Maity

unread,
Dec 11, 2018, 1:45:16 PM12/11/18
to Ansible Project
Thanks for your response Brian.

I think I'm using docker exec which support &&, please find the screenshot attached. 

Screen Shot 2018-12-11 at 12.37.23 PM.png


Like, if I run this command  -   docker exec -it apache bash -c "/usr/local/apache2/bin/httpd -t && echo a" ,then it execute properly. 

But, once I'm trying to run this -
 docker exec -it apache bash -c "/usr/local/apache2/bin/httpd -t && /bin/kill -s USR1 apache" ,then 1st command is getting executed but 2nd command is giving error as I used 'docker exec' to get into the container and it can't reload the apache staying inside of container. 

Output:

[root@### ~]$ docker exec -it apache bash -c "/usr/local/apache2/bin/httpd -t && /bin/kill -s USR1 apache"

Syntax OK

kill: failed to parse argument: 'apache'


FYIP, apache is a container running on the host.

Brian Coca

unread,
Dec 11, 2018, 1:55:46 PM12/11/18
to Ansible Project


On Tue, Dec 11, 2018 at 1:45 PM Himanshu Maity <himanshu....@gmail.com> wrote:
Thanks for your response Brian.

I think I'm using docker exec which support &&, please find the screenshot attached. 

-- 
For that you need to go to a docker mailing list/support forum.

I only responded to the first post as it seemed to show an incorrect usage of the Ansible comand module.

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages