[launchd-dev] Restrict so only one instance runs
Crawford Kyle
kcrwfrd at gmail.com
Wed Aug 27 16:42:07 PDT 2008
On Aug 27, 2008, at 3:29 PM, Dave Zarzycki wrote:
>
> On Aug 27, 2008, at 11:28 AM, Crawford Kyle wrote:
>
>> Hello,
>>
>> I often need to schedule scripts to run at an interval, but I don't
>> know how long that script will take to complete and I don't want the
>> script to run again at its normal interval unless the script isn't
>> running.
>>
>> I've done this with pid files and grepping through ps lists to exit
>> the script if another instance is running, but I was wondering if
>> there is something built into launchd to handle this.
>>
>> I tried combining LaunchOnlyOnce with StartInterval, but with
>> LaunchOnlyOnce, it seems that the job gets unloaded as soon as it
>> runs, so the interval becomes pretty meaningless.
>>
>> Is there a way to do this with launchd? Should there be a way to do
>> this with launchd?
>
>
> What you want is implicit with launchd. LaunchOnlyOnce will
> eventually get renamed to "HopefullyNeverExits" Just setup a
> StartInterval and you're set. If the job is still running, launchd
> will not start a second copy.
Thanks Dave. I must be missing something. Here is my job plist. The
shell script is just a test that logs to system log.
I see a message in system log only once though. And the job no longer
shows in launchctl list after it runs.
I tried this with and without OnDemand.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd
">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.company.test</string>
<key>ProgramArguments</key>
<array>
<string>/etc/testscript.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
<key>LaunchOnlyOnce</key>
<true/>
</dict>
</plist>
More information about the launchd-dev
mailing list