Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Trouble with launchd

Trouble with launchd
Thread Tools
l008com
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Jan 9, 2010, 05:03 AM
 
I have a bunch of crons that i'm trying to switch over to launchd like a good boy. But so far, it's not working so great. This command works fine from the CLI but not as a launchd. I run with sudo on the CLI, but the launchd is supposed to run as root anyway. It's in /Library/LaunchDeamons
Here's the xml:

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>net.macfixer.FirewallReset</string> <key>ProgramArguments</key> <array> <string>/sbin/ipfw</string> <string>delete</string> <string>set</string> <string>17</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>3</integer> <key>Minute</key> <integer>1</integer> </dict> </dict> </plist>
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jan 9, 2010, 05:49 AM
 
Is there anything being printed to your console? Is it being recognized in your launchctl list?
     
Art Vandelay
Professional Poster
Join Date: Sep 2002
Location: New York, NY
Status: Offline
Reply With Quote
Jan 9, 2010, 01:19 PM
 
You could try using lingon to create your launchd plists. It's a gui assistant that helps you create the plists.

Lingon | Get Lingon at SourceForge.net
Vandelay Industries
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Jan 10, 2010, 01:39 AM
 
I don't know if there is anything being printed to my console, i'll have to see.

I did use Lingon to create this plist. Doesn't seem to be working though.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Jan 10, 2010, 04:25 AM
 
So I put my firewall command in a script, and had launchd call that script instead of running the command itself, and it worked. Seems odd but oh well, works now.

But I have more launchd questions. Next question is, how do I get a script to run at different times. Like say I wanted something to run at 2am, 4am and 6am, every day. In Cron, i'd just put "2,4,6" as the hour value. But it doesn't look like you can do that with a launchd.

Would I just put in multiple Hour keys? like so:
Code:
<key>Hour</key> <integer>2</integer> <key>Hour</key> <integer>4</integer> <key>Hour</key> <integer>6</integer>
Or is there some other way to do it?
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jan 10, 2010, 05:09 AM
 
Why are you wanting to do this with launchd anyway?

Cron is still supported, and would be a far more practical way to do this, I think. You could have your cronjob email you when/if your script fails too, and if you'd prefer to invoke your script after certain time intervals rather an absolute times of the day you can use anacron.

Launchd is basically a way to provide the functionality of something like Monit, does not require that developers write an init.d startup script for services, and provides the functionality of anacron. Because your script just runs and then immediately exits you don't need it be constantly monitored, and it doesn't need a script to invoke it. Hence, my question as to why this needs to be done with launchd?
     
Hal Itosis
Grizzled Veteran
Join Date: Mar 2004
Status: Offline
Reply With Quote
Jan 10, 2010, 11:33 PM
 
Originally Posted by l008com View Post
Next question is, how do I get a script to run at different times. Like say I wanted something to run at 2am, 4am and 6am, every day. In Cron, i'd just put "2,4,6" as the hour value. But it doesn't look like you can do that with a launchd.

Would I just put in multiple Hour keys? like so:
Code:
<key>Hour</key> <integer>2</integer> <key>Hour</key> <integer>4</integer> <key>Hour</key> <integer>6</integer>
Or is there some other way to do it?
This should work:
Code:
<key>StartCalendarInterval</key> <array> <dict> <key>Hour</key> <integer>2</integer> </dict> <dict> <key>Hour</key> <integer>4</integer> </dict> <dict> <key>Hour</key> <integer>6</integer> </dict> </array>
-HI-
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:43 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,