| 1 |
#!/bin/bash |
| 2 |
# vim: set sw=4 : |
| 3 |
# |
| 4 |
# Resource Agent for BOOTH site daemon. |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of version 2 of the GNU General Public License as |
| 8 |
# published by the Free Software Foundation. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it would be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
# |
| 14 |
# Further, this software is distributed without any warranty that it is |
| 15 |
# free of the rightful claim of any third person regarding infringement |
| 16 |
# or the like. Any license provided herein, whether implied or |
| 17 |
# otherwise, applies only to this software file. Patent licenses, if |
| 18 |
# any, provided herein do not apply to combinations of this program with |
| 19 |
# other software, or any other product whatsoever. |
| 20 |
# |
| 21 |
# You should have received a copy of the GNU General Public License along |
| 22 |
# with this program; if not, write to the Free Software Foundation, Inc., |
| 23 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 |
# |
| 25 |
|
| 26 |
####################################################################### |
| 27 |
# Initialization: |
| 28 |
|
| 29 |
DEFAULT_BIN="boothd" |
| 30 |
DEFAULT_CONF="/etc/booth/booth.conf" |
| 31 |
|
| 32 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} |
| 33 |
# shellcheck source=/usr/lib/ocf/lib/heartbeat/ocf-shellfuncs |
| 34 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs |
| 35 |
|
| 36 |
####################################################################### |
| 37 |
|
| 38 |
booth_site_meta_data() { |
| 39 |
cat <<END |
| 40 |
<?xml version="1.0"?> |
| 41 |
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> |
| 42 |
<resource-agent name="booth-site" version="0.9"> |
| 43 |
<version>1.0</version> |
| 44 |
|
| 45 |
|
| 46 |
<longdesc lang="en"> |
| 47 |
This Resource Agent can control the BOOTH site daemon. |
| 48 |
It assumes that the binary boothd is in your default PATH. |
| 49 |
In most cases, it should be run as a primitive resource. |
| 50 |
</longdesc> |
| 51 |
<shortdesc lang="en">BOOTH site daemon</shortdesc> |
| 52 |
|
| 53 |
<parameters> |
| 54 |
|
| 55 |
<parameter name="config" unique="1"> |
| 56 |
<longdesc lang="en"> |
| 57 |
The configuration name (or configuration filename) to use. |
| 58 |
</longdesc> |
| 59 |
<shortdesc lang="en">BOOTH Options</shortdesc> |
| 60 |
<content type="string" default="$DEFAULT_CONF" /> |
| 61 |
</parameter> |
| 62 |
|
| 63 |
<parameter name="args" unique="1"> |
| 64 |
<longdesc lang="en"> |
| 65 |
Any additional options to start the BOOTH daemon with |
| 66 |
</longdesc> |
| 67 |
<shortdesc lang="en">BOOTH Options</shortdesc> |
| 68 |
<content type="string" default="" /> |
| 69 |
</parameter> |
| 70 |
|
| 71 |
<parameter name="daemon" unique="1"> |
| 72 |
<longdesc lang="en"> |
| 73 |
The daemon to start |
| 74 |
</longdesc> |
| 75 |
<shortdesc lang="en">The daemon to start</shortdesc> |
| 76 |
<content type="string" default="$DEFAULT_BIN" /> |
| 77 |
</parameter> |
| 78 |
|
| 79 |
</parameters> |
| 80 |
|
| 81 |
<actions> |
| 82 |
<action name="start" timeout="20" /> |
| 83 |
<action name="stop" timeout="20" /> |
| 84 |
<action name="restart" timeout="20" /> |
| 85 |
<action name="reload" timeout="20" /> |
| 86 |
<action name="monitor" timeout="20" interval="10" depth="0" start-delay="0" /> |
| 87 |
<action name="meta-data" timeout="5" /> |
| 88 |
<action name="validate-all" timeout="30" /> |
| 89 |
</actions> |
| 90 |
</resource-agent> |
| 91 |
END |
| 92 |
} |
| 93 |
|
| 94 |
####################################################################### |
| 95 |
|
| 96 |
booth_site_usage() { |
| 97 |
cat <<END |
| 98 |
usage: $0 {start|stop|restart|reload|monitor|validate-all|meta-data} |
| 99 |
|
| 100 |
Expects to have a fully populated OCF RA-compliant environment set. |
| 101 |
END |
| 102 |
} |
| 103 |
|
| 104 |
grep_cmd_pid() { |
| 105 |
ps -o pid,cmd -e | grep -w "$@" | |
| 106 |
awk '{print $1}' |
| 107 |
} |
| 108 |
get_booth_pid() { |
| 109 |
local pid |
| 110 |
pid=`grep_cmd_pid "[b]oothd.*$OCF_RESKEY_config"` |
| 111 |
if [ -z "$pid" ]; then |
| 112 |
grep_cmd_pid "[b]oothd site$" |
| 113 |
else |
| 114 |
echo $pid |
| 115 |
fi |
| 116 |
} |
| 117 |
is_booth_running() { |
| 118 |
[ -n "`get_booth_pid`" ] |
| 119 |
} |
| 120 |
|
| 121 |
booth_site_status() { |
| 122 |
is_booth_running || |
| 123 |
return $OCF_NOT_RUNNING |
| 124 |
} |
| 125 |
|
| 126 |
booth_monitor_basic() { |
| 127 |
booth list -c $OCF_RESKEY_config > /dev/null |
| 128 |
} |
| 129 |
|
| 130 |
booth_site_start() { |
| 131 |
local rc |
| 132 |
|
| 133 |
booth_site_status |
| 134 |
rc=$? |
| 135 |
|
| 136 |
case $rc in |
| 137 |
0) |
| 138 |
ocf_log info "boothd already running" |
| 139 |
return $OCF_SUCCESS |
| 140 |
;; |
| 141 |
$OCF_NOT_RUNNING) ;; |
| 142 |
esac |
| 143 |
|
| 144 |
# shellcheck disable=SC2154 |
| 145 |
# (OCF_RESKEY_args: injected by CRM) |
| 146 |
$OCF_RESKEY_daemon daemon -c $OCF_RESKEY_config $OCF_RESKEY_args || |
| 147 |
return $OCF_ERR_GENERIC |
| 148 |
sleep 1 |
| 149 |
while ! booth_monitor_basic; do |
| 150 |
sleep 1 |
| 151 |
done |
| 152 |
|
| 153 |
return $OCF_SUCCESS |
| 154 |
} |
| 155 |
|
| 156 |
booth_site_stop() { |
| 157 |
local pid |
| 158 |
pid=`get_booth_pid` |
| 159 |
if [ -z "$pid" ]; then |
| 160 |
ocf_log info "boothd already stopped" |
| 161 |
return $OCF_SUCCESS |
| 162 |
fi |
| 163 |
|
| 164 |
ocf_stop_processes TERM 5 $pid |
| 165 |
while is_booth_running; do |
| 166 |
sleep 1 |
| 167 |
done |
| 168 |
return $OCF_SUCCESS |
| 169 |
} |
| 170 |
|
| 171 |
booth_site_restart() { |
| 172 |
booth_site_stop |
| 173 |
booth_site_start |
| 174 |
} |
| 175 |
|
| 176 |
booth_site_reload() { |
| 177 |
booth_site_restart |
| 178 |
} |
| 179 |
|
| 180 |
booth_site_monitor() { |
| 181 |
booth_site_status |
| 182 |
case $? in |
| 183 |
0) return $OCF_SUCCESS ;; |
| 184 |
$OCF_NOT_RUNNING) return $OCF_NOT_RUNNING ;; |
| 185 |
esac |
| 186 |
} |
| 187 |
|
| 188 |
booth_site_validate_all() { |
| 189 |
if ! test -f $OCF_RESKEY_config; then |
| 190 |
ocf_log err "$OCF_RESKEY_config does not exist" |
| 191 |
return $OCF_ERR_INSTALLED |
| 192 |
fi |
| 193 |
|
| 194 |
# shellcheck disable=SC2154 |
| 195 |
# (OCF_RESKEY_CRM_meta_globally_unique: injected by CRM) |
| 196 |
if ocf_is_true $OCF_RESKEY_CRM_meta_globally_unique; then |
| 197 |
ocf_log err "$OCF_RESOURCE_INSTANCE must be configured with the globally_unique=false meta attribute" |
| 198 |
return $OCF_ERR_CONFIGURED |
| 199 |
fi |
| 200 |
|
| 201 |
return $OCF_SUCCESS |
| 202 |
} |
| 203 |
|
| 204 |
: ${OCF_RESKEY_daemon:=$DEFAULT_BIN} |
| 205 |
: ${OCF_RESKEY_config:=$DEFAULT_CONF} |
| 206 |
# shellcheck disable=SC2034 |
| 207 |
# (OCF_REQUIRED_BINARIES consumed by ocf_rarun) |
| 208 |
OCF_REQUIRED_BINARIES=${OCF_RESKEY_daemon} |
| 209 |
|
| 210 |
ocf_rarun $* |