~ubuntu-branches/debian/stretch/resource-agents/stretch

« back to all changes in this revision

Viewing changes to heartbeat/fio

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
Import upstream version 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
#       fio RA
 
4
#
 
5
# Copyright (c) 2010 SUSE Linux Products GmbH, Lars Marowsky-Brée
 
6
#                    All Rights Reserved.
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of version 2 of the GNU General Public License as
 
10
# published by the Free Software Foundation.
 
11
#
 
12
# This program is distributed in the hope that it would be useful, but
 
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
#
 
16
# Further, this software is distributed without any warranty that it is
 
17
# free of the rightful claim of any third person regarding infringement
 
18
# or the like.  Any license provided herein, whether implied or
 
19
# otherwise, applies only to this software file.  Patent licenses, if
 
20
# any, provided herein do not apply to combinations of this program with
 
21
# other software, or any other product whatsoever.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write the Free Software Foundation,
 
25
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 
26
#
 
27
 
 
28
#######################################################################
 
29
# Initialization:
 
30
 
 
31
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
32
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
33
 
 
34
#######################################################################
 
35
 
 
36
meta_data() {
 
37
        cat <<END
 
38
<?xml version="1.0"?>
 
39
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
40
<resource-agent name="fio" version="0.9">
 
41
<version>1.0</version>
 
42
 
 
43
<longdesc lang="en">
 
44
fio is a generic I/O load generator. This RA allows start/stop of fio
 
45
instances to simulate load on a cluster without configuring complex
 
46
services.
 
47
</longdesc>
 
48
<shortdesc lang="en">fio IO load generator</shortdesc>
 
49
 
 
50
<parameters>
 
51
<parameter name="args">
 
52
<longdesc lang="en">
 
53
Arguments to the fio client. Minimally, this should be a (list of) job
 
54
descriptions to run.
 
55
</longdesc>
 
56
<shortdesc lang="en">fio arguments</shortdesc>
 
57
<content type="string" default="" />
 
58
</parameter>
 
59
 
 
60
</parameters>
 
61
 
 
62
<actions>
 
63
<action name="start"        timeout="60" />
 
64
<action name="stop"         timeout="60" />
 
65
<action name="monitor"      timeout="60" interval="10" />
 
66
<action name="meta-data"    timeout="5" />
 
67
<action name="validate-all"   timeout="20" />
 
68
</actions>
 
69
</resource-agent>
 
70
END
 
71
}
 
72
 
 
73
#######################################################################
 
74
 
 
75
fio_usage() {
 
76
        cat <<END
 
77
usage: $0 {start|stop|monitor|validate-all|meta-data}
 
78
END
 
79
}
 
80
 
 
81
fio_start() {
 
82
        fio_monitor ; rc=$?
 
83
        if [ $rc = $OCF_SUCCESS ]; then
 
84
                ocf_log "fio already running."
 
85
                exit $OCF_SUCCESS
 
86
        fi
 
87
        if [ $rc != $OCF_NOT_RUNNING ]; then
 
88
                ocf_log info "fio apparently dead; cleaning up before restart"
 
89
                fio_stop
 
90
        fi
 
91
        fio $OCF_RESKEY_args >/dev/null 2>&1 </dev/null &
 
92
        fio_pid=`jobs -p`
 
93
        echo $fio_pid >${fio_state_file}
 
94
        ocf_log info "fio started as pid=$fio_pid"
 
95
        exit $OCF_SUCCESS
 
96
}
 
97
 
 
98
fio_stop() {
 
99
        for sig in SIGINT SIGTERM SIGKILL ; do
 
100
                fio_monitor ; rc=$?
 
101
                case $rc in
 
102
                $OCF_NOT_RUNNING)
 
103
                        ocf_log info "fio already stopped."
 
104
                        exit $OCF_SUCCESS
 
105
                        ;;
 
106
                $OCF_ERR_GENERIC)
 
107
                        rm $fio_state_file
 
108
                        ocf_log "fio stopped and cleaned up."
 
109
                        exit $OCF_SUCCESS
 
110
                        ;;
 
111
                $OCF_SUCCESS)
 
112
                        if [ -n "$fio_pid" ]; then
 
113
                                ocf_log "Sending $sig to fio (pid=$fio_pid)"
 
114
                                kill -$sig $fio_pid
 
115
                                sleep 3
 
116
                                continue
 
117
                        fi
 
118
                        ocf_log err "Internal logic failure in fio RA."
 
119
                        ;;
 
120
                *)      ocf_log err "Internal logic failure in fio RA."
 
121
                        ;;
 
122
                esac
 
123
        done
 
124
        ocf_log err "fio did not stop! Perhaps hung on IO?"
 
125
        exit $OCF_ERR_GENERIC
 
126
}
 
127
 
 
128
fio_monitor() {
 
129
        fio_state_file="${HA_RSCTMP}/fio-${OCF_RESOURCE_INSTANCE}.state"
 
130
        if [ ! -e $fio_state_file ]; then
 
131
                return $OCF_NOT_RUNNING
 
132
        fi
 
133
        fio_pid=`cat $fio_state_file`
 
134
        
 
135
        if [ -z "$fio_pid" ]; then
 
136
                ocf_log err "State file found, but empty. Assuming stopped."
 
137
                return $OCF_NOT_RUNNING
 
138
        fi
 
139
 
 
140
        ps=`ps h -o comm $fio_pid 2>&1`
 
141
        if [ "$ps" != "fio" ]; then
 
142
                fio_pid=""
 
143
                return $OCF_ERR_GENERIC
 
144
        fi
 
145
        return $OCF_SUCCESS
 
146
}
 
147
 
 
148
fio_validate() {
 
149
        return $OCF_SUCCESS
 
150
}
 
151
 
 
152
case $__OCF_ACTION in
 
153
        meta-data)      meta_data
 
154
                        exit $OCF_SUCCESS
 
155
                        ;;
 
156
        validate-all)   fio_validate;;
 
157
        usage|help)     fio_usage
 
158
                        exit $OCF_SUCCESS
 
159
                        ;;
 
160
esac
 
161
 
 
162
ocf_is_probe || check_binary fio
 
163
 
 
164
case $__OCF_ACTION in
 
165
        start)          fio_start;;
 
166
        stop)           fio_stop;;
 
167
        monitor)        fio_monitor;;
 
168
        *)              fio_usage
 
169
                        exit $OCF_ERR_UNIMPLEMENTED
 
170
                        ;;
 
171
esac
 
172