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  
 <plist version="1.0">

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

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 | |

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 .