#!/bin/sh #------------------------------------------------------------------------------ # OPT_RRDTOOL /etc/rc.d/rc900.rrdtool __FLI4LVER__ # Creation: bastard # Last Update: $Id$ #------------------------------------------------------------------------------ case $OPT_RRDTOOL in yes) begin_script RRDTOOL "starting rrdtool..." # apply default values if nessesary [ -z "$RRDTOOL_WWW_PATH" ] && local RRDTOOL_WWW_PATH='/srv/www/admin' [ -z "$RRDTOOL_LOG_PATH" ] && local RRDTOOL_LOG_PATH='/dev/null' [ -z "$RRDTOOL_DB_PATH" ] && local RRDTOOL_DB_PATH='/var/db/rrdtool' [ -z "$RRDTOOL_CACHE_PATH" ] && local RRDTOOL_CACHE_PATH='/var/cache/rrdtool' [ -z "$RRDTOOL_GRAPH_WIDTH" ] && local RRDTOOL_GRAPH_WIDTH=600 [ -z "$RRDTOOL_DATE_FMT" ] && local RRDTOOL_DATE_FMT='+%Y-%m-%d %H\:%M\:%S' [ -z "$RRDTOOL_VALUE_INTERVAL" ] && local RRDTOOL_VALUE_INTERVAL=1 [ -z "$RRDTOOL_GRAPH_INTERVAL" ] && local RRDTOOL_GRAPH_INTERVAL=15 [ -z "$RRDTOOL_RENDERING_SPEED" ] && local RRDTOOL_RENDERING_SPEED=1 [ -z "$RRDTOOL_TIME_RANGES" ] && local RRDTOOL_TIME_RANGES='e-3h e-24h e-1w e-1m e-1y' # check for trailing slashes and remove them if there for curPath in RRDTOOL_WWW_PATH RRDTOOL_LOG_PATH RRDTOOL_DB_PATH RRDTOOL_CACHE_PATH RRDTOOL_BACKUP_PATH; do eval $curPath'='`eval echo \\$$curPath | sed -r 's;^(/?([^/]+/)*[^/]+)/?$;\1;'` done # define config file local confFile=/var/run/rrdtool.conf # define error log file case "$RRDTOOL_LOG_PATH" in /dev/*) RRDTOOL_LOG_FILE="$RRDTOOL_LOG_PATH" ;; *) RRDTOOL_LOG_FILE="$RRDTOOL_LOG_PATH/rrdtool.log" ;; esac if [ ! -e /var/run/webgui/language.conf ]; then mkdir -p /var/run/webgui echo "$HTTPD_GUI_LANG" > /var/run/webgui/language.conf fi # store variables needed later for graph rendering { echo "#!/bin/sh" echo "RRDTOOL_CONF_LOADED='yes'" echo "RRDTOOL_HTTPD_GUI_LANG=\"\`cat /var/run/webgui/language.conf\`\"" set | grep '^RRDTOOL_[^0-9]' set | grep '^RRDTOOL_[0-9]' } > $confFile # create db folder mkdir -p "$RRDTOOL_DB_PATH" # create cache folder mkdir -p "$RRDTOOL_CACHE_PATH" rrdtool_services="" rm -r /etc/rrdtool/schedule_* > /dev/null 2>&1 if [ -n "$RRDTOOL_BACKUP_PATH" ]; then if ! echo "$RRDTOOL_BACKUP_PATH"|grep -q "\(`echo \`sed -e '/ \(devpts\|bdev\|proc\|\(tmp\|sock\|pipe\|ram\|sys\|usb\(dev\|\)\|root\|capi\)fs\) /d' /proc/mounts|cut -d\ -f2\`|sed -e 's/ \//\\\|\//g'`\)"; then log_error "ERROR: RRDTOOL_BACKUP_PATH is in the RAM-disk, aborting backup" for i in `seq 1 10`; do do_beep sleep 1 done else mkdir -p "$RRDTOOL_BACKUP_PATH" if [ -n "$RRDTOOL_BACKUP_INTERVAL" ]; then rrdtool_services="$rrdtool_services schedule_backup" ln -s /etc/rrdtool/rrdtool_backup /etc/rrdtool/schedule_backup fi echo ". /etc/rrdtool/rrdtool_backup" >/etc/rc0.d/rc495.rrdtool fi fi # for each defined source ... [ 0"$RRDTOOL_N" -eq 0 ] || for idx in `seq 1 "$RRDTOOL_N"` do eval source='$RRDTOOL_'$idx'_SOURCE' eval options='$RRDTOOL_'$idx'_OPTIONS_N' local source_options_str= [ "$options" -eq 0 ] || for idy in `seq 1 $options` do eval option='$RRDTOOL_'${idx}'_OPTIONS_'${idy} source_options_str="$source_options_str $option" done # remove spaces from $source_options_str source_options_str=`echo $source_options_str` { echo "RRDTOOL_${idx}_OPTIONS_STRING='$source_options_str'" # ERROR ERROR ERROR # ----------------- # if use the same source more than once the next line is not a uniq # var in the $confFile # echo "RRDTOOL_${source}_ID='$idx'" } >> $confFile # create folders: image storage and linkage and db mkdir -p "$RRDTOOL_DB_PATH/$source" mkdir -p "$RRDTOOL_CACHE_PATH/$source" mkdir -p "$RRDTOOL_WWW_PATH/$source" # restore backups if [ -n "`ls "$RRDTOOL_BACKUP_PATH/$source"/*.rrd 2>/dev/null`" ] then cp -R "$RRDTOOL_BACKUP_PATH"/* "$RRDTOOL_DB_PATH" fi # create rrd if neccesary sh $shell_dbg_opt /etc/rrdtool/$source.rrd $source_options_str # appand task to value collection interval if [ "$RRDTOOL_VALUE_INTERVAL" -gt 0 ] then [ ! -f /etc/rrdtool/schedule_value.unsort ] && rrdtool_services="$rrdtool_services schedule_value" echo "/etc/rrdtool/$source.val" >> /etc/rrdtool/schedule_value.unsort fi # appand task to graph rendering interval if [ "$RRDTOOL_GRAPH_INTERVAL" -gt 0 ] then [ ! -f /etc/rrdtool/schedule_graph.unsort ] && rrdtool_services="$rrdtool_services schedule_graph" echo "/etc/rrdtool/$source.graph" >> /etc/rrdtool/schedule_graph.unsort else echo "/etc/rrdtool/$source.graph" >> /etc/rrdtool/schedule_graph_no fi done # sort /etc/rrdtool/schedule_* for uniq entries if [ -f /etc/rrdtool/schedule_value.unsort ] then sort -u /etc/rrdtool/schedule_value.unsort > /etc/rrdtool/schedule_value fi if [ -f /etc/rrdtool/schedule_graph.unsort ] then sort -u /etc/rrdtool/schedule_graph.unsort > /etc/rrdtool/schedule_graph fi # generate parameters for graph rendering echo "creating cached graph rendering data" sh $shell_dbg_opt /etc/rrdtool/rrdtool-generator echo "finished creating cached graph rendering data" # start schedules for i in $rrdtool_services; do log_info "starting rrdtool-scheduler for $i" /usr/bin/service-restart.sh 20 /etc/rrdtool/rrdtool_scheduler $i >> $RRDTOOL_LOG_FILE 2>&1 & done # add menu item to webinterface [ "$OPT_HTTPD" == "yes" ] && httpd-menu.sh add -p 600 "rrdtool.cgi" "RRDtool" "" rrdtool end_script ;; esac