#!/usr/bin/env /lib/init/init-d-script
### BEGIN INIT INFO
# Provides:          {{ name }}
# Should-Start:      $syslog
# Required-Start:    $time $local_fs
# Required-Stop:     $time $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: {{ description }}
### END INIT INFO
NAME='{{ name }}'
DESC='{{ description }}'
DAEMON='/usr/sbin/{{ name }}'

if ! test -x '/usr/bin/daemon' ; then
	log_failure_msg "install \`daemon' package to use ${NAME} script"
	exit 1
fi
if ! test -x '/usr/bin/chpst' ; then
	log_failure_msg "install \`runit' package to use ${NAME} script"
	exit 1
fi

daemon_ () { /usr/bin/daemon -D "/etc/sv/${NAME}" --noconfig --name "${NAME}" "$@"; }
do_start_cmd_override () { daemon_ -- /usr/bin/chpst -e conf /bin/sh ./run; }
do_stop_cmd_override () {
	if daemon_ --running ; then
		daemon_ --stop
	fi
}
