How to setup upstart: When Cron isn’t just enough

Reaching the limits of Cron

If you’re reading this blog post on account of the title, hopefully you already have a good understanding of what Cron is and you may well also be aware of some of it’s limitations. There are some situations when Cron use simply becomes impractical; the Cron minimum timeout of 1 minute can be prohibitively long to wait, rendering Cron an unhelpful tool for that particular project or situation.

In such moments I use Linux Upstart. It can run your code without a timeout at all or you can choose to set the timeout that you need.

Setting up Upstart

It’s very simple to set this up. To make a Symfony command I use daemonizable-command and write something like this:

Configuration

After that you’ll need to add an Upstart configuration file in Ubuntu.

The file extension should be “conf” eg,“project-task.conf”. Put the file into /etc/init/ or $HOME/.init/

You can find more configurations here.

Control

Now you can control your command like a Ubuntu service:
service <project-task> status/stop/start/restart

Bonus

And for more usability I’ve written a small task for checking the status of and restarting these Upstart tasks. This one’s run by cron 🙂

I hope this makes your life easier 😉