Benutzer-Werkzeuge

Webseiten-Werkzeuge


Writing /srv/www/htdocs/udo/singollo.de/linux.singollo.de/public_html/data/cache/1/1d84a194e4811e81f2634eff2a78ff7e.metadata failed
mrtg

mrt automatisch starten

Ich nutze zur Serverüberwachung diverse Tools. Darunter ist auch mrtg, dass mir in meiner Konfiguration etwas über die Netzauslastung anzeigt. Leider kommt mrtg nicht mit einem passenden init-Script daher, so dass ich mir ein eigenes schreiben musste.

Neben der Konfiguration von mrtg benötigt man eine Konfigurationsdatei für das init-Script. Dort hinterlegt man die entsprechende mrtg-Konfiguration, lässt aber die Erweiterung „.cfg“ weg (kann natürlich auch eine andere sein, aber dann muss das Script auch noch angepasst werden).

/etc/sysconfig/mrtg

# Pfad zur Konfiguration (ohne .cfg)
MRTG_CONFIG="/etc/mrtg/foo"

Das Script reiht sich nach Apache, Netzwerk und syslog in die Startreihenfolge ein. Der Dienst time sollte gestartet werden, um die Daten in der RRD auch konsistent zu halten.

/etc/init.d/mrtg

#!/bin/sh                      
### BEGIN INIT INFO            
# Provides:          mrtg      
# Required-Start:    $syslog $network $apache
# Should-Start:      $time                   
# Required-Stop:                             
# Should-Stop:                               
# Default-Start:     3 5                     
# Default-Stop:      0 1 2 6                 
# Short-Description: mrtg daemon providing server statistics
# Description:       Start mrtg to monitoring your server
### END INIT INFO                                             
 
# Read config
. /etc/sysconfig/mrtg
 
# Check for existence of needed config file and read it
test -r "$MRTG_CONFIG.cfg" || { echo "$MRTG_CONFIG.cfg not existing";
        if [ "$1" = "stop" ]; then exit 0;                           
        else exit 6; fi; }                                           
 
# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance          
MRTG_BIN=/usr/bin/mrtg                                         
test -x $MRTG_BIN || { echo "$MRTG_BIN not installed";         
        if [ "$1" = "stop" ]; then exit 0;                     
        else exit 5; fi; }                                     
 
export LANG=C
MRTG="$MRTG_BIN --daemon $MRTG_CONFIG.cfg"
 
. /etc/rc.status
 
# Reset status of this service
rc_reset                      
 
# Return values acc. to LSB for all commands but status:
# 0       - success                                     
# 1       - generic or unspecified error                
# 2       - invalid or excess argument(s)               
# 3       - unimplemented feature (e.g. "reload")       
# 4       - user had insufficient privileges            
# 5       - program is not installed                    
# 6       - program is not configured                   
# 7       - program is not running                      
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
#                                                                
# Note that starting an already running service, stopping        
# or restarting a not-running service as well as the restart     
# with force-reload (in case signaling is not supported) are     
# considered a success.                                          
 
case "$1" in
    start)  
        echo -n "Starting mrtg "
        $MRTG 2>&1 1>/dev/null  
 
        # Remember status and be verbose
        rc_status -v                    
        ;;                              
    stop)                               
        echo -n "Shutting down mrtg "   
 
        /bin/kill `cat $MRTG_CONFIG.pid`
 
        # Remember status and be verbose
        rc_status -v                    
        ;;                              
    restart)                            
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start
 
        # Remember status and be quiet
        rc_status
        ;;
    force-reload)
        ## Signal the daemon to reload its config. Most daemons
        ## do this on signal 1 (SIGHUP).
        ## If it does not support it, restart the service if it
        ## is running.
 
        echo -n "Reload service mrtg "
        ## if it supports it:
        /sbin/killproc -HUP $MRTG_BIN
        #touch /var/run/mrtg.pid
        rc_status -v
 
        ## Otherwise:
        #$0 try-restart
        #rc_status
        ;;
    reload)
        ## Like force-reload, but if daemon does not support
        ## signaling, do nothing (!)
 
        # If it supports signaling:
        echo -n "Reload service mrtg "
        /sbin/killproc -HUP $MRTG_BIN
        #touch /var/run/mrtg.pid
        rc_status -v
 
        ## Otherwise if it does not support reload:
        #rc_failed 3
        #rc_status -v
        ;;
    status)
        echo -n "Checking for service mrtg "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.
 
        # Return value is slightly different for the status command:
        # 0 - service up and running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running (unused)
        # 4 - service status unknown :-(
        # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
 
        # NOTE: checkproc returns LSB compliant status values.
        /sbin/checkproc $MRTG_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit
mrtg.txt · Zuletzt geändert: 07.10.2012 18:31 (Externe Bearbeitung)