~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to lib/plugins/stonith/external/ssh

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# External STONITH module for ssh.
4
 
#
5
 
# Copyright (c) 2004 SUSE LINUX AG - Lars Marowsky-Bree <lmb@suse.de>
6
 
#
7
 
# This program is free software; you can redistribute it and/or modify
8
 
# it under the terms of version 2 of the GNU General Public License as
9
 
# published by the Free Software Foundation.
10
 
#
11
 
# This program is distributed in the hope that it would be useful, but
12
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
#
15
 
# Further, this software is distributed without any warranty that it is
16
 
# free of the rightful claim of any third person regarding infringement
17
 
# or the like.  Any license provided herein, whether implied or
18
 
# otherwise, applies only to this software file.  Patent licenses, if
19
 
# any, provided herein do not apply to combinations of this program with
20
 
# other software, or any other product whatsoever.
21
 
#
22
 
# You should have received a copy of the GNU General Public License
23
 
# along with this program; if not, write the Free Software Foundation,
24
 
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
25
 
#
26
 
 
27
 
SSH_COMMAND="/usr/bin/ssh -q -x -o PasswordAuthentication=no -o StrictHostKeyChecking=no -n -l root" 
28
 
#SSH_COMMAND="/usr/bin/ssh -q -x -n -l root"
29
 
 
30
 
REBOOT_COMMAND="echo 'sleep 2; /sbin/reboot -nf' | SHELL=/bin/sh at now >/dev/null 2>&1"
31
 
 
32
 
# Warning: If you select this poweroff command, it'll physically
33
 
# power-off the machine, and quite a number of systems won't be remotely
34
 
# revivable.
35
 
# TODO: Probably should touch a file on the server instead to just
36
 
# prevent heartbeat et al from being started after the reboot.
37
 
# POWEROFF_COMMAND="echo 'sleep 2; /sbin/poweroff -nf' | SHELL=/bin/sh at now >/dev/null 2>&1"
38
 
POWEROFF_COMMAND="echo 'sleep 2; /sbin/reboot -nf' | SHELL=/bin/sh at now >/dev/null 2>&1"
39
 
 
40
 
# Rewrite the hostlist to accept "," as a delimeter for hostnames too.
41
 
hostlist=`echo $hostlist | tr ',' ' '`
42
 
 
43
 
is_host_up() {
44
 
  for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
45
 
  do
46
 
    if
47
 
      ping -w1 -c1 "$1" >/dev/null 2>&1
48
 
    then
49
 
      sleep 1
50
 
    else
51
 
      return 1
52
 
    fi
53
 
  done
54
 
  return 0
55
 
}
56
 
 
57
 
 
58
 
case $1 in
59
 
gethosts)
60
 
        for h in $hostlist ; do
61
 
                echo $h
62
 
        done
63
 
        exit 0
64
 
        ;;
65
 
on)
66
 
        # Can't really be implemented because ssh cannot power on a system
67
 
        # when it is powered off.
68
 
        exit 1
69
 
        ;;
70
 
off)
71
 
        # Shouldn't really be implemented because if ssh cannot power on a 
72
 
        # system, it shouldn't be allowed to power it off.
73
 
        exit 1
74
 
        ;;
75
 
reset)
76
 
        for h in $hostlist
77
 
        do
78
 
          if
79
 
            [ "$h" != "$2" ]
80
 
          then
81
 
            continue
82
 
          fi
83
 
          if
84
 
            case ${livedangerously} in
85
 
              [Yy]*)    is_host_up $h;;
86
 
              *)        true;;
87
 
             esac
88
 
          then
89
 
            $SSH_COMMAND "$2" "$REBOOT_COMMAND"
90
 
            # Good thing this is only for testing...
91
 
            if
92
 
              is_host_up $h
93
 
            then
94
 
              exit 1
95
 
            else
96
 
              exit 0
97
 
            fi
98
 
          else
99
 
            # well... Let's call it successful, after all this is only for testing...
100
 
            exit 0
101
 
          fi
102
 
        done
103
 
        exit 1
104
 
        ;;
105
 
status)
106
 
        if
107
 
          [ -z "$hostlist" ]
108
 
        then
109
 
          exit 1
110
 
        fi
111
 
        for h in $hostlist
112
 
        do
113
 
          if
114
 
            ping -w1 -c1 "$h" 2>&1 | grep "unknown host"
115
 
          then
116
 
            exit 1
117
 
          fi
118
 
        done
119
 
        exit 0
120
 
        ;;
121
 
getconfignames)
122
 
        echo "hostlist"
123
 
        exit 0
124
 
        ;;
125
 
getinfo-devid)
126
 
        echo "ssh STONITH device"
127
 
        exit 0
128
 
        ;;
129
 
getinfo-devname)
130
 
        echo "ssh STONITH external device"
131
 
        exit 0
132
 
        ;;
133
 
getinfo-devdescr)
134
 
        echo "ssh-based Linux host reset"
135
 
        echo "Fine for testing, but not suitable for production!"
136
 
        exit 0
137
 
        ;;
138
 
getinfo-devurl)
139
 
        echo "http://openssh.org"
140
 
        exit 0
141
 
        ;;
142
 
getinfo-xml)
143
 
        cat << SSHXML
144
 
<parameters>
145
 
<parameter name="hostlist" unique="1" required="1">
146
 
<content type="string" />
147
 
<shortdesc lang="en">
148
 
Hostlist
149
 
</shortdesc>
150
 
<longdesc lang="en">
151
 
The list of hosts that the STONITH device controls
152
 
</longdesc>
153
 
</parameter>
154
 
 
155
 
<parameter name="livedangerously" unique="0" required="0">
156
 
<content type="enum" />
157
 
<shortdesc lang="en">
158
 
Live Dangerously!!
159
 
</shortdesc>
160
 
<longdesc lang="en">
161
 
Set to "yes" if you want to risk your system's integrity.
162
 
Of course, since this plugin isn't for production, using it
163
 
in production at all is a bad idea.  On the other hand,
164
 
setting this parameter to yes makes it an even worse idea.
165
 
Viva la Vida Loca!
166
 
</longdesc>
167
 
</parameter>
168
 
 
169
 
</parameters>
170
 
SSHXML
171
 
        exit 0
172
 
        ;;
173
 
*)
174
 
        exit 1
175
 
        ;;
176
 
esac