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

Last change on this file since 2222 was 2087, checked in by price, 16 years ago

revert r2085

also while I'm touching this code, use run-parts --list rather than glob

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