/
postinstall
executable file
·227 lines (191 loc) · 5.15 KB
/
postinstall
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/sh
# OpenHA postinstall script
LOG_D=/var/log/openha
CONF_D=/etc/openha
VAR_D=/var/lib/openha
SHARE_D=/usr/share/openha
PROC_D=$LOG_D/proc
SVC_D=$VAR_D/services
[ ! -d $LOG_D ] && mkdir $LOG_D
log () {
exec >> $LOG_D/postinstall.log 2>&1
DATE=`date +"%Y-%m-%d %H:%M:%S"`
printf "%b\n" "$DATE $*"
}
BASEDIR=${BASEDIR:-/}
# removing leading / if present
TRAILING=`echo "$BASEDIR" | sed 's/^.*\(.\)$/\1/'`
if [ "${TRAILING}" = "/" ] ; then
MYBASEDIR=`echo "$BASEDIR" | sed 's/.$//'`
else
MYBASEDIR=$BASEDIR
fi
LD_LIBRARY_PATH=${MYBASEDIR}/usr/local/lib; export LD_LIBRARY_PATH
create_directories()
{
log "Creating openha directories structure"
[ ! -d $CONF_D ] && mkdir -p $CONF_D
[ ! -d $PROC_D ] && mkdir -p $PROC_D
[ ! -d $SVC_D ] && mkdir -p $SVC_D
}
remove_old_symlinks()
{
for symlink in ${MYBASEDIR}/etc/rc2.d/S99cluster ${MYBASEDIR}/etc/rc3.d/S99cluster ${MYBASEDIR}/etc/rc0.d/K01cluster ${MYBASEDIR}/etc/rcS.d/K01cluster
do
if test -h $symlink
then
log "remove_old_symlinks : removing $symlink"
rm -f $symlink
fi
done
}
is_systemd_mgmt()
{
type systemctl >> /dev/null 2>&1
ret=$?
if test $ret -eq 0
then
log "is_systemd_mgmt : detected systemd managed distribution"
return 1
else
return 0
fi
}
is_chkconfig_mgmt()
{
type chkconfig >> /dev/null 2>&1
ret=$?
if test $ret -eq 0
then
log "is_chkconfig_mgmt : detected chkconfig managed distribution"
return 1
else
return 0
fi
}
is_updatercd_mgmt()
{
type update-rc.d >> /dev/null 2>&1
ret=$?
if test $ret -eq 0
then
log "is_updatercd_mgmt : detected update-rc.d managed distribution"
return 1
else
return 0
fi
}
systemd_launch()
{
systemdsvc="opensvc-openha.service"
log "systemd_launch : Copying systemd unit file to system"
cp -f $SHARE_D/systemd.opensvc-openha.service /etc/systemd/system/$systemdsvc
log "systemd_launch : setting perms on systemd unit file"
chmod 644 /etc/systemd/system/$systemdsvc
log "systemd_launch : reloading systemd configuration"
systemctl -q daemon-reload
log "systemd_launch : enabling opensvc-openha.service unit"
systemctl -q enable $systemdsvc
}
chkconfig_launch()
{
if test -f /etc/init.d/ezha -o -h /etc/init.d/ezha
then
log "chkconfig_launch : removing existing /etc/init.d/ezha"
chkconfig --del ezha >> /dev/null 2>&1
rm -f /etc/init.d/ezha
fi
if test -f /etc/init.d/openha -o -h /etc/init.d/openha
then
log "chkconfig_launch : removing existing /etc/init.d/openha"
chkconfig --del openha >> /dev/null 2>&1
rm -f /etc/init.d/openha
fi
log "chkconfig_launch : copying launcher to /etc/init.d/openha"
cp -f $SHARE_D/init/openha.init /etc/init.d/openha
chmod 755 /etc/init.d/openha
log "chkconfig_launch : enabling launcher /etc/init.d/openha"
chkconfig --add openha
}
updatercd_launch()
{
if test -f /etc/init.d/ezha -o -h /etc/init.d/ezha
then
log "updatercd_launch : removing existing /etc/init.d/ezha"
update-rc.d -f ezha remove >> /dev/null 2>&1
rm -f /etc/init.d/ezha
fi
if test -f /etc/init.d/openha -o -h /etc/init.d/openha
then
log "updatercd_launch : removing existing /etc/init.d/openha"
update-rc.d -f openha remove >> /dev/null 2>&1
rm -f /etc/init.d/openha
fi
log "updatercd_launch : copying launcher to /etc/init.d/openha"
cp -f $SHARE_D/init/openha.init /etc/init.d/openha
chmod 755 /etc/init.d/openha
log "updatercd_launch : enabling launcher /etc/init.d/openha"
update-rc.d openha defaults
}
legacy_launch()
{
log "legacy_launch : creating symlinks"
if test -d ${MYBASEDIR}/etc/init.d
then
TARGET=${MYBASEDIR}/etc/init.d/openha
elif test -d ${MYBASEDIR}/sbin/init.d
then
TARGET=${MYBASEDIR}/sbin/init.d/openha
else
return
fi
cp -f ${MYBASEDIR}/usr/share/openha/init/openha.init ${TARGET}
rm -f /etc/rc?.d/K01cluster
rm -f /etc/rc?.d/S99cluster
sls="${MYBASEDIR}/etc/rc2.d/S99openha ${MYBASEDIR}/etc/rc0.d/K01openha ${MYBASEDIR}/etc/rcS.d/K01openha"
if [ `uname -s` = "Linux" ]
then
sls="$sls ${MYBASEDIR}/etc/rc3.d/S99openha"
fi
for symlink in $sls
do
ln -sf ../init.d/openha $symlink
if test $? -eq 0
then
log "legacy_launch : adding $symlink"
else
log "legacy_launch : error while adding $symlink"
fi
done
}
migrate_to_fsh() {
[ "$(echo /etc/openha/*)" != "/etc/openha/*" ] && return
for cf in nodes monitor services
do
[ -f /usr/local/cluster/conf/$cf ] && {
log "cp /usr/local/cluster/conf/$cf /etc/openha"
cp /usr/local/cluster/conf/$cf /etc/openha
}
done
}
# start
create_directories
remove_old_symlinks
is_systemd_mgmt ; reta=$?
is_chkconfig_mgmt ; retb=$?
is_updatercd_mgmt ; retc=$?
log "main : reta=$reta retb=$retb retc=$retc"
if test $reta -eq 1
then
systemd_launch
elif test $retb -eq 1
then
chkconfig_launch
elif test $retc -eq 1
then
updatercd_launch
else
legacy_launch
fi
migrate_to_fsh
exit 0