source: package_tags/invirt-xen-config/0.0.22/debian/invirt-xen-config.init @ 2685

Last change on this file since 2685 was 2085, checked in by broder, 15 years ago

Correctly calculate the lists of both the sysvms to startup and the
Mako templates to render in the invirt-xen-config startup script.

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