Logo Search packages:      
Sourcecode: nbd version File versions  Download package

nbd-client.init.d

#! /bin/bash
# We use some bashisms (arrays), so /bin/sh won't work.
# I hope this is policy-compliant; I couldn't find anything different,
# but if so, I'm gonna need help here to find a better way of handling
# this.
#
# skeleton  example file to build /etc/init.d/ scripts.
#           This file should be used to construct scripts for /etc/init.d.
#
#           Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#           Modified for Debian GNU/Linux
#           by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#           Modified for the nbd-client package
#           by Wouter Verhelst <wouter@debian.org>
#
# Version:  @(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#TODO: find a better way to figure out what nbd-devices need to be
#disconnected (the for-loop works, but the kernel does
#printk("NBD_DISCONNECT") after each request).

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/sbin/nbd-client"
NAME="nbd-client"
DESC="NBD client process"

test -f /etc/nbd-client && . /etc/nbd-client

test -x $DAEMON || exit 0

case "$1" in
    connect)
      # I don't use start-stop-daemon: nbd-client only does some setup
      # for the connection; the 'nbd-client' you see in your ps output
      # later on is a kernel thread...
      modprobe -k nbd
      echo -n 'Connecting...'
      i=0
      while [ ! -z ${NBD_DEVICE[$i]} ]
        do
        $DAEMON ${NBD_HOST[$i]} ${NBD_PORT[$i]} ${NBD_DEVICE[$i]}
        echo "connected ${NBD_DEVICE[$i]}"
        i=`expr $i + 1`
      done
      ;;
    start)
      echo -n "Starting $DESC: "
      $0 connect
      $0 activate
      ;;
    activate)
      echo 'Activating...'
      i=0
      while [ ! -z ${NBD_DEVICE[$i]} ]
        do
        case ${NBD_TYPE[$i]} in
            "s")
              /sbin/swapon ${NBD_DEVICE[$i]}
              echo "${NBD_DEVICE[$i]}: swap activated."
              ;;
            "f")
              spinner="-C"
              case "$TERM" in
                dumb|network|unknown|"") spinner="" ;;
              esac
              /sbin/fsck $spinner -a ${NBD_DEVICE[$i]}
              if [ $? -lt 2 ]
                  then
                  /bin/mount ${NBD_DEVICE[$i]}
                  echo "${NBD_DEVICE[$i]}: filesystem mounted."
              else
                  echo "fsck of ${NBD_DEVICE[$i]} failed. Not mounting."
              fi
              ;;
            "r")
              # Nothing needs to be done
              echo "${NBD_DEVICE[$i]}: raw selected. doing nothing."
              ;;
            *)
              echo "Error: NBD_TYPE[$i] contains unknown value ${NBD_TYPE[$i]}"
              ;;
        esac
        i=`expr $i + 1`
      done
      echo "$NAME."
      ;;
    stop)
      echo "Stopping $DESC: "
      # We want to make sure that *all* nbd-client processes are
      # stopped.
      echo "umounting all filesystems for nbd-blockdevices..."
      for i in `mount | cut -d " " -f 1 | grep nb`
        do
        umount $i 2>/dev/null
        if [ $? -eq 1 ]
            then
            echo -n "umount of $i failed! Data loss may occur! will continue in 10 seconds..."
            sleep 1
            for i in 9 8 7 6 5 4 3 2 1
            do
            echo -n $i" "
            sleep 1
            done
            echo "ok, going on..."
        fi
        echo $i
      done
      if [ -d /dev/nbd ]
          then
          echo "Invoking swapoff on all files in /dev/nbd..."
          swapoff /dev/nbd/* 2>/dev/null
          echo "Disconnecting $DESCes..."
          for i in /dev/nbd/*
            do
            $DAEMON -d $i 2>/dev/null >/dev/null
          done
      else
          echo "Invoking swapoff on all 'nb*' files in /dev..."
          swapoff /dev/nb* 2>/dev/null
          echo "Disconnecting $DESCes..."
          for i in /dev/nb*
            do
            $DAEMON -d $i
          done
      fi
      rmmod nbd
      echo "$NAME."
      ;;
    restart|force-reload)
      if dpkg --compare-versions "$(uname -r)" gt "2.4"
      then
            $0 stop
            sleep 10
            $0 start
      else
            echo "Need 2.4-kernel for disconnect. As such, restart won't work"
            echo "Either upgrade to a 2.4-kernel, or use $0 stop, restart the server,"
            echo "and do $0 start."
      fi
      ;;
    *)
      N=/etc/init.d/$NAME
      echo "Usage: $N {start|connect|stop|restart|force-reload|activate}" >&2
      exit 1
      ;;
esac

exit 0

Generated by  Doxygen 1.6.0   Back to index