title: OSX, shutting launchd daemon down and network is not available
body: <p>We have launchd daemon which should be running forever and be started as soon as system is booted, therefore in its plist we say:</p>
  
  <p><code>&lt;key&gt;KeepAlive&lt;/key&gt;
  &lt;true/&gt;
  </code></p>
  
  <p>Everything is OK until the system is shutdown. Agent needs to inform the remote server about the system being shutdown, via HTTP. System sends SIGTERM to the agent just fine and agent is able to process it. However, by the time it receives SIGTERM, DNS (or maybe entire networking subsystem) is already down, and it cannot send status to the server as it cannot resolve its name. All network functions fail, so I suspect networking is down. On Linux this is resolved by SNN/KMM symlinks with NN=99 and MM=00. However on OSX it is explicitly said that launchd daemons don't have any priorities. How then can we have OSX to send SIGTERM to our daemon before it shuts down DNS/networking?</p>
  
  <p>I have quickly looked at ability to register a listener for system shutdown event as program can register itself to listen for power mode changes (namely, sleep), however a few sources told that this is not possible either - <a href="https://stackoverflow.com/questions/1321219/receiving-power-notifications-especially-shutdown-on-mac-osx">Receiving power notifications (especially shutdown) on Mac OSX</a>.</p>