Hello fellow computer people 🙂
I have a shell script that I will use as a watchdog timer. It checks to see if my other ‘main’ program is running. If it is not, it restarts it.
The question is: How do I get this installed on a Mac? Is there a folder/plist file scenario somewhere where the OS will automatically and periodically call the script, ensuring that my program never goes that long without running? I would ideally like to test every minute, but every hour or even a couple of times a day would be satisfactory.
Thank you!
The way to do this on Mac OS X is using Launch Services. It replaces the older system services such as
initandcrontaband provides a single, unified framework for managing system services.In your case, you probably don’t need a separate script – keeping an instance of your app running should be handled by the system. First you need to create
.plistfile that describes your daemon/script/application. You place it in one of the following locations, depending on the type of service:~/Library/LaunchAgents: Per-user agents provided by the user./Library/LaunchAgents: Per-user agents provided by the administrator./Library/LaunchDaemons: System wide daemons provided by the administrator./System/Library/LaunchAgents: Mac OS X Per-user agents./System/Library/LaunchDaemons: Mac OS X System wide daemons.Once you have defined the service, you can use the
launchctlcommand to controllaunchd. For example, you can list running services, start/stop services, and so on.The full documentation is here:
launchdDaemons and Agents