Contents of /trunk/xen-tools/xendomains.rc
Parent Directory | Revision Log
Revision 615 -
(show annotations)
(download)
Sat May 24 10:32:18 2008 UTC (16 years, 5 months ago) by niro
File size: 2709 byte(s)
Sat May 24 10:32:18 2008 UTC (16 years, 5 months ago) by niro
File size: 2709 byte(s)
-initscript files for xen-tools packages
1 | #!/bin/bash |
2 | # $Header: /root/magellan-cvs/src/xen-tools/xendomains.rc,v 1.1 2008-05-24 10:32:18 niro Exp $ |
3 | |
4 | #%rlevels: 3:s 4:s 5:s 0:k 1:k 2:k 6:k |
5 | #%start: 65 |
6 | #%stop: 25 |
7 | |
8 | #deps |
9 | #%needs: |
10 | #%before: |
11 | #%after: |
12 | |
13 | source /etc/sysconfig/rc |
14 | source $rc_functions |
15 | |
16 | get_domname() |
17 | { |
18 | local name_from_file=$(sed -rn 's/^name\W*=\W*\"?([[:alnum:]_\.-]+)\"?\W*;?/\1/p' "${1}" | tail -n 1) |
19 | |
20 | if [[ -z ${name_from_file} ]] |
21 | then |
22 | basename "${1}" |
23 | else |
24 | echo ${name_from_file} |
25 | fi |
26 | } |
27 | |
28 | is_running() |
29 | { |
30 | /usr/sbin/xm list "${1}" >/dev/null 2>&1 |
31 | } |
32 | |
33 | set_screen_cmd() |
34 | { |
35 | screen_cmd="screen -q -r ${SCREEN_NAME:=xen} -X" |
36 | } |
37 | |
38 | using_screen() |
39 | { |
40 | [[ "${SCREEN}" == "yes" || "${SCREEN}" == "YES" ]] |
41 | } |
42 | |
43 | case "$1" in |
44 | start) |
45 | set_screen_cmd |
46 | |
47 | echo -e ${COLOREDSTAR}"Starting Xen domains from ${AUTODIR:=/etc/xen/auto} ..." |
48 | if using_screen |
49 | then |
50 | echo -e ${COLOREDSTAR}"Creating screen session to hold domain consoles ..." |
51 | ( |
52 | screen -d -m -S ${SCREEN_NAME} -t dom0 \ |
53 | && ${screen_cmd} zombie dr \ |
54 | && logrotate -f /etc/xen/xen-consoles.logrotate \ |
55 | && ${screen_cmd} logfile /var/log/xen-consoles/%t.log \ |
56 | && ${screen_cmd} logfile flush ${SCREEN_LOG_INTERVAL:-1} \ |
57 | && ${screen_cmd} log on \ |
58 | && ${screen_cmd} deflog on |
59 | ) >/dev/null |
60 | if [[ $? -ne 0 ]] |
61 | then |
62 | evaluate_retval |
63 | return 1 |
64 | else |
65 | evaluate_retval |
66 | fi |
67 | fi |
68 | |
69 | # Create all domains with config files in AUTODIR |
70 | for dom in $(ls "${AUTODIR}/"* 2>/dev/null) |
71 | do |
72 | name=$(get_domname ${dom}) |
73 | if ! is_running ${name} |
74 | then |
75 | echo -e ${COLOREDSTAR}"Starting domain ${name} ..." |
76 | if using_screen |
77 | then |
78 | ${screen_cmd} screen -t ${name} xm create ${dom} -c |
79 | else |
80 | xm create --quiet ${dom} |
81 | fi |
82 | evaluate_retval |
83 | else |
84 | ${WARNING} "Not starting domain ${name} - already running ..." |
85 | fi |
86 | done |
87 | |
88 | update_svcstatus $1 |
89 | splash svc_started "$(basename $0)" 0 |
90 | ;; |
91 | |
92 | stop) |
93 | set_screen_cmd |
94 | |
95 | echo -e ${COLOREDSTAR}"Shutting down Xen domains from ${AUTODIR:=/etc/xen/auto} ..." |
96 | # Stop all domains with config files in AUTODIR |
97 | for dom in $(ls "${AUTODIR}/"* 2>/dev/null) |
98 | do |
99 | name=$(get_domname ${dom}) |
100 | if is_running ${name} |
101 | then |
102 | echo -e ${COLOREDSTAR}"Stopping domain ${name} ..." |
103 | xm shutdown --wait ${name} >/dev/null |
104 | evaluate_retval |
105 | else |
106 | ${WARNING} "Not stopping domain ${name} - not running ..." |
107 | fi |
108 | done |
109 | |
110 | if using_screen |
111 | then |
112 | echo -e ${COLOREDSTAR}"Closing screen session ${SCREEN_NAME} ..." |
113 | ${screen_cmd} quit |
114 | evaluate_retval |
115 | fi |
116 | |
117 | update_svcstatus $1 |
118 | splash svc_stopped "$(basename $0)" 0 |
119 | ;; |
120 | |
121 | restart) |
122 | $0 stop |
123 | sleep 1 |
124 | $0 start |
125 | ;; |
126 | |
127 | status) |
128 | /usr/sbin/xm list |
129 | ;; |
130 | |
131 | *) |
132 | echo "Usage: $0 {start|stop|restart|status}" |
133 | exit 1 |
134 | ;; |
135 | esac |