~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to cts/cts

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-07-16 16:40:24 UTC
  • mfrom: (1.1.11) (2.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130716164024-lvwrf4xivk1wdr3c
Tags: 1.1.9+git20130321-1ubuntu1
* Resync from debian expiremental.
* debian/control:
  - Use lower version for Build-Depends on libcorosync-dev
    and libqb-dev.
  - Build-Depends on libcfg-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
cts_root=`dirname $0`
 
4
stonith=rhcs
 
5
schema=1.1
 
6
stack=mcp
 
7
 
 
8
logfile=0
 
9
summary=0
 
10
verbose=0
 
11
pengine=0
 
12
watch=0
 
13
saved=0
 
14
tests=""
 
15
 
 
16
install=0
 
17
clean=0
 
18
build=0
 
19
kill=0
 
20
run=0
 
21
 
 
22
custom_log=""
 
23
patterns="-e CTS:"
 
24
 
 
25
# Note the quotes around `$TEMP': they are essential!
 
26
#TEMP=`getopt -o t:ac:sSvpe:lwf:d  --long run,clean -n 'cts' -- "$@"`
 
27
#eval set -- "$TEMP"
 
28
 
 
29
while true; do
 
30
    case $1 in
 
31
        -x) set -x; shift;;
 
32
        -a)
 
33
        screen -ls | grep cts
 
34
        exit 0;;
 
35
        -c|-g) cluster_name=$2; shift; shift;;
 
36
        -S) summary=1; saved=1; shift;;
 
37
        -s) summary=1; shift;;
 
38
        -v) verbose=`expr $verbose + 1`; shift;;
 
39
        -p) pengine=1; shift;;
 
40
        -e) patterns="$patterns -e `echo $2 | sed 's/ /\\\W/g'`"; shift; shift;;
 
41
        -l) logfile=1; shift;;
 
42
        -w) watch=1; shift;;
 
43
        -f) summary=1; custom_log=$2; shift; shift;;
 
44
        -t) tests="$tests $2"; shift; shift;;
 
45
        [0-9]*) tests="$tests $1"; shift;;
 
46
        --build|build) build=1; shift;;
 
47
        --kill|kill) kill=1; shift; break;;
 
48
        --run|run) run=1; shift; break;;
 
49
        --clean|clean) clean=1; shift;;
 
50
        --inst|--install|install) install=1; clean=1; shift;;
 
51
        local-init)
 
52
            local_root=
 
53
            case $cts_root in
 
54
                /*) local_root=`dirname $cts_root`;;
 
55
                *)  local_root=`dirname $PWD/$cts_root`;;
 
56
            esac
 
57
 
 
58
            cat << EOF > $cts_root/CTSvars.py
 
59
class CTSvars:
 
60
        CTS_home="$local_root/cts"
 
61
        Fencing_home="$local_root/fencing"
 
62
        CRM_CONFIG_DIR="/var/lib/pacemaker/cib"
 
63
        CRM_DAEMON_USER="hacluster"
 
64
        CRM_DAEMON_DIR="/usr/libexec/pacemaker"
 
65
        OCF_ROOT_DIR="/usr/lib/ocf"
 
66
EOF
 
67
 
 
68
            files="extra/cluster-init extra/cluster-helper extra/cluster-clean tools/crm_report.in"
 
69
            for f in $files; do
 
70
                cp $local_root/$f $cts_root/
 
71
            done
 
72
 
 
73
            cp $local_root/report_common.in $local_root/report_common
 
74
            sed -i.sed s:@localstatedir@:/var: $local_root/report_common
 
75
 
 
76
            cp $cts_root/crm_report.in $cts_root/crm_report
 
77
            sed -i.sed s:@datadir@/@PACKAGE@:$local_root/tools: $cts_root/crm_report
 
78
            chmod +x $cts_root/crm_report
 
79
 
 
80
            cp $cts_root/LSBDummy.in $cts_root/LSBDummy
 
81
            chmod +x $local_root/fencing/fence_*
 
82
            sed -i.sed s:@OCF_ROOT_DIR@:/usr/lib/ocf: $cts_root/LSBDummy
 
83
            exit 0
 
84
            ;;
 
85
 
 
86
        --wget)
 
87
            files="cluster-helper cluster-clean"
 
88
            for f in $files; do
 
89
                rm -f $cts_root/$f
 
90
                echo "Downloading helper script $f from GitHub"
 
91
                wget -O $cts_root/$f https://raw.github.com/ClusterLabs/pacemaker/master/extra/$f
 
92
                chmod +x $cts_root/$f
 
93
            done
 
94
            shift
 
95
            ;;
 
96
        --) shift; tests="$tests $*"; break;;
 
97
        "") break;;
 
98
        *) echo "Unknown argument: $1"; exit 1;;
 
99
    esac
 
100
done
 
101
 
 
102
# Add the location of this script
 
103
export PATH="$PATH:$cts_root"
 
104
which cluster-helper &>/dev/null
 
105
if [ $? != 0 ]; then
 
106
    echo $0 needs the cluster-helper script to be in your path
 
107
    echo You can obtain it from: https://raw.github.com/ClusterLabs/pacemaker/master/extra/cluster-helper
 
108
    exit 1
 
109
fi
 
110
 
 
111
which cluster-clean &>/dev/null
 
112
if [ $? != 0 ]; then
 
113
    echo $0 needs the cluster-clean script to be in your path
 
114
    echo You can obtain it from: https://raw.github.com/ClusterLabs/pacemaker/master/extra/cluster-clean
 
115
    exit 1
 
116
fi
 
117
 
 
118
if [ "x$cluster_name" = x -o "x$cluster_name" = xpick ]; then
 
119
    clusters=`ls -1 ~/.dsh/group/[a-z]+[0-9] | sed s/.*group.// | tr '\n' ' ' `
 
120
 
 
121
    echo "custom) interactively define a cluster"
 
122
    for i in $clusters; do
 
123
        echo "$i) `cluster-helper --list short -g $i`"
 
124
    done
 
125
 
 
126
    read -p "Choose a cluster [custom]: " cluster_name
 
127
    echo
 
128
fi
 
129
 
 
130
if [ -z $cluster_name ]; then
 
131
    cluster_name=custom
 
132
fi
 
133
 
 
134
 
 
135
case $cluster_name in
 
136
  *)
 
137
    cluster_hosts=`cluster-helper --list short -g $cluster_name`
 
138
    cluster_log=~/cluster-$cluster_name.log;
 
139
    ;;
 
140
  custom)
 
141
    read -p "Cluster name: " cluster_name
 
142
    read -p "Cluster hosts: " cluster_hosts
 
143
    read -p "Cluster log file: " cluster_log
 
144
    ;;
 
145
esac
 
146
 
 
147
if [ $build = 1 -a $run = 1 ]; then
 
148
    install=1
 
149
    clean=1
 
150
fi
 
151
 
 
152
if [ $build = 1 ]; then
 
153
    which build-pcmk
 
154
    if [ $? != 0 ]; then
 
155
        echo "You'll need to write/obtain build-pcmk in order to build pacemaker from here.  Skipping"
 
156
    else
 
157
        build-pcmk -18
 
158
        rc=$?
 
159
        if [ $rc != 0 ]; then
 
160
            echo "Build failed: $rc"
 
161
            exit $rc
 
162
        fi
 
163
    fi
 
164
fi
 
165
 
 
166
if [ $clean = 1 ]; then
 
167
    rm -f $cluster_log; cluster-clean -g $cluster_name --kill
 
168
elif [ $kill = 1 ]; then
 
169
    cluster-clean -g $cluster_name --kill-only
 
170
fi
 
171
 
 
172
if [ $install = 1 ]; then
 
173
    cluster-helper -g $cluster_name -- yum install -y pacemaker pacemaker-debuginfo pacemaker-cts libqb libqb-debuginfo
 
174
fi
 
175
 
 
176
if [ $run = 1 ]; then
 
177
    $cts_root/CTSlab.py -g $cluster_name -r --stonith $stonith -c --schema pacemaker-$schema --stack $stack 500 $*
 
178
    exit $?
 
179
 
 
180
elif [ $clean = 1 ]; then
 
181
    exit 0
 
182
fi
 
183
 
 
184
screen -ls | grep cts-$cluster_name &>/dev/null
 
185
active=$?
 
186
 
 
187
if [ ! -z $custom_log ]; then
 
188
    cluster_log=$custom_log
 
189
fi
 
190
 
 
191
if [ "x$tests" != x -a "x$tests" != "x " ]; then
 
192
    for t in $tests; do
 
193
        echo "crm_report --cts-log $cluster_log -d -T $t"
 
194
        crm_report --cts-log $cluster_log -d -T $t
 
195
    done
 
196
 
 
197
elif [ $logfile = 1 ]; then
 
198
    echo $cluster_log
 
199
 
 
200
elif [ $summary = 1 ]; then
 
201
    files=$cluster_log
 
202
    if [ $saved = 1 ]; then
 
203
        files=`ls -1tr ~/CTS-*/cluster-log.txt`
 
204
    fi
 
205
    for f in $files; do
 
206
        echo $f
 
207
        case $verbose in
 
208
            0) cat -n $f | grep $patterns | grep -v "CTS: debug:"
 
209
                ;;
 
210
            1) cat -n $f | grep $patterns | grep -v "CTS:.* cmd:"
 
211
                ;;
 
212
            *) cat -n $f | grep $patterns
 
213
                ;;
 
214
        esac
 
215
        echo ""
 
216
    done
 
217
 
 
218
elif [ $watch = 1 ]; then
 
219
    case $verbose in
 
220
        0) tail -F $cluster_log | grep $patterns | grep -v "CTS: debug:"
 
221
                ;;
 
222
        1) tail -F $cluster_log | grep $patterns | grep -v "CTS:.* cmd:"
 
223
                ;;
 
224
        *) tail -F $cluster_log | grep $patterns
 
225
                ;;
 
226
    esac
 
227
 
 
228
elif [ $active = 0 ]; then
 
229
    screen -x cts-$cluster_name
 
230
 
 
231
else
 
232
    touch $cluster_log
 
233
 
 
234
#    . ~/.bashrc
 
235
#    . $BASH_FILES/.heartbeat
 
236
    export cluster_name cluster_hosts cluster_log
 
237
    screen -S cts-$cluster_name bash
 
238
fi