blob: b1e61b35d0bb1e407f390304d3ee7b99cfde4a68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#!/bin/sh
#
# High-Availability pgagent OCF resource agent
#
# Description: Starts/stops pgagent
# Author: Oleg Selin
# License: GNU General Public License (GPL)
#
# OCF parameters:
# OCF_RESKEY_connection_string
# OCF_RESKEY_user
# OCF_RESKEY_options
#
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
OCF_RESKEY_executable_default="`which pgagent`"
OCF_RESKEY_connection_string_default="user=postgres host=/var/run/postgresql"
OCF_RESKEY_user_default="postgres"
OCF_RESKEY_options_default="-r 1 -t 1"
: ${OCF_RESKEY_executable="${OCF_RESKEY_executable_default}"}
: ${OCF_RESKEY_connection_string="${OCF_RESKEY_connection_string_default}"}
: ${OCF_RESKEY_user="${OCF_RESKEY_user_default}"}
: ${OCF_RESKEY_options="${OCF_RESKEY_options_default}"}
pgagent_validate_all() {
check_binary pgagent
ocf_log debug "executable: '$OCF_RESKEY_executable'"
ocf_log debug "connection string: '$OCF_RESKEY_connection_string'"
ocf_log debug "user: '$OCF_RESKEY_user'"
ocf_log debug "options: '$OCF_RESKEY_options'"
if [ -z "$OCF_RESKEY_connection_string" ]; then
ocf_log err "Connection string is not configured!"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_user" ]; then
ocf_log err "User is not configured!"
exit $OCF_ERR_CONFIGURED
fi
getent passwd $OCF_RESKEY_user >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
ocf_log err "User $OCF_RESKEY_user doesn't exist";
return $OCF_ERR_CONFIGURED;
fi
return $OCF_SUCCESS
}
pgagent_start() {
pgagent_validate_all
nohup su - $OCF_RESKEY_user -c "'$OCF_RESKEY_executable' $OCF_RESKEY_options '$OCF_RESKEY_connection_string'" > /dev/null 2>&1 &
sleep 1
if pgagent_monitor; then
return $OCF_SUCCESS
fi
return $OCF_ERR_GENERIC
}
pgagent_stop() {
pgagent_validate_all
pid=`pgrep -f -x -U $OCF_RESKEY_user "$OCF_RESKEY_executable $OCF_RESKEY_options $OCF_RESKEY_connection_string"`
if [ -n "$pid" ]; then
ocf_run kill $pid || return $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
}
pgagent_monitor() {
if [ -z "$OCF_RESKEY_executable" ]; then
return $OCF_ERR_INSTALLED
fi
ocf_run pgrep -f -x -U "$OCF_RESKEY_user" "$OCF_RESKEY_executable $OCF_RESKEY_options $OCF_RESKEY_connection_string" || return $OCF_NOT_RUNNING
return $OCF_SUCCESS
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="pgagent" version="1.0">
<version>1.0</version>
<longdesc lang="en">This is a pgagent Resource Agent.</longdesc>
<shortdesc lang="en">Controls pgagent</shortdesc>
<parameters>
<parameter name="connection_string">
<longdesc lang="en">Connection string for pgagent.</longdesc>
<shortdesc lang="en">pgagent connection string</shortdesc>
<content type="string" default="$OCF_RESKEY_connection_string_default" />
</parameter>
<parameter name="user">
<longdesc lang="en">User to run pgagent as.</longdesc>
<shortdesc lang="en">User to run pgagent</shortdesc>
<content type="string" default="$OCF_RESKEY_user_default" />
</parameter>
<parameter name="options">
<longdesc lang="en">Options for pgagent.</longdesc>
<shortdesc lang="en">pgagent run options, see pgagent --help for details</shortdesc>
<content type="string" default="$OCF_RESKEY_options_default" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="5s" />
<action name="stop" timeout="5s" />
<action name="monitor" timeout="20s" interval="10s" depth="0" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="5s" />
</actions>
</resource-agent>
END
}
pgagent_usage() {
cat <<END
usage: $0 {start|stop|monitor|meta-data|validate-all}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
case $__OCF_ACTION in
start) pgagent_start;;
stop) pgagent_stop;;
monitor) pgagent_monitor;;
validate-all) pgagent_validate_all;;
usage|help) pgagent_usage
exit $OCF_SUCCESS
;;
meta-data) meta_data
exit $OCF_SUCCESS
;;
*) pgagent_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
|