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.
Tha开发者_开发百科nk you!
The way to do this on Mac OS X is using Launch Services. It replaces the older system services such as init
and crontab
and 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 .plist
file 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 launchctl
command to control launchd
. For example, you can list running services, start/stop services, and so on.
The full documentation is here:
- Creating
launchd
Daemons and Agents - Daemons vs Agents
I'm not a Mac user but there should be cron
daemon. http://hints.macworld.com/article.php?story=2001020700163714
Crontab should do you nicely. Set your script to run every X minutes and cron will do the rest. If you prefer a GUI interface to your programs, try cronnix.
精彩评论