Gnbd-cliente

De FJWiki
Saltar a: navegación, buscar

Este es un demonio RedHat/CentOS para montar los dispositivos GNBD que estuvieran configurados (o sea, automatiza la importanción inicial).

gnbd-cliente

#!/bin/bash
#
#
#
# chkconfig: 345 25 75
# description: export/import/whatever the gnbd block devices configured in /etc/gnbdtab
#
#
### BEGIN INIT INFO
# Provides:
### END INIT INFO

. /etc/init.d/functions

GNBD_SRV_TIMEOUT=5

start() {
        local GNBD

        if [ ! -f /etc/gnbdtab ] ; then
                echo "Please create /etc/gnbdtab"
                echo "Sample conf: /etc/gnbdtab"
                failure "Falta crear el archivo"
                echo
                return 1
        fi

        echo "Loading needed kernel modules for gnbd"
        modprobe gnbd
        rtrn=$?
        if [ $rtrn -ne 0 ]; then
                failure "Failed to load needed kernel modules for gnbd"
                echo
                return 1
        fi

        GNBD=`cat /etc/gnbdtab | egrep '^import'`
        if [ -n "$GNBD" ] ; then
                echo "Importing all GNBDs devices"
                echo "$(awk '/^import/ { print "--> server:", $2 }' /etc/gnbdtab )"
                cat /etc/gnbdtab | awk '/^import/ { print "-i", $2 }' | xargs -l gnbd_import ${GNBD_CLIENT_OPTS} > /dev/null
                rtrn=$?
                if [ $rtrn -ne 0 ]; then
                        failure "Failed to import gnbd devices"
                        echo
                        return 1
                fi
        fi
        echo "Buscando de nuevo volumenes (porsia)"
        vgscan
        clvmd -R
        vgchange -aly
        success "Iniciado"
        echo
        return 0
}

stop() {

        local GNBD_MONITOR_PROC

        echo "Desactivando Volume Group que usan gnbd"
        pvdisplay -C | awk '/^[ \t\f\n\r\v]*\/dev\/gnbd/ {print $2 }' | xargs -l vgchange -an

        echo "Unimporting all GNBDs devices"
        gnbd_import -q -R &> /dev/null
        rtrn=$?
        if [ $rtrn -ne 0 ]; then
                failure "Failed to unimport"
                echo "Failed to unimport"
                return 1
        fi

        GNBD_MONITOR_PROC="$(pgrep gnbd_monitor)"
        if [ -n "${GNBD_MONITOR_PROC}" ]; then
                echo "Stopping gnbd_monitor"
                killall gnbd_monitor &> /dev/null
                rtrn=$?
                if [ $rtrn -ne 0 ]; then
                        echo "Failed to stop gnbd_monitor"
                fi
        fi

        echo "Unloading gnbd kernel module"
        modprobe -r gnbd
        rtrn=$?
        if [ $rtrn -ne 0 ]; then
                failure "Failed to unload gnbd kernel module"
                echo
                return 1
        fi
        success "Finalizado"
        echo
        return 0
}

status() {
        gnbd_import -l
        rtrn=$?
        if [ $rtrn -ne 0 ]; then
                echo "No hay gnbd importados"
                return $rtrn
        fi
        return 0
}

case "$1" in
  start)
        start
        rtrn=$?
        ;;
  stop)
        stop
        rtrn=$?
        ;;
  status)
        status
        rtrn=$?
        ;;
  restart)
        stop
        start
        rtrn=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        ;;
esac

exit $rtrn