# Upstart

August 29th, 2013

At work I’ve been tasked with converting a cronjob to run on Ubuntu’s excellent Upstart system. I have to say, Upstart is freaking awesome for someone who’s worked with Node’s event system or anything in Java that has Listener as part of the name.

## Creating a job

Creating a job is as simple as placing a configuration file in /etc/init.

#### sample1.conf

start on startup

script
/path/to/important/script.sh
end script

Instead of making your workflow into one massive job, split it into separate files and make them listen for each other. For example, suppose you want to prepare some data from a database (convert it, perhaps) and then upload it to a server:

#### prepare-data.conf

task
script
/script/to/prepare/data.sh
initctl emit data-prepared
end script

start on data-prepared
script
end script

This way, you can fire off a series of events and not have to worry.

Our configuration requires that one server be able to touch off events on another. To do this, we’re using “signal files” so one server SSHes in and touches the signal file on the other. Upstart makes this easy too:

#### on-server-1.conf

task
script
my-action.sh
ssh server-2 "touch /path/to/notify/job-1-done"
end