Resolved odd LaunchAgent behaviour

Discussion in 'OS X Mavericks (10.9)' started by costabunny, Nov 4, 2013.

  1. costabunny, Nov 4, 2013
    Last edited: Nov 15, 2013

    costabunny macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #1
    I have my backup shell script and it works as expected when run from the cli. It also runs ok from its LaunchAgent entry (in ~/Library/LaunchAgents/)

    The problem is that the script uses /usr/bin/mail at the end of a run to send the content of the summary log to myself. When running from the prompt this is successful; however when running from launchd it simply does not send the email. the mail logs show no attempt at all from the script.

    Any ideas?

    Code:
    ~/Library/LaunchAgents/com.local.lokibackup.plist 
    
    
    <?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.local.lokibackup</string>
        	<key>ProgramArguments</key>
        <array>
            <string>/Users/MYUSER/Scripts/backup.sh</string>
        </array>
        
    	<key>StartCalendarInterval</key>
        <dict>
    		<key>Weekday</key>
    			<integer>1</integer>
    		<key>Hour</key>
    			<integer>16</integer>
    		<key>Minute</key>
    			<integer>10</integer>
    
    	</dict>
    	<key>UserName</key>
    	<string>MYUSER</string>		
    </dict>
    </plist>
    
     
  2. costabunny thread starter macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #2
    wow 144 views and no answers - u guys :)

    well I've not been sitting here waiting for an answer, but I have finally found the info needed on this site.

    its all about launchd and the way it kills all child processes started by a script its handling. In my case its killing off sendmail :(

    so adding a key telling not to do this was the answer:

    Code:
    	<key>AbandonProcessGroup</key>
    		<true/>
    
    Nows its running fine as well as sending my report :) Happy Bunny
     
  3. costabunny thread starter macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #3
    So next problem

    My script is working 100%. My launch agent is good except one little niggle.

    it runs the first backup at the time specified, but never seems to start again. I experimented with the keepalive option (dumb - kept launching the script again and again).

    If I unload the plist and reload it it will trigger at the next time instance set, then it won't the next day.

    Any ideas folks? This is driving me nuts. I just want the launch agent to trigger the backup script at a specified time (06:30) every day.

    permissions etc must be correct (else it wouldn't execute the first time).

    this is my LaunchAgent

    com.local.lokibackup.plist
    Code:
    <?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.local.lokibackup</string>
        
    	<key>ProgramArguments</key>
        	<array>
            	<string>/Users/myuser/Scripts/backup.sh</string>
        	</array>		
    	
    	<key>StandardOutPath</key>	
    		<string>/Users/myuser/Scripts/report.txt</string>
    	
    	<key>StandardErrorPath</key>
    		<string>/Users/myuser/Scripts/report.txt</string>    
    	
    	<key>StartCalendarInterval</key>
        	<dict>
    			<key>Minute</key>
    				<integer>06</integer>
    			<key>Hour</key>
    				<integer>30</integer>		
    		</dict>
    		
    	<key>AbandonProcessGroup</key>
    		<true/>
    </dict>
    </plist>
     
  4. costabunny thread starter macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #4
    well it was a silliest typo issue ever :(

    transposed the hours/minutes value.
     
  5. cerberusss macrumors 6502a

    cerberusss

    Joined:
    Aug 25, 2013
    Location:
    The Netherlands
    #5
    Wow, helpful stuff. Coming from the Linux side, I never took the time to really dig in and find out this side of launchd.

    By the way, for the logging you could write to /var/log/yourscriptname.log. Then it nicely gets compressed and rotated. You'd have to add the new log file its name to newsyslog.conf I guess.
     
  6. costabunny thread starter macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #6
    My script already logs to its own logs ;)

    the redirection of outputs in the plist is for the rsync output to a file that can be emailed as a summary :)
     
  7. iSaint macrumors 603

    iSaint

    Joined:
    May 26, 2004
    Location:
    South Mississippi y'all, near the water!
    #7
    Mail is not working at all after the Mavericks Mail update 1.0. Can you walk me through a layman's fix? Should I delete com.apple.mdworker.mail.plist
     
  8. costabunny thread starter macrumors 68020

    costabunny

    Joined:
    May 15, 2008
    Location:
    Weymouth, UK
    #8
    What do the logs say about mail?

    Better see whats going on before deleting the plist
     

Share This Page