I have several pieces of server software installed on my MacBook Pro for work using Homebrew. There is one service in particular, that likes to peg the CPU after the OS wakes up from sleep until I restart it. The service is currently managed by launchd, and I am wondering if there is a way for me to tell launchd to stop the service when the OS goes to sleep, and then start it up again on wake.
You can use SleepWatcher:
It can be used to execute a Unix command when the Mac or the display of the Mac goes to sleep mode or wakes up, after a given time without user interaction or when the user resumes activity after a break or when the power supply of a Mac notebook is attached or detached.
launchctl load <path> and
launchctl unload <path> with SleepWatcher on wake and sleep respectively.
I ended up using ControlPlane's Laptop Lid Open/Closed event to switch to a context that stops and starts the service using