description "start/stop/control collectd"
# http://collectd.org/
# Upstart is the replacement init system used in Debian, Ubuntu,
# and in Fedora. Refer to http://upstart.ubuntu.com/cookbook/
#
# Normally this file will live as `/etc/init/collectd.conf`

usage "initctl <start|stop> collectd"
author "Dave Cottlehuber <dch@jsonified.com>"
version "1.1"

# There are a number of alternative start sequences however
# most of those do not work on all Ubuntu flavours and releases.
start on started networking and filesystem
stop on runlevel [!2345]

# collectd itself will run with reduced privileges, but not
# all plugins will. Test and edit as required.
# An alternative configuration is as a user script in ~/.init/ however
# these cannot be started at boot time by the system without
# arcane trickery. Also a root user will not see these tasks/jobs
# by default. set*id is a reasonable and secure compromise.
# These options are not supported on early upstart versions.
#setuid nobody
#setgid nobody

# Other parameters such as the path to the configuration file
# will have been compiled into the binary. These are trivially
# added as environment variables below, and then into both
# `pre-start` command check before collectd runs, and subsequent
# `exec` command parameters below. Remember that upstart runs all
# shell commands via `sh -e`.
env DAEMON=/usr/sbin/collectd

# Tell upstart to wait for collectd to SIGSTOP itself, signaling it is ready
# to run. Warning: this only works with collectd 5.5 and newer. You'll have to
# use "expect fork" instead, if using collectd 5.4 and older.
expect stop

# prevent thrashing - 10 restarts in 5 seconds
respawn
respawn limit 10 5

# Uncomment to make a log available in /var/log/upstart/collectd.log
# (not supported on early upstart versions).
#console log

# The daemon will not start if the configuration is invalid.
pre-start exec $DAEMON -t
# Let's start!
exec $DAEMON
