<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martian Thoughts on Design &#187; launchd</title>
	<atom:link href="http://blogs.martiangraphix.com/tag/launchd/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.martiangraphix.com</link>
	<description>Design, Web Development, and Interesting Technology</description>
	<lastBuildDate>Wed, 11 May 2011 03:32:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Automating Drupal cron with OS X’s launchd</title>
		<link>http://blogs.martiangraphix.com/2009/10/automating-drupal-cron-with-os-xs-launchd/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automating-drupal-cron-with-os-xs-launchd</link>
		<comments>http://blogs.martiangraphix.com/2009/10/automating-drupal-cron-with-os-xs-launchd/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 01:04:47 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Multi-Site]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Planet Drupal]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blogs.martiangraphix.com/?p=147</guid>
		<description><![CDATA[Found this great post on Configuring cron on Mac OS X Server 10.5.x in the Drupal documentation. I&#8217;d been wanting to do that with my original post on Building a Drupal Multi-Site development environment, but I hadn&#8217;t had time to figure it out. The title of the page at Drupal says &#8220;Mac OS X Server&#8220;, [...]]]></description>
			<content:encoded><![CDATA[<p>Found this great post on <a href="http://drupal.org/node/562904">Configuring cron on Mac OS X Server 10.5.x</a> in the Drupal documentation.  I&#8217;d been wanting to do that with my original post on <a href="http://blogs.martiangraphix.com/2009/09/building-a-drupal-development-environment-for-mac/">Building a Drupal Multi-Site development environment</a>, but I hadn&#8217;t had time to figure it out.</p>
<p>The title of the page at Drupal says &#8220;<strong>Mac OS X Server</strong>&#8220;, but there&#8217;s nothing that says you can&#8217;t use this technique on <strong>OS X Client</strong>, and I believe it will work on everything 10.4.x and up.</p>
<p>So I&#8217;m going to show you how to tie it into the Multi-Site setup I created on my local machine for the previous blog post.  <span id="more-147"></span>If you haven&#8217;t read that post, you might want to do so, because some of what we&#8217;re going to do here is specific to that installation.</p>
<p>Again, we&#8217;ll be using the <strong>Terminal</strong> a lot for this to make sure that everyone can play, with no special software necessary.</p>
<h3>Step 1: Remove the crontab Installation</h3>
<p>The first thing I&#8217;m going to do is remove the information that I put into the crontab previously.  Obviously, if you did not follow the procedure for creating a crontab file described in <strong>Step 10</strong> for building a Drupal Multi-Site development environment, then this step is not necessary.</p>
<p>The user crontab files are located in <em>/var/cron/tabs/</em>.  The first thing you need to do is make sure that the cronall statement that we put in earlier is the only thing in the file.  In your <strong>Terminal</strong> application do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>tabs<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p>If the only thing you see is the statement to execute http://drupal6.local/cronall.php, then it is safe to just delete this file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>tabs<span style="color: #000000; font-weight: bold;">/</span>www</pre></div></div>

<p>We&#8217;ll need to stop and start the cron process in order for our changes to take effect.  You can either restart your computer, or a better way is to just use Activity Monitor to quit the cron process.</p>
<ul>
<li>Open <strong>Finder</strong> and navigate into your <strong>Applications &gt; Utilities</strong> folder</li>
<li>Launch the <strong>Activity Monitor</strong></li>
<li>Select <strong>Administrator Processes</strong> in the pulldown at the top</li>
<li>In the <strong>Filter</strong> box at the top, type &#8220;<strong>cron</strong>&#8220;</li>
<li>Highlight the process and select <strong>Quit Process</strong> at the top</li>
<li>You should see the process go away, and come right back again with a new <strong>Process ID</strong></li>
</ul>
<p>If you saw additional commands in the file when you executed the cat command, then it&#8217;s probably best just to edit the crontab file and remove the lines related to Drupal.  If you need to do that then do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EDITOR</span>=<span style="color: #c20cb9; font-weight: bold;">nano</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> crontab <span style="color: #660033;">-u</span> www <span style="color: #660033;">-e</span></pre></div></div>

<p>Remove the line containing <strong>http://drupal6.local/cronall.php</strong>.</p>
<h3>Step 2: Create a plist file</h3>
<p>Again, we&#8217;re basically following the recommendations found in <a href="http://drupal.org/node/562904">Configuring cron on Mac OS X Server 10.5.x</a>, so if you want to tweek this installation, please read that article.  Now we need to create a launchd daemon .plist file.  We&#8217;ll call this file <em>drupal6.local-cronall.plist</em>, and place it in <em>/Library/LaunchDaemons/</em>.  Open your <strong>Terminal</strong> application and do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> drupal6.local-cronall.plist</pre></div></div>

<p>Enter the following into the file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span> 
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot;</span>
<span style="color: #00bbdd;">         &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>drupal6.local-cronall<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UserName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>nobody<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>GroupName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>www<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ProgramArguments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/bin/curl<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-s<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://drupal6.local/cronall.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>StartInterval<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3600<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Save the file.</p>
<p><strong><em>Important!!!</em></strong> Note that we changed the <strong>GroupName</strong> from _www as described in the documentation to simply <strong>www</strong>.  Not sure if this is a variation between the OS X Server and the Client version, or it could be a difference between 10.4 and 10.5+.  In any case, for me on 10.4.x Client, it wouldn&#8217;t work until I got this value correct.</p>
<p>As you can see, we&#8217;ve used the <strong>StartInterval</strong> approach described in the article.  I think this approach is more appropriate for our development environment, because it won&#8217;t care if you laptop or desktop is asleep at a specific time.</p>
<h3>Step 3: Start the process</h3>
<p>Ok, so now let&#8217;s load the agent into <strong>launchd</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> launchtl load <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>drupal6.local-cronall.plist</pre></div></div>

<p>When I ran this, I got an error about &#8220;<strong>Workaround Bonjour: &#8230;.</strong>&#8220;, but the script seems to be executing ok, so I think you can ignore it.</p>
<p>Now let&#8217;s do a little testing.</p>
<h3>Step 4: Testing</h3>
<p>There are a couple of ways to test out what we&#8217;ve just done.  The main thing is to open the Drupal status report (<a href="http://drupal6.local/admin/reports/status">http://drupal6.local/admin/reports/status</a>), and check how long it&#8217;s been since your cronall process ran.  If you want to alter the interval while testing, change StartInterval.  I used <strong>120</strong> to make the process run every 2 minutes.  To get your changes to take effect, do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> launchtl unload <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>drupal6.local-cronall.plist</pre></div></div>

<p>This is important, you don&#8217;t want to alter things in the .plist file until you unload it, or you&#8217;ll lose access to the service.  Now change the value of <strong>StartInterval</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>drupal6.local-cronall.plist</pre></div></div>

<p>And then restart the service:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> launchtl load <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>drupal6.local-cronall.plist</pre></div></div>

<p>Just make sure that you reset the <strong>StartInterval</strong> to something like <strong>3600</strong> (1 hr), so that your computer isn&#8217;t constantly banging on your network connection.</p>
<p>That&#8217;s it for this article.  I hope you&#8217;ve found it useful.  If you got into this article from <strong>Step 10</strong> of <a href="http://blogs.martiangraphix.com/2009/09/building-a-drupal-development-environment-for-mac/">Building a Drupal development environment for Mac</a>, then continue back to that article at <strong>Step 11</strong>.  </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.martiangraphix.com/2009/10/automating-drupal-cron-with-os-xs-launchd/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

