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

launchd
Thread Tools
l008com
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 19, 2010, 09:55 PM
 
I'm trying to make a launchdeamon that will run a script of mine, every 10 minutes, on the :00, :10, :20, :30, :40, :50
I tried using lingon but it doesn't let you get specific enough with the time interval fields. So I came up with this XML and entered it manually into the plist file. But, this is making it run every minute, instead of every 10 minutes.

Code:
<?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.johnmasone.coldmac</string> <key>ProgramArguments</key> <array> <string>/scripts/get_temps.php</string> </array> <key>StartCalendarInterval</key> <array> <dict> <key>Minute</key> <integer>0</integer> </dict> <dict> <key>Minute</key> <integer>10</integer> </dict> <dict> <key>Minute</key> <integer>20</integer> </dict> <dict> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Minute</key> <integer>40</integer> </dict> <dict> <key>Minute</key> <integer>50</integer> </dict> </array> </dict> </plist>
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 19, 2010, 10:01 PM
 
Just use cron and call it a day. Launchd is completely unnecessary for something this incredibly simple and straight forward.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 19, 2010, 10:02 PM
 
I thought cron was dead/dying?
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Dec 19, 2010, 10:12 PM
 
Cron might be a much better tool for this job, as launchd might end up trying to make up a whole bunch of missed tasks at once when you wake your Mac from sleep. I'm guessing you probably don't want that.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 19, 2010, 10:16 PM
 
Originally Posted by l008com View Post
I thought cron was dead/dying?

In the world of Linux/Unix/Posix OSes, definitely not, in the world of OS X I believe it still isn't.

Launchd was designed for a different purpose than cron. Launchd is basically init.d style startup scripts + something like Monit that ensures a process is constantly running + anacron/cron. In this case, you don't need anything but the scheduling, which is why I say it's complete overkill.

AFAIK Apple has no plans to discontinue cron, there is no reason to.
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Dec 19, 2010, 10:16 PM
 
Originally Posted by l008com View Post
I thought cron was dead/dying?
That’s what Apple wants you to believe. But i have to agree with besson3c on this one.

If you really want to abuse yourself and use launchd, at least use Lingon.

One word of warning: launchd doesn’t like short running scripts; it thinks they’re dying, so tries to relaunch them. Eventually, it concludes the “daemon” is defective and disables it.

cron just works.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 19, 2010, 10:18 PM
 
Originally Posted by CharlesS View Post
Cron might be a much better tool for this job, as launchd might end up trying to make up a whole bunch of missed tasks at once when you wake your Mac from sleep. I'm guessing you probably don't want that.

If you put your machine to sleep frequently I would suggest Anacron rather than Cron, actually. Anacron is based on time intervals rather than absolute times, but it won't queue up jobs like Charles is describing here. If a job is missed, a job is missed.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:16 AM
 
FYI my plan is for this particular machine to never sleep.
Anyway, I ditched the launchd and set up a cron (with cronnix) but that's not working either. The script runs fine when I tell it to "run now" but it doesn't run at all otherwise. Here's what I have:

Minute: 0,10,20,30,40,50
Hour: *
Day of the month: *
Month: *
Day of the week: *

Commands: ./scripts/get_temps.php
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:19 AM
 
With the path you have provided to your script it is going to execute relative to the owner of the cronjob. If that is you, then in this case the cronjob will expect the script to live in your home directory in a folder called "scripts". I suspect that Cronnix is creating the crontab as root. To avoid confusion, I would write out the absolute path to your script.

Check your console to see what error messages are being generated, and I'd suggest setting up your MTA if you haven't already so that errors are emailed to you if this script is mission critical and you'd like to be informed when it doesn't run properly.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:21 AM
 
I did write out the absolute path. It's in /scripts/get_temps.php
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:23 AM
 
ok i changed the command to "cd /scripts; ./get_temps.php" and now it's working
not sure why "./scripts/get_temps.php" wasn't working?
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:23 AM
 
Also like I said, when I chose "run now" in cronnix, it would run the script normally. It just wouldn't run by it's schedule. But now it is. Go figure.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:25 AM
 
Originally Posted by l008com View Post
ok i changed the command to "cd /scripts; ./get_temps.php" and now it's working
not sure why "./scripts/get_temps.php" wasn't working?

Because ./scripts is not an absolute path. The . means "relative to the current directory".
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Dec 20, 2010, 12:26 AM
 
Because ./scripts/get_temps.php starts with the current directory, since it has a dot in front. Just doing /scripts/get_temps.php probably would have worked.

edit: beaten by besson3c.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:27 AM
 
oh iiiii seeeeee. OK then everything is good. this may yet turn in to an interesting project
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:27 AM
 
Originally Posted by l008com View Post
Also like I said, when I chose "run now" in cronnix, it would run the script normally. It just wouldn't run by it's schedule. But now it is. Go figure.

Clicking on "run now" may have ran the script as you, whereas the cronjob was created belonging to root. You can list the cronjobs belonging to you:

crontab -l

belonging to root:

sudo crontab -u root -l
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:29 AM
 
You can also edit your cronjob via a:

crontab -e

You don't need to use Cronnix to do that, it's very simple once you are hip to the syntax and are comfortable with a Unix text editor.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:31 AM
 
I hate unix text editors I tolerate pico (nano), and despise the rest.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:35 AM
 
I was like you too, but learning one of vi or emacs is extremely useful. I've seen people who have mastered one or the other that can do things in a fraction of time it would take me to do the same sort of thing in another editor. Plus, when you are setting up a non OS X system from scratch chances are it won't include pico/nano by default, but vi instead. Vi is the default editor in many shells.

This may be your universe if Apple ever decides to can OS X Server
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 12:37 AM
 
When apple kills OS X Server, I'll take your suggestion under advisement. Meanwhile, I'm emailing BBEdit, suggesting to them, that they build an SSH client directly into the app. Then I can say goodbye forever, to the CLI text editor!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 12:43 AM
 
Originally Posted by l008com View Post
When apple kills OS X Server, I'll take your suggestion under advisement. Meanwhile, I'm emailing BBEdit, suggesting to them, that they build an SSH client directly into the app. Then I can say goodbye forever, to the CLI text editor!

You can use BBEdit with your remote files today via MacFUSE/SSHfs. I use TextMate (an OS X app) with all of my code which lives on a remote server with no problem.

However, I also can get around both emacs and vi. It is waaayyy faster to edit config files and make modifications this way through my shell, especially files that are owned by root, so TextMate is just used when I'm programming stuff.
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Dec 20, 2010, 01:08 AM
 
Originally Posted by l008com View Post
When apple kills OS X Server, I'll take your suggestion under advisement. Meanwhile, I'm emailing BBEdit, suggesting to them, that they build an SSH client directly into the app. Then I can say goodbye forever, to the CLI text editor!
TextWrangler has supported SSH for some time now, if you choose "Open from SFTP Server" in the File menu. Since TextWrangler is basically the "lite" version of BBEdit, I'd expect BBEdit to have that too.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 01:11 AM
 
It does have 'open sftp', how do I tell it to use ssh?
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 01:19 AM
 
Originally Posted by l008com View Post
It does have 'open sftp', how do I tell it to use ssh?

SFTP and SSH are the same thing.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 01:21 AM
 
I sure wish I knew that 5 years ago
All the fights I had with cli text editors! argh.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 01:31 AM
 
It wouldn't have helped much, you are only able to edit files you own this way.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 01:32 AM
 
So log into the server as root? And now you can save root-owned files. Just make sure a pet doesn't run across your keyboard. This will be very handy for me when editing apache config files.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 01:42 AM
 
I don't understand your question, what does it pertain to?

You aren't going to get much use out of TextWrangler or MacFUSE when it comes to editing Apache config files, as those are not owned by you, they are owned by the Apache user, and you do not want this same user to have a login shell.

Using any sort of Mac GUI is going to work best with files that you own, unless you want to manually change the permissions each time you want to edit a file.

My suggestion is to learn vi or emacs (or vim) for editing config files, it won't take you long to learn the basics, and it will be worthwhile in the long run particularly in the speed in which you can make changes to things. MacFUSE is great for editing websites and stuff that are comprised of files that you own.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 01:44 AM
 
l008com: if you don't mind me asking, do you have a disaster recovery plan for your server? What happens when a disk fails or data is lost? What happens if there is a disaster that hits the physical location where your server resides?

I ask because many servers lack a good plan, I'm constantly tweaking mine...
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 01:49 AM
 
FYI this thread was about an old 900 Mhz iBook I'm going to set up a project with, nothing to do with my real server...

For my real server, which lives in a datacenter, I have a script that runs once a week. It creates a compressed, encrypted disk image once a week, that contains a copy of all my web folders, all of my database dumps, and my mail server storage folder. Then when it's done making this, it moves it to the backup folder, and emails me a link to download is (password protected download). So once a week I get this link, and download a backup. They're only about 1.4 GB these days. So if I had to, i could set up all my sites up on my home folder, and host them here at home while I build a new xserve - or whatever.

And regarding drive failure, my boot drive is a mirrored raid and my backup drive is a single disk. So if one drive fails, I'd have my data center pop it out and ship it to me, and i'd ship them back a nice fresh one.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 01:56 AM
 
Cool...

Looks like you have done your due diligence beyond other setups I have seen. It sounds like you could be out a week's worth of changes if the data implodes and you haven't downloaded the backup (e.g. the machine won't sustain a network connection to complete your download, you're away on vacation, etc.), but if that doesn't make you shudder that sounds cool, and your home copy sounds like your offsite backup, so that's cool.

How many DNS servers do you have that are authoritative over your domains? If your primary DNS server went down, say because your server was just completely hosted, could you fail over to your home machine as you've described?

At my old job we actually had to practice these sort of disaster scenarios and failovers. The way this policy was enforced was a little silly, but still, I've heard too many stories about the shit hitting the fan and people being responsible for data being severely burned. It's no fun, I've lost some data in my days, it can be majorly stressful.

This was before the days of virtualization, virtualization is the savior of all sysadmins these days
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 03:05 AM
 
register.com handles all of my DNS. And actually, I had a day or two of intermittent downtime recently when register.com was hacked. But in the grand scheme of things, that doesn't matter.

As far as weekly backups, that's plenty for me. On an average week, I don't really create enough data, that losing it would ruin me. And I also bring my laptop with me on vacation, so even on vacation, weekly backups get downloaded

- I wrote this reply an hour ago, and just found this window buried on my screen, with this reply not yet posted, oops -
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 03:13 AM
 
Cool!

If you are ever interested in automating that backup, I can help
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 03:15 AM
 
It is automated. All I have to do is click a link in my email to download it.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2010, 03:34 AM
 
Originally Posted by l008com View Post
It is automated. All I have to do is click a link in my email to download it.

That's not fully automated

I meant have it automatically download to a machine/disk...
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Dec 20, 2010, 03:35 AM
 
Oh, yeah I don't really need or want that.
     
   
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 08:52 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.,