0

I have a script scheduled to run as LaunchDaemon. Script runs fine when launched manually through terminal.

I have two commands

sudo launchctl unload -F /Library/LaunchDaemons/com.test.plist
sudo launchctl load -F /Library/LaunchDaemons/com.test.plist

plist below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com  
 /DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
  <key>Label</key>
  <string>com.test.plist</string>
 <key>Program</key>
 <string>/usr/local/bin/test.sh</string>
 <key>StandardErrorPath</key>
 <string>/tmp/com.test.plist.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.test.plist.out</string>
<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>18</integer>
    <key>Minute</key>
    <integer>4</integer>
</dict>

when run separately they do work. But once scheduled in launchd it runs for split second them goes to unloaded. I am guessing once it unloads the script it stops running. I change the values of the intervals set in the plist with another script which is why I need to unload and load. Is there another way to do this?

  • What does the plist look like - we need to know what options you have chosen – mmmmmm Oct 27 '14 at 17:59
  • Well that should just run the script and from what you say it does - what does the output text file show - what does the script do/ Also what do you mean ny unload - here the plist runs your script – mmmmmm Oct 27 '14 at 18:13
  • It doesnt write anything to the plist.out file. I get some 'launchd assertion failed' error messages in the console but other than that nothing. The script does an initial backup and unloads / loads the new schedule time which is updated using another script that runs first and uses plistbuddy to make the changes. – MBP2013 Oct 27 '14 at 18:22
1

Is the problem perhaps that your unload command hasn't finished before the load command starts?

How about trying kickstart instead? "-k" instructs launchctl to "kill the running instance before restarting the service."

sudo launchctl kickstart -k /Library/LaunchDaemons/com.test.plist

Note that load and unload are now under "Legacy commands" in the Yosemite launchctl man page.

| improve this answer | |
0

Thanks Alastair, good to know for the future but presently I am only running Mavericks.

My solution was to put the load commands into the first script (which isnt executed by launchd). I think the issue was caused trying to unload and load while launchd was already running the script.

Thanks for the suggestions

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .