#!/bin/sh DAEMON=rrdstats DAEMON_LONG_NAME=RRDstats . /etc/init.d/modlibrc HTTPD_PID_RRD=/var/run/webcfg-rrd.pid HTTPD_PID_ONE=/var/run/webcfg-one.pid config() { for SUBDAEMON in rrd one; do modlib_config httpd-$SUBDAEMON /mod/etc/httpd-${SUBDAEMON}.conf done # kein "-p" wg externer Pfade! mkdir $RRDSTATS_RRDDATA 2>/dev/null mkdir $RRDSTATS_RRDTEMP 2>/dev/null rm /var/mod/etc/statpix 2>/dev/null ln -s $(echo "$RRDSTATS_RRDTEMP" | sed 's/\/*$//g') /var/mod/etc/statpix 2>/dev/null # show/hide digitemp modunreg status rrdstats rrddt modunreg file rrdstats [ -r /etc/options.cfg ] && . /etc/options.cfg if [ "$FREETZ_PACKAGE_RRDSTATS_DIGITEMP" == "y" -a "$RRDSTATS_DIGITEMP1W" = "yes" ]; then mkdir -p /tmp/.rrdstats/ rm -f /tmp/.rrdstats/digitemp_alert* modreg status rrdstats DigiTemp rrddt modreg file rrdstats dt-conf 'dt-conf' 0 "dt-conf" modreg file rrdstats dt-alias 'dt-alias' 1 "dt-alias" modreg file rrdstats dt-group 'dt-group' 1 "dt-group" modreg file rrdstats dt-alert 'dt-alert' 1 "dt-alert" fi } start() { [ "$RRDSTATS_SAVEBACKUP" = yes -a "$RRDSTATS_END_BACKUP" = no ] && backup [ "$RRDSTATS_START_RESTORE" = yes ] && restore silent stop_status modlib_startdaemon start-stop-daemon -S -b -q -m -p $PID_FILE -n $DAEMON -a rrdstats -- $RRDSTATS_INTERVAL if [ "$RRDSTATS_WEBENABLED" = "yes" -a "$RRDSTATS_WEB_INETD" != "yes" ]; then webcfg-rrd -P "$HTTPD_PID_RRD" fi if [ -x "$(which digitemp)" -a "$RRDSTATS_DIGITEMP_HTTP" = "yes" -a "$RRDSTATS_DIGITEMP_INETD" != "yes" ]; then webcfg-one -P "$HTTPD_PID_ONE" fi [ -x /mod/etc/init.d/rc.inetd ] && /mod/etc/init.d/rc.inetd config rrdstats modreg status rrdstats RRDstats stats } stop_pre() { stop_status } stop_post() { [ "$1" == 0 -a "$RRDSTATS_SAVEBACKUP" = yes -a "$RRDSTATS_END_BACKUP" = yes ] && backup silent } stop_status() { kill -9 "$(cat $HTTPD_PID_RRD 2>/dev/null)" 2>/dev/null kill -9 "$(cat $HTTPD_PID_ONE 2>/dev/null)" 2>/dev/null [ -x /mod/etc/init.d/rc.inetd ] && /mod/etc/init.d/rc.inetd config rrdstats >/dev/null modunreg status rrdstats rrddt modunreg status rrdstats stats } backup() { _TIMESTRING=$(echo $(date -Iseconds | sed 's/\:/-/g;s/\+.*//g;s/T/_/g')) _BACKUPNAME=$RRDSTATS_RRDBACKUP/$_TIMESTRING if [ $(ls $RRDSTATS_RRDDATA/*.rrd 2>/dev/null | wc -w) -le 0 ]; then [ "$1" != "silent" ] && echo "RRDstats " echo -n 'backup skipped, no files found ... ' [ "$1" != "silent" ] && echo return fi mkdir $RRDSTATS_RRDBACKUP 2>/dev/null mkdir $_BACKUPNAME 2>/dev/null cp -pP $RRDSTATS_RRDDATA/*.rrd $_BACKUPNAME/ 2>/dev/null exitval=$? if [ $exitval -ne 0 ]; then [ "$1" != "silent" ] && echo -n "Starting RRDstats ... not able to backup files, " echo "failed." exit $exitval fi _BACKUPLOG=$RRDSTATS_RRDBACKUP/backup.log echo $_TIMESTRING >> $_BACKUPLOG if [ "$RRDSTATS_DELBACKUP" = yes ]; then countbackup=$(cat $_BACKUPLOG | wc -l) countdelete=$(($countbackup-$RRDSTATS_MAXIMUMBACKUPS)) if [ $countdelete -gt 0 ]; then for delname in $(head $_BACKUPLOG -n $countdelete); do rm -rf $RRDSTATS_RRDBACKUP/$delname done tail $_BACKUPLOG -n $(($countbackup-$countdelete)) > $_BACKUPLOG.temp mv $_BACKUPLOG.temp $_BACKUPLOG fi fi } restore() { if kill -0 $(cat $PID_FILE 2>/dev/null) 2>/dev/null; then restart_rrdstats=yes modlib_stop fi [ "$1" != "silent" ] && echo -n 'RRDstats is restoring files ... ' if [ $(ls $RRDSTATS_RRDBACKUP/* 2>/dev/null | wc -w) -le 0 ]; then [ "$1" != "silent" ] || echo -n "Starting RRDstats ... " echo -n "no files to restore, failed." exit 1 fi [ ! -d "$RRDSTATS_RRDDATA" ] && mkdir -p $RRDSTATS_RRDDATA 2>/dev/null cp -pP $RRDSTATS_RRDBACKUP/$(echo $(tail -n1 $RRDSTATS_RRDBACKUP/backup.log))/*.rrd $RRDSTATS_RRDDATA/ 2>/dev/null exitval=$? if [ $exitval -ne 0 ]; then [ "$1" != "silent" ] || echo -n "Starting RRDstats ... not able to restore files, " echo "failed." exit $exitval else [ "$1" != "silent" ] && echo 'done.' fi [ "$restart_rrdstats" = yes ] && modlib_start } case $1 in config) config ;; ""|load) modlib_add_httpd_symlink rrd one modreg cgi rrdstats RRDstats modreg extra rrdstats "" 2 dt-init modreg daemon $DAEMON modlib_start $RRDSTATS_ENABLED ;; unload) modunreg daemon $DAEMON modunreg cgi rrdstats modunreg file rrdstats modunreg extra rrdstats modlib_stop ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; status) modlib_status ;; status_webcfg-one) [ -x "$(which digitemp)" -a "$RRDSTATS_DIGITEMP_HTTP" = "yes" -a "$RRDSTATS_DIGITEMP_INETD" = "yes" -a "$(modlib_status)" == "running" ] && echo 'inetd' || modlib_status ;; status_webcfg-rrd) [ "$RRDSTATS_WEBENABLED" = "yes" -a "$RRDSTATS_WEB_INETD" = "yes" -a "$(modlib_status)" == "running" ] && echo 'inetd' || modlib_status ;; backup) echo -n 'RRDstats is creating a backup of .rrd files ... ' backup silent echo "done." ;; restore) restore ;; graph) shift echo -n "RRDstats generating graph(s) ... " /usr/lib/cgi-bin/rrdstats/main.cgi $* >/dev/null 2>&1 echo "done." ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status|config|backup|restore]" 1>&2 echo " $0 graph [-graph=] [-group=] [-width=] [-period=] [-not-lazy]" 1>&2 exit 1 ;; esac exit 0