title: how to daemonize a php script to be run with upstart
body: <p>I have a PHP script that has been running as a cron job.   The script uses the DB to see if it has anything to do, and to make sure its brethren are not already running.</p>
  
  <p>I'd like to run the PHP script as a daemon with <a href="http://upstart.ubuntu.com/getting-started.html" rel="nofollow">upstart</a>.</p>
  
  <p>I've set up my <code>/etc/init/super-mailer.conf</code> file as this:</p>
  
  <pre><code>description "super mailer"
  author "Rob Nugen"
  
  start on startup
  stop on shutdown
  respawn
  
  exec sudo -u www-data php -f /var/www/super-mailer/scripts/mailer.php
  </code></pre>
  
  <p>I execute <code>sudo start super-mailer</code> and it runs once.</p>
  
  <p>It doesn't run again, though.   Why not?</p>
  
  <p>I've also tried replacing the <code>exec sudo</code> line with</p>
  
  <pre><code>script
      sudo -u www-data php -f /var/www/clubberia-mailer/scripts/mailer.php
  end script
  </code></pre>
  
  <p>Do I need to change my PHP script to loop?  How do I tell upstart to keep starting the script?</p>