forked from oVirt/vdsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdsmd_init_common.sh.in
280 lines (230 loc) · 7.05 KB
/
vdsmd_init_common.sh.in
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/sh
# Copyright 2013 IBM, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#
VDSM_TOOL="@BINDIR@/vdsm-tool"
UPGRADE_LOGGING_PARAMS="--vvverbose --append --logfile=@VDSMLOGDIR@/upgrade.log"
prog=vdsm
#### pre-start tasks ####
task_wait_for_network() {
# interfaces that we depend upon may not have their IP address ready yet
# see https://bugzilla.redhat.com/show_bug.cgi?id=1174611#c34
@LIBEXECDIR@/wait_for_ipv4s
# never fail, in order to allow intentionally-downed vdsm-controlled
# interfaces
return 0
}
task_configure_coredump() {
local conf_file="@CONFDIR@/vdsm.conf"
local getconfitem="@VDSMDIR@/get-conf-item"
if "${getconfitem}" "${conf_file}" vars core_dump_enable false |
tr A-Z a-z | grep -q true; then
echo "/var/log/core/core.%p.%t.dump" > /proc/sys/kernel/core_pattern
fi
}
task_configure_vdsm_logs() {
local vdsm_logs="
@VDSMLOGDIR@/connectivity.log
@VDSMLOGDIR@/mom.log
@VDSMLOGDIR@/vdsm.log
"
for logfile in ${vdsm_logs}; do
if [ ! -e "${logfile}" ]; then
@TOUCH_PATH@ "${logfile}"
@CHMOD_PATH@ 0644 "${logfile}"
@CHOWN_PATH@ @VDSMUSER@:@VDSMGROUP@ "${logfile}"
fi
done
}
task_run_init_hooks(){
"@PYTHON@" -m "vdsm.hooks" before_vdsm_start
}
task_check_is_configured() {
"$VDSM_TOOL" is-configured
}
task_prepare_transient_repository() {
"$VDSM_TOOL" setup-transient-repository
"$VDSM_TOOL" cleanup-transient-repository
}
task_syslog_available() {
if ! [ -S "/dev/log" ]; then
echo " Cannot communicate with syslog daemon for reports. "
echo " Install syslog daemon provider, configure it properly"
echo " and start the service."
echo " (Alternatives: rsyslog, syslog-ng)"
return 1
fi
return 0
}
task_nwfilter(){
"${VDSM_TOOL}" nwfilter
}
task_dummybr(){
"${VDSM_TOOL}" dummybr
}
_has_systemd() {
"@MOUNTPOINT_PATH@" -q /cgroup/systemd ||
"@MOUNTPOINT_PATH@" -q /sys/fs/cgroup/systemd
}
task_dump_bonding_options(){
"${VDSM_TOOL}" dump-bonding-options
}
task_tune_system(){
"@SYSCTL_PATH@" -q -p "/etc/sysctl.d/vdsm.conf"
}
_CONF_FILE="@CONFDIR@/vdsm.conf"
_GETCONFITEM="@VDSMDIR@/get-conf-item"
_DOM_METADATA_BACKUP_DIR="@VDSMLOGDIR@/backup"
_mk_data_center() {
local dc
dc="$("${_GETCONFITEM}" "${_CONF_FILE}" irs repository /rhev/)"
@MKDIR_P@ "${dc}"
"@CHOWN_PATH@" @VDSMUSER@:@VDSMGROUP@ "${dc}"
}
_mk_dom_backup() {
@MKDIR_P@ "${_DOM_METADATA_BACKUP_DIR}" > /dev/null 2>&1
"@CHOWN_PATH@" @METADATAUSER@:@METADATAGROUP@ "$(dirname "${_DOM_METADATA_BACKUP_DIR}")" > /dev/null 2>&1
"@CHOWN_PATH@" @METADATAUSER@:@METADATAGROUP@ "${_DOM_METADATA_BACKUP_DIR}" > /dev/null 2>&1
}
_mk_core_path() {
local core_path=/var/log/core
if ! [ -d "${core_path}" ]; then
@MKDIR_P@ "${core_path}" > /dev/null 2>&1
fi
"@CHMOD_PATH@" a+tw "${core_path}" > /dev/null 2>&1
}
_mk_run_path() {
local run_path
for run_path in "@VDSMRUNDIR@"; do
@MKDIR_P@ "${run_path}"
"@CHMOD_PATH@" 755 "${run_path}"
"@CHOWN_PATH@" @VDSMUSER@:@VDSMGROUP@ "${run_path}"
"@RESTORECON_PATH@" "${run_path}"
done
}
_mk_console_path() {
local console_path=/var/run/ovirt-vmconsole-console
if ! [ -d "${console_path}" ]; then
@MKDIR_P@ "${console_path}" > /dev/null 2>&1
fi
"@CHOWN_PATH@" @VDSMUSER@:@QEMUGROUP@ "${console_path}"
"@CHMOD_PATH@" 0775 "${console_path}" > /dev/null 2>&1
"@CHCON_PATH@" "system_u:object_r:qemu_var_run_t:s0" "${console_path}" > /dev/null 2>&1
}
task_mkdirs(){
_mk_data_center
_mk_core_path
_mk_dom_backup
_mk_run_path
_mk_console_path
"@CHMOD_PATH@" 1777 /dev/shm
}
_free_space() {
local pathToTest="$1"
df -P "${pathToTest}" | awk '{print $4}'| tail -1
}
task_test_space() {
local MIN_SPACE_KB=10000
if [ "$(_free_space "@VDSMLOGDIR@")" -lt "${MIN_SPACE_KB}" ]; then
echo "${prog}: low log space"
return 1
fi
return 0
}
task_test_lo() {
if ! LC_ALL=C "@IP_PATH@" link show lo | "@GREP_PATH@" -q UP; then
echo "VDSMD: lo interface is down, can't run !"
echo "VDSMD: lo interface is down, can't run !" > /dev/kmsg
return 1
fi
return 0
}
task_validate_configuration(){
"$VDSM_TOOL" validate-config
}
task_upgraded_version_check(){
local upgraded_ver_file="@VDSMLIBDIR@/upgraded_version"
if [ -f "${upgraded_ver_file}" ]; then
local ret=0
if grep -q '^vdsm-4\.10\.' "${upgraded_ver_file}"; then
# REQUIRED_FOR upgrade from vdsm-4.10.x
"$VDSM_TOOL" configure --force
ret=$?
elif grep -qE '^vdsm-4\.(13|14|16)\.' "${upgraded_ver_file}"; then
# REQUIRED_FOR upgrade from 4.13.x or 4.14.x or 4.16.x
# mutlipath and sasl password configuration logic moved to
# vdsm-tool in 4.17.
"$VDSM_TOOL" configure --module multipath --module passwd
ret=$?
fi
[ "${ret}" -eq 0 ] && rm -f "${upgraded_ver_file}"
fi
}
#### pre-start tasks end ####
#### post-stop tasks ####
task_run_final_hooks(){
"@PYTHON@" "@VDSMDIR@/hooks.pyc" after_vdsm_stop
}
#### post-stop tasks end ####
usage(){
echo "Usage:"
echo "vdsm_init_common.sh --pre-start|--post-stop"
}
run_tasks(){
local tasks="$1"
for taskName in $tasks ; do
echo "${prog}: Running ${taskName}"
"task_${taskName}"
rt=$?
if [ "$rt" -ne 0 ]; then
echo "${prog}: stopped during execute ${taskName} task" \
"(task returned with error code ${rt})."
exit 1
fi
done
}
case "$1" in
--pre-start)
run_tasks " \
mkdirs \
configure_coredump \
configure_vdsm_logs \
wait_for_network \
run_init_hooks \
upgraded_version_check \
check_is_configured \
validate_configuration \
prepare_transient_repository \
syslog_available \
nwfilter \
dummybr \
tune_system \
test_space \
test_lo \
"
;;
--post-stop)
run_tasks " \
run_final_hooks \
"
;;
--help|*)
usage
exit 1
;;
esac