#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

: ${configfile:=/etc/c-icap/c-icap.conf}

get_config() {
    local value=$(awk '$1 == "'$1'" { print $2 }' ${configfile})
    echo ${value:-$2}
}

command="/usr/libexec/c-icap"
command_arguments="${EXTRA_OPTS} -f ${configfile}"
pidfile=$(get_config PidFile /var/run/c-icap/c-icap.pid)

depend() {
	need localmount
	config ${configfile}
	[ "$(get_config Logger file_logger)" = "sys_logger" ] && use logger
}

start_pre() {
	local cmdsocket=$(get_config CommandsSocket /var/run/c-icap/c-icap.ctl)

	checkpath -d "$(dirname "${cmdsocket}")" "$(dirname "${pidfile}")"
}
