paweu
(paweu)
July 26, 2012, 7:24pm
1
Hi,
I’m trying to run a daemon on a server with ansible:
name: “Run daemon”
action: shell if [ -z “$(ps axu | grep daemon | grep -v grep)” ]; then /root/bin/daemon; fi
I would like it to turn the daemon on and run the next action in my playbook, but it is stuck there as if it cannot let the daemon go to background. I tried & at the end already
When just starting from the shell this daemon goes straight to background.
Could you make an init script for it? Have you tried using the ‘service’ module instead of ‘shell’?
service name=mydaemon state=started
http://ansible.github.com/modules.html#id11
paweu
(paweu)
July 26, 2012, 7:31pm
3
W dniu czwartek, 26 lipca 2012 21:26:02 UTC+2 użytkownik Mark Theunissen napisał:
Could you make an init script for it? Have you tried using the ‘service’ module instead of ‘shell’?
I really don’t want to do it. I have it like that on many servers.
Is there no way to put it to background?
Possibly “fire and forget” with async (see docs)
You do have to set a maximum runtime for the command, because Ansible will kill it if not done by then.
paweu
(paweu)
July 26, 2012, 7:52pm
5
It works with:
async: 1
poll: 0
Thanks
W dniu czwartek, 26 lipca 2012 21:36:26 UTC+2 użytkownik Michael DeHaan napisał:
I really don't want to do it. I have it like that on many servers.
Create a template for the init script, push that out through your
playbook and launch that.
-action: template src=myinit.script.j2 dest=/etc/init.d/$item mode=0755
with_items:
- daemon1
- daemon2
- service14
-action: command /sbin/chkconfig $item on
with_items:
- daemon1
- daemon2
- service14
-action: service name=$item state=running
with_items:
- daemon1
- daemon2
- service14
Untested, but you get the idea.
Safest way I'd say.
-JP
Please, whatever you do next, learn to use pgrep first !
What you do can be simplified to:
if ! pgrep daemon &>/dev/null; then /root/bin/daemon; fi
or you can do:
pgrep daemon &>/dev/null || /root/bin/daemon
but I prefer the former as it is more explicit.
PS Yes, it is unfortunate that pgrep does not have the -q option.
paweu
(paweu)
July 27, 2012, 6:28pm
8
Thanks for the tip
W dniu piątek, 27 lipca 2012 14:40:58 UTC+2 użytkownik Dag Wieers napisał: