-
Notifications
You must be signed in to change notification settings - Fork 28
/
esdc-service-control
executable file
·134 lines (117 loc) · 2.68 KB
/
esdc-service-control
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
#!/bin/bash
if [[ "$(id -u)" != "0" ]]; then
echo "This script must be run as root" >&2
exit 6
fi
MAINDIR="$(cd "$(dirname "$0")/.." || exit 64 ; pwd -P)"
ERIGONES_HOME="${ERIGONES_HOME:-"${MAINDIR}"}"
ESLIB="${ESLIB:-"${ERIGONES_HOME}/bin/eslib"}"
# shellcheck disable=SC1090
. "${ESLIB}/functions.sh"
function pcs_resource_action() {
local action="$1"
local resname="$2"
local nodename="$(ha_get_my_nodename)"
if [[ "${action}" == "status" ]]; then
crm_resource -Wr "${resname}"
elif crm_resource -Wr "${resname}" | grep -q "running on: ${nodename}"; then
# touch only if the resource is running on this node
pcs resource "${action}" "${resname}" --wait=20 > /dev/null
else
echo "Ignoring ${resname} on ${nodename} (not running locally)"
fi
}
systemd_pretty_status() {
local svcname="$1"
echo "${svcname} is $(get_svc_prop "${svcname}" SubState)"
}
function node_status() {
svcs svc:/application/erigonesd:*
}
function node_restart() {
svcadm restart svc:/application/erigonesd:*
}
function node_start() {
svcadm enable svc:/application/erigonesd:*
}
function node_stop() {
svcadm disable -t svc:/application/erigonesd:*
}
function node_disable() {
svcadm disable svc:/application/erigonesd:*
}
function mgmt_status() {
if ha_is_active; then
pcs_resource_action status postgres-ha
pcs_resource_action status erigonesd-beat
else
systemd_pretty_status erigonesd-beat
fi
systemd_pretty_status erigonesd
systemd_pretty_status [email protected]
systemd_pretty_status [email protected]
systemd_pretty_status [email protected]
}
function mgmt_restart() {
if ha_is_active; then
pcs_resource_action restart erigonesd-beat
else
systemctl restart erigonesd-beat
fi
systemctl restart esdc@{gunicorn-api.service,gunicorn-gui.service,gunicorn-sio.service} erigonesd
}
function mgmt_stop() {
if ha_is_active; then
pcs_resource_action disable erigonesd-beat
systemctl stop esdc@* erigonesd
else
systemctl stop esdc@* erigonesd erigonesd-beat
fi
}
function mgmt_disable() {
if ha_is_active; then
pcs_resource_action disable erigonesd-beat
systemctl disable esdc@* erigonesd
else
systemctl disable esdc@* erigonesd erigonesd-beat
fi
}
function is_node() {
[[ "$(uname -s)" == "SunOS" ]] && \
[[ -f /usr/bin/zonename ]] && \
[[ "$(/usr/bin/zonename)" == "global" ]]
}
case "$1" in
"status")
if is_node; then
node_status
else
mgmt_status
fi
;;
"restart")
if is_node; then
node_restart
else
mgmt_restart
fi
;;
"start")
if is_node; then
node_start
else
mgmt_restart
fi
;;
"stop")
if is_node; then
node_stop
else
mgmt_stop
fi
;;
*)
echo "Usage: $0 {status|start|stop|restart}" >&2
exit 1
;;
esac