diff --git a/dns/knot-resolver/files/kresd.in b/dns/knot-resolver/files/kresd.in index 1aa44de36514..2ae112756ba8 100644 --- a/dns/knot-resolver/files/kresd.in +++ b/dns/knot-resolver/files/kresd.in @@ -20,16 +20,56 @@ rcvar=kresd_enable load_rc_config ${name} -# set defaults - kresd_enable=${kresd_enable:-"NO"} -kresd_config=${kresd_config:-"%%ETCDIR%%/${name}.conf"} +kresd_config=${kresd_config:-"/usr/local/etc/knot-resolver/${name}.conf"} +kresd_rundir="/var/run/kresd" -pidfile="%%RUNDIR%%/${name}.pid" -procname="%%PREFIX%%/sbin/${name}" +pidfile="/var/run/kresd/${name}.pid" +procname="/usr/local/sbin/${name}" required_files="${kresd_config}" +kuser=${name} +kgroup=$name} + +restart_cmd="${name}_restart" +start_cmd="${name}_start" +stop_cmd="${name}_stop" command="/usr/sbin/daemon" -command_args="-c -f -S -r -P ${pidfile} -- ${procname} -c ${kresd_config} -n -q %%RUNDIR%%" +command_args="-c -f -S -r -P ${pidfile} -- ${procname} -c ${kresd_config} -n -q ${kresd_rundir}" + +kresd_restart() { + if [ -f "${pidfile}" ]; then + printf "restarting ${name}...\n\n" + run_rc_command stop + run_rc_command start + else + printf "Hmm... ${name} isn't running.\n\n" + run_rc_command start + fi +} +kresd_start() +{ + if [ ! -d /var/run/${name} ]; then + install -d -o ${kuser} -g ${kgroup} /var/run/${name} + elif [ ! -f "${pidfile}" ]; then + echo "starting ${name}..." && \ + ${command} ${command_args} + printf "\n${name} started.\n" + else + echo "Nothing to do. ${name} is already running." + fi +} +kresd_stop() { + if [ -f "${pidfile}" ]; then + echo "stopping ${name}..." && \ + for pid in `ps waux | grep ${name} | grep daemon | awk '{print $2}'`; \ + do \ + kill -TERM $pid + printf "\n${name} stopped.\n\n" + done + else + echo "Nothing to do. ${name} isn't running." + fi +} run_rc_command "$1"