How to use upstart to control your services

In this first post I’ll be using the upstart configuration to easily manage a DLNA server in a Ubuntu desktop/server.

For starters I really don’t know exactly how DLNA works but it doesn’t matter, my TV and my Android do so that’s enough for me. I tried a bunch of DLNA servers, but the easiest one proved to be minidlna.

Upstart is a great tool to manage boot services (previously /etc/init.d/ !?) or to start/stop any service in a really simple and effective way.

For example starting a service will be as easy as writing in a terminal:

start dlna

So for starters you will need to install minidlna. Use Ubuntu software center to look for it or just type

sudo apt-get install minidlna

The only change I did to /etc/minidlna.conf was this one

media_dir=V,/home/myuser/Videos

Afterwords you need to create the file /etc/init/dlna.conf and type this into that file.

# rc - System V runlevel compatibility
#
# This task runs the minidlna service when filesystem and nic are availabe

description    "MiniDLNA controller"
author        "Nuno Mota <nrmmota@gmail.com>"

start on filesystem and net-device-up IFACE=eth0
stop on runlevel [!$RUNLEVEL]

expect fork
exec minidlna -f /etc/minidlna.conf

And that’s it. Whenever you boot your machine the service will be imediatly available. If for some reason the process dies, upstart will start it again. Everything is logged in syslog.