Gnbd-servidor
De FJWiki
Este demonio RedHat/CentOS exporta las particiones definidas para GNBD.
gnbd-servidor
#!/bin/bash
#
#
#
# chkconfig: 345 23 77
# 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
echo "Starting gnbd_serv"
/sbin/gnbd_serv -q
rtrn=$?
if [ $rtrn -ne 0 ]; then
failure "Failed to start gnbd_serv"
echo
return 1
fi
GNBD=`cat /etc/gnbdtab | egrep '^export'`
if [ -n "$GNBD" ] ; then
awk '/^export/ { print "--> device:", $4, "as", $3 }' /etc/gnbdtab
cat /etc/gnbdtab | awk '/^export/ { print "-d", $4, "-e", $3 }'| xargs -l gnbd_export ${GNBD_SRV_OPTS} > /dev/null
rtrn=$?
if [ $rtrn -ne 0 ]; then
failure "Failed to export gnbd devices"
echo
return 1
fi
fi
success "Iniciado"
echo
return 0
}
stop() {
local GNBD_SRV_PROCS GNBD_CLUSTERD_PROC
echo "Unexporting all GNBDs devices"
gnbd_export -q -R &> /dev/null
rtrn=$?
if [ $rtrn -ne 0 ]; then
failure "Failed to unexport all gnbd devices"
echo
return 1
fi
GNBD_SRV_PROCS="$(pgrep gnbd_serv)"
while [ -n "${GNBD_SRV_PROCS}" ] && [ ${GNBD_SRV_TIMEOUT} -gt 0 ] ; do
gnbd_serv -k &> /dev/null
sleep 1
GNBD_SRV_TIMEOUT=$(( ${GNBD_SRV_TIMEOUT}-1 ))
GNBD_SRV_PROCS="$(pgrep gnbd_serv)"
done
if [ -n "${GNBD_SRV_PROCS}" ]; then
gnbd_serv -K &> /dev/null
fi
rtrn=$?
if [ $rtrn -ne 0 ]; then
failure "Failed to stop gnbd_serv"
echo
return 1
fi
GNBD_CLUSTERD_PROC="$(pgrep gnbd_clusterd)"
if [ -n "${GNBD_CLUSTERD_PROC}" ]; then
echo "Stopping gnbd_clusterd"
killall gnbd_clusterd &> /dev/null
rtrn=$?
if [ $rtrn -ne 0 ]; then
echo "Failed to stop gnbd_clusterd"
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_export -l
rtrn=$?
if [ $rtrn -ne 0 ]; then
echo "No hay exportados"
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