This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpostgres-xl-gtm
executable file
·158 lines (142 loc) · 4.19 KB
/
postgres-xl-gtm
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/sh
#
# Resource Agent for managing Postgres-XL GTM resources.
#
# License: PostgreSQL License.
# (c) 2017 Bitnine Global, Inc.
: ${OCF_FUNCTIONS_DIR=$OCF_ROOT/lib/heartbeat}
. $OCF_FUNCTIONS_DIR/ocf-shellfuncs
OCF_RESKEY_user_default=postgres
OCF_RESKEY_bindir_default=/usr/local/pgsql/bin
OCF_RESKEY_host_default=$(hostname)
OCF_RESKEY_port_default=6666
: ${OCF_RESKEY_user=$OCF_RESKEY_user_default}
: ${OCF_RESKEY_bindir=$OCF_RESKEY_bindir_default}
: ${OCF_RESKEY_host=$OCF_RESKEY_host_default}
: ${OCF_RESKEY_port=$OCF_RESKEY_port_default}
gtm_ctl=$OCF_RESKEY_bindir/gtm_ctl
pgxc_monitor=$OCF_RESKEY_bindir/pgxc_monitor
runasowner() {
local loglevel=''
case $1 in
-info|-warn)
loglevel=$1
shift
;;
esac
ocf_run $loglevel su $OCF_RESKEY_user -c "cd $OCF_RESKEY_datadir; $*"
}
meta_data() {
cat <<EOF
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="postgres-xl-gtm">
<version>1.0</version>
<longdesc lang="en">
Resource agent for a GTM in a Postgres-XL cluster. It manages a GTM as an HA resource.
</longdesc>
<shortdesc lang="en">Resource agent for a GTM in a Postgres-XL cluster</shortdesc>
<parameters>
<parameter name="user">
<longdesc lang="en">
The user who starts GTM.
</longdesc>
<shortdesc lang="en">The user who starts GTM</shortdesc>
<content type="string" default="$OCF_RESKEY_user_default" />
</parameter>
<parameter name="bindir">
<longdesc lang="en">
Path to the directory storing the Postgres-XL binaries. The resource agent uses gtm_ctl and pgxc_monitor.
</longdesc>
<shortdesc lang="en">Path to the Postgres-XL binaries</shortdesc>
<content type="string" default="$OCF_RESKEY_bindir_default" />
</parameter>
<parameter name="datadir" required="true">
<longdesc lang="en">
Path to the GTM data directory.
</longdesc>
<shortdesc lang="en">Path to the GTM data directory</shortdesc>
<content type="string" />
</parameter>
<parameter name="host">
<longdesc lang="en">
Host IP address or unix socket directory the instance is listening on.
</longdesc>
<shortdesc lang="en">Instance IP or unix socket directory</shortdesc>
<content type="string" default="$OCF_RESKEY_host_default" />
</parameter>
<parameter name="port">
<longdesc lang="en">
Port the instance is listening on.
</longdesc>
<shortdesc lang="en">Instance port</shortdesc>
<content type="integer" default="$OCF_RESKEY_port_default" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="5" />
<action name="stop" timeout="5" />
<action name="monitor" timeout="10" interval="10" depth="0" />
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
EOF
}
ocf_start() {
if ocf_monitor; then
ocf_log info 'GTM is already running'
return $OCF_SUCCESS
fi
runasowner "$gtm_ctl start -Z gtm -w -D $OCF_RESKEY_datadir -l gtm.logfile -p $OCF_RESKEY_bindir"
if [ $? -eq 0 ]; then
ocf_log info 'GTM is started'
return $OCF_SUCCESS
else
ocf_exit_reason "Can't start GTM"
return $OCF_ERR_GENERIC
fi
}
ocf_stop() {
if ! ocf_monitor -info; then
ocf_log info 'GTM already stopped'
return $OCF_SUCCESS
fi
runasowner "$gtm_ctl stop -Z gtm -w -D $OCF_RESKEY_datadir -p $OCF_RESKEY_bindir"
if [ $? -eq 0 ]; then
return $OCF_SUCCESS
else
ocf_exit_reason 'GTM failed to stop'
return $OCF_ERR_GENERIC
fi
}
ocf_monitor() {
local loglevel=$1
if ! runasowner "test -w $OCF_RESKEY_datadir"; then
ocf_log info "$OCF_RESKEY_datadir does not exist"
return $OCF_NOT_RUNNING
fi
runasowner $loglevel "$pgxc_monitor -Z gtm -h $OCF_RESKEY_host -p $OCF_RESKEY_port"
if [ $? -eq 0 ]; then
return $OCF_SUCCESS
else
return $OCF_NOT_RUNNING
fi
}
case $__OCF_ACTION in
meta-data)
meta_data
exit $OCF_SUCCESS
;;
start)
ocf_start
exit $?
;;
stop)
ocf_stop
exit $?
;;
monitor)
ocf_monitor
exit $?
;;
esac