source: trunk/packages/invirt-xen-config/debian/invirt-xen-config.init @ 1462

Last change on this file since 1462 was 1462, checked in by broder, 16 years ago

Add some additional documentation on how the sysvm disk locking works

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/bash
2### BEGIN INIT INFO
3# Provides:          invirt-xen-config
4# Required-Start:    $local_fs $remote_fs
5# Required-Stop:     $local_fs $remote_fs
6# Default-Start:     2 3 4 5
7# Default-Stop:      0 1 6
8# Short-Description: Startup script for the Invirt Xen host
9# Description:       
10### END INIT INFO
11
12PACKAGE=invirt-xen-config
13NAME="$PACKAGE"
14DESC="Invirt Xen host"
15PARENTPACKAGE=xend
16GEN_FILES=(/etc/xen/xend-config.sxp.invirt)
17SYSVMS=(s_master s_remote s_console)
18i=1
19for vm in "${SYSVMS[@]}"; do
20    GEN_FILES[$i]="/etc/xen/sysvms/$vm"
21    i=$((i + 1))
22done
23
24dpkg -s "$PACKAGE" >/dev/null 2>/dev/null || exit 0
25
26. /lib/init/gen-files.sh
27. /lib/init/std-init.sh
28
29start_sysvm() {
30    # Attempt to start a sysvm, but only if it's not running already
31    # somewhere on the cluster
32   
33    VM="$1"
34    DISK="/dev/xenvg/${VM}_hda"
35   
36    # Don't bother trying to start the VM if it's already running
37    if xm list "$1" >/dev/null 2>&1; then
38        return 1
39    fi
40   
41    if lvchange -a n "$DISK" >/dev/null 2>&1 && lvchange -a ey "$DISK" >/dev/null 2>&1; then
42        # If we can disable and then re-enable the VMs disk, then the
43        # VM can't be running. If the lvchange -a ey succeeds, then we
44        # have an exclusive lock across the cluster on enabling the
45        # disk, which avoids the potential race condition of two hosts
46        # starting a VM at the same time
47        [ "$VERBOSE" != no ] && log_daemon_msg "Starting sysvm $VM"
48        xm create "sysvms/$VM" >/dev/null
49        [ "$VERBOSE" != no ] && log_end_msg $?
50        RET=0
51    else
52        RET=1
53    fi
54   
55    # Regardless of whether we could get the lock or not, the
56    # lvchange -a n probably disabled the LV somewhere; be sure we
57    # clean up
58    lvchange -a y "$DISK" >/dev/null 2>&1
59   
60    return $RET
61}
62
63do_startup() {
64    gen_files
65   
66    for vm in "${SYSVMS[@]}"; do
67        start_sysvm "$vm"
68    done
69   
70    echo 1 >/proc/sys/net/ipv4/ip_forward
71    for i in all default; do
72        echo 1 >/proc/sys/net/ipv4/conf/$i/rp_filter
73        echo 1 >/proc/sys/net/ipv4/conf/$i/proxy_arp
74    done
75   
76    invoke-rc.d "$PARENTPACKAGE" "$1"
77}
78
79do_start() {
80    do_startup "start"
81}
82
83do_reload() {
84    do_startup "reload"
85}
86
87do_stop() {
88    invoke-rc.d "$PARENTPACKAGE" stop
89}
90
91std_init "$1"
Note: See TracBrowser for help on using the repository browser.