|
|
launchd
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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>
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Just use cron and call it a day. Launchd is completely unnecessary for something this incredibly simple and straight forward.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
I thought cron was dead/dying?
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
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.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status:
Offline
|
|
Originally Posted by l008com
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by CharlesS
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
I did write out the absolute path. It's in /scripts/get_temps.php
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
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".
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
oh iiiii seeeeee. OK then everything is good. this may yet turn in to an interesting project
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
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
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
I hate unix text editors I tolerate pico (nano), and despise the rest.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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!
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
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.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally Posted by l008com
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.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
It does have 'open sftp', how do I tell it to use ssh?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
It does have 'open sftp', how do I tell it to use ssh?
SFTP and SSH are the same thing.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
I sure wish I knew that 5 years ago
All the fights I had with cli text editors! argh.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
It wouldn't have helped much, you are only able to edit files you own this way.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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...
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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 -
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Cool!
If you are ever interested in automating that backup, I can help
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
It is automated. All I have to do is click a link in my email to download it.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by l008com
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...
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
Oh, yeah I don't really need or want that.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|