~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/examples/xendomains

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# /etc/init.d/xendomains
4
 
# Start / stop domains automatically when domain 0 boots / shuts down.
5
 
#
6
 
# chkconfig: 345 99 00
7
 
# description: Start / stop Xen domains.
8
 
#
9
 
# This script offers fairly basic functionality.
10
 
#
11
 
# Based on the example in the "Designing High Quality Integrated Linux
12
 
# Applications HOWTO" by Avi Alkalay
13
 
# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/>
14
 
#
15
 
 
16
 
RETVAL=0
17
 
 
18
 
INITD=/etc/init.d/
19
 
. $INITD/functions
20
 
 
21
 
on_fn_exit()
22
 
{
23
 
    if [ $RETVAL -eq 0 ]; then
24
 
        success
25
 
    else
26
 
        failure
27
 
    fi
28
 
    
29
 
    echo
30
 
}
31
 
 
32
 
start() {
33
 
    if [ -f /var/lock/subsys/xendomains ]; then return; fi
34
 
 
35
 
    echo -n $"Starting auto Xen domains:"
36
 
 
37
 
    # we expect config scripts for auto starting domains to be in
38
 
    # /etc/xc/auto/ - they could just be symlinks to files elsewhere
39
 
    if [ $(ls /etc/xc/auto/ | wc -l) -gt 0 ]; then
40
 
        
41
 
       # create all domains with config files in /etc/xc/auto
42
 
        for dom in /etc/xc/auto/*; do
43
 
            xc_dom_create.py -q -f $dom
44
 
            if [ $? -ne 0 ]; then
45
 
                RETVAL=$?
46
 
            fi
47
 
        done
48
 
    fi
49
 
 
50
 
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/xendomains
51
 
 
52
 
    on_fn_exit
53
 
}
54
 
 
55
 
stop()
56
 
{
57
 
    # NB. this shuts down ALL Xen domains (politely), not just the ones in
58
 
    # /etc/xc/auto/*
59
 
    # This is because it's easier to do ;-) but arguably if this script is run
60
 
    # on system shutdown then it's also the right thing to do.
61
 
    
62
 
    echo -n $"Shutting down all Xen domains:"
63
 
 
64
 
    if [ $(ls /var/run/xendomains/ | wc -l) -gt 0 ]; then
65
 
        
66
 
        cd /var/run/xendomains/
67
 
 
68
 
        for pid in *; do
69
 
           
70
 
            kill -s SIGTERM $(cat $pid)
71
 
 
72
 
        done
73
 
 
74
 
    fi
75
 
 
76
 
    sleep 3 # avoid races
77
 
 
78
 
    xc_dom_control.py shutdown all -w # shut down all domains, politely and wait
79
 
                                      # for all to exit
80
 
    
81
 
    RETVAL=$?
82
 
 
83
 
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xendomains
84
 
 
85
 
    on_fn_exit
86
 
}
87
 
 
88
 
# This does NOT necessarily restart all running domains: instead it
89
 
# stops all running domains and then boots all the domains specified in
90
 
# /etc/xc/auto.  If other domains have been started manually then they will
91
 
# not get restarted.
92
 
# Commented out to avoid confusion!
93
 
#
94
 
#restart()
95
 
#{
96
 
#    stop
97
 
#    start
98
 
#}
99
 
 
100
 
# same as restart for now - commented out to avoid confusion
101
 
#reload()
102
 
#{
103
 
#    restart
104
 
#}
105
 
 
106
 
 
107
 
case "$1" in
108
 
    start)
109
 
        start
110
 
        ;;
111
 
 
112
 
    stop)
113
 
        stop
114
 
        ;;
115
 
 
116
 
# The following are commented out to disable them by default to avoid confusion
117
 
# - see the notes above
118
 
#
119
 
#    restart)
120
 
#       restart
121
 
#       ;;
122
 
#
123
 
#    reload)
124
 
#       reload
125
 
#       ;;
126
 
 
127
 
    status)
128
 
        xc_dom_control.py list
129
 
        ;;
130
 
 
131
 
    *)
132
 
        echo $"Usage: $0 {start|stop|status}"
133
 
        ;;
134
 
esac
135
 
 
136
 
exit $RETVAL