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

Last change on this file since 2086 was 2085, checked in by broder, 16 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
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
[2085]16SYSVM_TEMPLATES=(/etc/xen/sysvms/s_*.mako)
17SYSVM_FILES=("${SYSVM_TEMPLATES[@]/.mako/}")
[2067]18SYSVMS=("${SYSVM_FILES[@]/#\/etc\/xen\/sysvms\/}")
[2085]19GEN_FILES=(/etc/xen/xend-config.sxp.invirt "${SYSVM_FILES[@]}")
[1257]20
[1261]21dpkg -s "$PACKAGE" >/dev/null 2>/dev/null || exit 0
22
23. /lib/init/gen-files.sh
24. /lib/init/std-init.sh
25
[1457]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"
[1580]31    LV="${VM}_hda"
32    DISK="/dev/xenvg/$LV"
[1457]33   
34    # Don't bother trying to start the VM if it's already running
[1580]35    if xm list "$VM" >/dev/null 2>&1; then
[1457]36        return 1
37    fi
38   
[1580]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
[1591]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
[1457]64    fi
65   
66    return $RET
67}
68
[1275]69do_startup() {
[1261]70    gen_files
71   
[1457]72    for vm in "${SYSVMS[@]}"; do
73        start_sysvm "$vm"
74    done
75   
[1257]76    echo 1 >/proc/sys/net/ipv4/ip_forward
[1261]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
[1257]80    done
[1261]81   
82    invoke-rc.d "$PARENTPACKAGE" "$1"
83}
84
[1275]85do_start() {
86    do_startup "start"
87}
88
[1261]89do_reload() {
[1275]90    do_startup "reload"
[1261]91}
92
93do_stop() {
[1277]94    invoke-rc.d "$PARENTPACKAGE" stop
[1261]95}
96
97std_init "$1"
Note: See TracBrowser for help on using the repository browser.