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