source: lliurex-rpi-packages/trunk/fuentes/ldm/ltsp/nbd-disconnect @ 2328

Last change on this file since 2328 was 2328, checked in by kbut, 3 years ago

add new package

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/bin/sh
2# Tries to work around LP bug #696454, i.e. that if the root /dev/nbd0 device
3# is unmounted on shutdown then nbd read errors occur, and if it isn't, then
4# the nbd-server process on the server doesn't terminate.
5# Called by init scripts on reboot or shutdown.
6
7case "$RUNLEVEL" in
8    0)
9        key="o"
10        message="Shutting down NOW."
11        ;;
12    6)
13        key="b"
14        message="Rebooting NOW."
15        ;;
16    *)
17        echo "nbd-disconnect should only be called by initscripts on reboot/shutdown." >&2
18        exit 1
19        ;;
20esac
21
22disconnect() {
23    echo "$message" >&2
24    nbd-client -d /dev/nbd0
25    echo $key > /proc/sysrq-trigger
26}
27
28# Disconnect swap nbd devices first
29while read device etc; do
30    case "$device" in
31        /dev/nbd[1-9])
32            swapoff "$device"
33            nbd-client -d "$device"
34            ;;
35    esac
36done < /proc/swaps
37
38# If we're not using an nbd root, exit
39grep -qw "nbdroot" /proc/cmdline || exit 0
40
41trap "disconnect" 0 HUP INT QUIT KILL SEGV PIPE TERM
42sync
43# Give up to 5 seconds for other services to be called.
44# If they finish before that time, process termination will start, and the trap
45# will be called.
46sleep 5
Note: See TracBrowser for help on using the repository browser.