4

I created a simple Ansible role with the purpose of configuring dnsmasq on OSX targets (dnsmasq is installed from homebrew).

I want to create a handler that would restart the daemon when configuration file gets changed (Ansible as of version 1.9.3 does not implement service module for OSX).

I have a task:

- name: Create dnsmasq config file in /usr/local/etc/ from template
  template: src=dnsmasq.conf.j2 dest=/usr/local/etc/dnsmasq.conf
  notify:
  - restart dnsmasq

In /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist there is a key <key>KeepAlive</key> which starts the daemon automatically when not running, so the following handler does its job. Can I always rely on this?

- name: restart dnsmasq
  sudo: yes
  command: launchctl stop homebrew.mxcl.dnsmasq

Aren't there any scenarios or timing issues that would result in the daemon getting permanently stopped? What would be the proper way for such handler to be written?

techraf
  • 4,243
  • 8
  • 29
  • 44

1 Answers1

3

From launchctl(1):

 stop label
          Stop the specified job by label. If a job is on-demand, launchd
          may immediately restart the job if launchd finds any criteria
          that is satisfied.

So I'd assume that the KeepAlive would cause the daemon to come back up, though that subcommand is down in the LEGACY SUBCOMMANDS block, so might be removed by Apple at some point in the future? kickstart -k looks like it would perform a start-or-restart, and is not in the legacy block...

thrig
  • 1,676
  • 11
  • 9