Running ezstream as a startup service with Upstart

This is a method to run an ezstream icecast2 audio stream as a startup service within a Upstart init system. This method will also work for anything else which needs to run as a service.

I assume you have icecast2 installed and functioning:

Create a configuration file for ezstream in /etc/icecast2/ or in a project specific directory:

    <svrinfoname>Example Stream</svrinfoname>
    <svrinfodescription>Example Stream</svrinfodescription>

Then create an Upstart service startup script for the stream in /etc/init/ezstream-PROJECT.conf:

description "ezstream service for YOUR PROJECT"
author "YOUR NAME"

# Start the service on runlevel 2/3/4/5
start on runlevel [2345]

# Stop the service on runlevel 0/1/6
stop on runlevel [016]

	# Loop and wait for icecast2 to open port 8000. Change if you are using a different port.
	until nc -z localhost 8000; do
		echo "Waiting for icecast2 to start"
		sleep 1
	# Start the ezstream instance with a unique name so multiple instances can be run.
	exec start-stop-daemon --start --name UNIQUE_SERVICE_NAME --exec /usr/bin/ezstream -- -c /PATH/TO/EZSTREAM/CONFIG.cfg
end script

More Upstart service configuration options here: Upstart Intro, Cookbook and Best Practises