rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / cluster / resource-agents-openindiana / files / haproxy
blob92490be398ea7699573d3701dfb9e26da6a6eae9
1 #!/bin/bash
3 # Resource script for haproxy daemon
5 # Description: Manages haproxy daemon as an OCF resource in
6 # an High Availability setup.
8 # HAProxy OCF script's Author: Andreas Grueninger
9 # License: BSD
10 # Copyright 2016 Andreas Grueninger, Grueninger GmbH, (grueni). All rights reserved.
13 # usage: $0 {start|stop|status|monitor|validate-all|meta-data}
15 # The "start" arg starts haproxy.
17 # The "stop" arg stops it.
19 # OCF parameters:
20 # OCF_RESKEY_binpath
21 # OCF_RESKEY_conffile
22 # OCF_RESKEY_extraconf
24 # Note:This RA requires that the haproxy config files has a "pidfile"
25 # entry so that it is able to act on the correct process
26 ##########################################################################
27 # Initialization:
29 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
30 . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
32 USAGE="Usage: $0 {start|stop|status|monitor|validate-all|meta-data}";
34 ##########################################################################
36 usage()
38 echo $USAGE >&2
41 meta_data()
43 cat <<END
44 <?xml version="1.0"?>
45 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
46 <resource-agent name="haproxy">
47 <version>1.0</version>
48 <longdesc lang="en">
49 This script manages haproxy daemon
50 </longdesc>
51 <shortdesc lang="en">Manages an haproxy daemon</shortdesc>
53 <parameters>
55 <parameter name="binpath">
56 <longdesc lang="en">
57 The haproxy binary path.
58 For example, "/usr/sbin/haproxy"
59 </longdesc>
60 <shortdesc lang="en">Full path to the haproxy binary</shortdesc>
61 <content type="string" default="/usr/sbin/haproxy"/>
62 </parameter>
64 <parameter name="conffile">
65 <longdesc lang="en">
66 The haproxy daemon configuration file name with full path.
67 For example, "/etc/haproxy/haproxy.cfg"
68 </longdesc>
69 <shortdesc lang="en">Configuration file name with full path</shortdesc>
70 <content type="string" default="/etc/haproxy/haproxy.cfg" />
71 </parameter>
73 <parameter name="extraconf">
74 <longdesc lang="en">
75 Extra command line arguments to pass to haproxy.
76 For example, "-f /etc/haproxy/shared.cfg"
77 </longdesc>
78 <shortdesc lang="en">Extra command line arguments for haproxy</shortdesc>
79 <content type="string" default="" />
80 </parameter>
82 </parameters>
84 <actions>
85 <action name="start" timeout="20s"/>
86 <action name="stop" timeout="20s"/>
87 <action name="monitor" depth="0" timeout="20s" interval="60s" />
88 <action name="validate-all" timeout="20s"/>
89 <action name="meta-data" timeout="5s"/>
90 </actions>
91 </resource-agent>
92 END
93 exit $OCF_SUCCESS
96 get_pid_and_conf_file()
98 if [ -n "$OCF_RESKEY_conffile" ]; then
99 CONF_FILE=$OCF_RESKEY_conffile
100 else
101 CONF_FILE="/etc/haproxy/haproxy.cfg"
104 PIDFILE="`grep -v \"#\" ${CONF_FILE} | grep \"pidfile\" | sed 's/^[ \t]*pidfile[ \t]*//'`"
105 if [ "${PIDFILE}" = '' ]; then
106 PIDFILE="/var/run/${OCF_RESOURCE_INSTANCE}.pid"
110 haproxy_status()
112 if [ -n "$PIDFILE" -a -f "$PIDFILE" ]; then
113 # haproxy is probably running
114 PID=`cat $PIDFILE`
115 if [ -n "$PID" ]; then
116 if ps -p $PID | grep haproxy >/dev/null ; then
117 # ocf_log info "haproxy daemon running"
118 return $OCF_SUCCESS
119 else
120 ocf_log info "haproxy daemon is not running but pid file exists"
121 return $OCF_NOT_RUNNING
123 else
124 ocf_log err "PID file empty!"
125 return $OCF_ERR_GENERIC
129 # haproxy is not running
130 ocf_log info "haproxy daemon is not running"
131 return $OCF_NOT_RUNNING
134 haproxy_start()
136 # if haproxy is running return success
137 haproxy_status
138 retVal=$?
139 if [ $retVal -eq $OCF_SUCCESS ]; then
140 exit $OCF_SUCCESS
141 elif [ $retVal -ne $OCF_NOT_RUNNING ]; then
142 ocf_log err "Error. Unknown status."
143 exit $OCF_ERR_GENERIC
146 if [ -n "$OCF_RESKEY_binpath" ]; then
147 COMMAND="$OCF_RESKEY_binpath"
148 else
149 COMMAND="/usr/sbin/haproxy"
152 mkdir -p /var/run/haproxy
153 $COMMAND $OCF_RESKEY_extraconf -D -f $CONF_FILE -p $PIDFILE;
154 if [ $? -ne 0 ]; then
155 ocf_log err "Error. haproxy daemon returned error $?."
156 exit $OCF_ERR_GENERIC
159 ocf_log info "Started haproxy daemon."
160 exit $OCF_SUCCESS
164 haproxy_stop()
166 if haproxy_status ; then
167 PID=`cat $PIDFILE`
168 if [ -n "$PID" ] ; then
169 kill $PID
170 if [ $? -ne 0 ]; then
171 kill -SIGKILL $PID
172 if [ $? -ne 0 ]; then
173 ocf_log err "Error. Could not stop haproxy daemon."
174 return $OCF_ERR_GENERIC
177 rm $PIDFILE 2>/dev/null
180 ocf_log info "Stopped haproxy daemon."
181 exit $OCF_SUCCESS
184 haproxy_monitor()
186 haproxy_status
189 haproxy_validate_all()
191 if [ -n "$OCF_RESKEY_binpath" -a ! -x "$OCF_RESKEY_binpath" ]; then
192 ocf_log err "Binary path $OCF_RESKEY_binpath does not exist."
193 exit $OCF_ERR_ARGS
195 if [ -n "$OCF_RESKEY_conffile" -a ! -f "$OCF_RESKEY_conffile" ]; then
196 ocf_log err "Config file $OCF_RESKEY_conffile does not exist."
197 exit $OCF_ERR_ARGS
200 if grep -v "^#" "$CONF_FILE" | grep "pidfile" > /dev/null ; then
202 else
203 ocf_log err "Error. \"pidfile\" entry required in the haproxy config file by haproxy OCF RA."
204 return $OCF_ERR_GENERIC
207 return $OCF_SUCCESS
212 # Main
215 if [ $# -ne 1 ]; then
216 usage
217 exit $OCF_ERR_ARGS
220 case $1 in
221 start) get_pid_and_conf_file
222 haproxy_start
225 stop) get_pid_and_conf_file
226 haproxy_stop
229 status) get_pid_and_conf_file
230 haproxy_status
233 monitor)get_pid_and_conf_file
234 haproxy_monitor
237 validate-all) get_pid_and_conf_file
238 haproxy_validate_all
241 meta-data) meta_data
244 usage) usage
245 exit $OCF_SUCCESS
248 *) usage
249 exit $OCF_ERR_UNIMPLEMENTED
251 esac