#!/sbin/runscript # Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ run_dir=${run_dir:-/run/rrdcached} pidfile=${run_dir}/${SVCNAME}.pid user=${user:-rrdcached} group=${group:-rrdcached} write_timeout=${write_timeout:-300} flush_timeout=${flush_timeout:-3600} write_threads=${write_threads:-4} journal_dir=${journal_dir:-"/var/lib/rrdcached/journal"} flush_when_shutdown=${flush_when_shutdown:-"yes"} output_dir=${output_dir:-"/var/lib/rrdcached/db"} restrict_to_output_dir=${restrict_to_output_dir:-"no"}; other_rrdcached_args=${other_rrdcached_args:-""} command="/usr/bin/rrdcached" command_args="${other_rrdcached_args} \ -p ${pidfile} \ -w ${write_timeout} \ -f ${flush_timeout} \ -t ${write_threads} \ -j ${journal_dir} \ -b ${output_dir}" start_stop_daemon_args="--quiet --user ${user}:${group}" description="RRDtool data caching daemon" depend() { need localmount net use logger } _eval_var() { local i=$1 eval " address=\${address${i}} gid=\${gid${i}:-"rrdcached"} mode=\${mode${i}:-"660"} commands=\${commands${i}:-""}" } _parse_confd() { if [ -n "${write_delay}" ]; then command_args="${command_args} -z ${write_delay}" fi if yesno "${flush_when_shutdown}" ; then command_args="${command_args} -F" fi if yesno "${restrict_to_output_dir}" ; then command_args="${command_args} -B" fi local idx=`set | grep address | awk -F "=" '{print $1}' | sed 's/address//'` for i in ${idx}; do _eval_var ${i} # set gid in start_post function command_args="-m ${mode} -P ${commands} -l ${address} ${command_args}" einfo " binding address: ${address}" einfo " group: ${gid}" einfo " mode: ${mode}" einfo " commands: ${commands}" done } start_pre() { checkpath -d -m 0755 -o "${user}":"${group}" "${run_dir}" if [ ! -f ${config_file} ]; then eerror "Missing configuration file ${config_file}" return 1 fi _parse_confd } start_post() { # if rrdcached run as non-privilege user # rrdcached: failed to set socket group permissions (Operation not permitted) local idx=`set | grep address | awk -F "=" '{print $1}' | sed 's/address//'` for i in ${idx}; do _eval_var ${i} if [[ "${address}" == unix:* ]] ; then local path=`echo ${address} | awk -F ":" '{print $2}'` ewaitfile 10 ${path} ret=$? [ $ret -eq 0 ] || return ${ret} chgrp ${gid} ${path} fi done }