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

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

Fix the sysvm startup lock cleanup

  • Property svn:executable set to *
File size: 2.5 KB
RevLine 
[1275]1#!/bin/bash
[1257]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
[1261]12PACKAGE=invirt-xen-config
[1275]13NAME="$PACKAGE"
[1280]14DESC="Invirt Xen host"
[1261]15PARENTPACKAGE=xend
[1457]16SYSVMS=(s_master s_remote s_console)
[1471]17GEN_FILES=(/etc/xen/xend-config.sxp.invirt "${SYSVMS[@]/#//etc/xen/sysvms/}")
[1257]18
[1261]19dpkg -s "$PACKAGE" >/dev/null 2>/dev/null || exit 0
20
21. /lib/init/gen-files.sh
22. /lib/init/std-init.sh
23
[1457]24start_sysvm() {
25    # Attempt to start a sysvm, but only if it's not running already
26    # somewhere on the cluster
27   
28    VM="$1"
[1580]29    LV="${VM}_hda"
30    DISK="/dev/xenvg/$LV"
[1457]31   
32    # Don't bother trying to start the VM if it's already running
[1580]33    if xm list "$VM" >/dev/null 2>&1; then
[1457]34        return 1
35    fi
36   
[1580]37    RET=1
38    # To keep multiple hosts from trying to start a VM at the same
39    # time, lock VM creation at startup-time with a lock LV, since LV
40    # creation is atomic
41    if lvcreate -L 1K -n "lock_${LV}" xenvg >/dev/null 2>&1; then
42        # If we can disable the LV, then the VM isn't already running
43        # somewhere else
44        if lvchange -a n "$DISK" >/dev/null 2>&1; then
45            lvchange -a y "$DISK" >/dev/null 2>&1
46           
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        fi
52       
53        # Regardless of whether we could get the lock or not, the
54        # lvchange -a n probably disabled the LV somewhere; be sure we
55        # clean up
56        lvchange -a y "$DISK" >/dev/null 2>&1
57   
58        # Cleanup the lock, regardless of whether we started the LV
[1591]59        lvchange -a n "/dev/xenvg/lock_${LV}" >/dev/null 2>&1
60        lvchange -a ey "/dev/xenvg/lock_${LV}" >/dev/null 2>&1
61        lvremove -f "/dev/xenvg/lock_${LV}" >/dev/null 2>&1
[1457]62    fi
63   
64    return $RET
65}
66
[1275]67do_startup() {
[1261]68    gen_files
69   
[1457]70    for vm in "${SYSVMS[@]}"; do
71        start_sysvm "$vm"
72    done
73   
[1257]74    echo 1 >/proc/sys/net/ipv4/ip_forward
[1261]75    for i in all default; do
76        echo 1 >/proc/sys/net/ipv4/conf/$i/rp_filter
77        echo 1 >/proc/sys/net/ipv4/conf/$i/proxy_arp
[1257]78    done
[1261]79   
80    invoke-rc.d "$PARENTPACKAGE" "$1"
81}
82
[1275]83do_start() {
84    do_startup "start"
85}
86
[1261]87do_reload() {
[1275]88    do_startup "reload"
[1261]89}
90
91do_stop() {
[1277]92    invoke-rc.d "$PARENTPACKAGE" stop
[1261]93}
94
95std_init "$1"
Note: See TracBrowser for help on using the repository browser.