-
Notifications
You must be signed in to change notification settings - Fork 201
/
vdsmd_init_common.sh.in
executable file
·236 lines (189 loc) · 5.51 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
#!/bin/sh
# SPDX-FileCopyrightText: 2013 IBM, Inc.
# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later
VDSM_TOOL="@BINDIR@/vdsm-tool"
UPGRADE_LOGGING_PARAMS="--vvverbose --append --logfile=@VDSMLOGDIR@/upgrade.log"
prog=vdsm
#### pre-start tasks ####
task_configure_vdsm_logs() {
local vdsm_logs="
@VDSMLOGDIR@/mom.log
@VDSMLOGDIR@/vdsm.log
"
local wanted_mode="0644"
local wanted_owner="@VDSMUSER@:@VDSMGROUP@"
for logfile in ${vdsm_logs}; do
if [ ! -e "${logfile}" ]; then
@TOUCH_PATH@ "${logfile}"
@CHMOD_PATH@ "${wanted_mode}" "${logfile}"
@CHOWN_PATH@ "${wanted_owner}" "${logfile}"
else
owner=$(stat -c %U:%G "${logfile}")
fmode=$(stat -c 0%a "${logfile}")
if [ "${owner}" != "${wanted_owner}" ]; then
echo "Warning: log file ${logfile} is owned by ${owner}... Fixing..."
@CHOWN_PATH@ "${wanted_owner}" "${logfile}"
fi
if [ "${fmode}" != "${wanted_mode}" ]; then
echo "Warning: bad file access mode for log file ${logfile} : ${fmode}... Fixing..."
@CHMOD_PATH@ "${wanted_mode}" "${logfile}"
fi
fi
done
}
task_run_init_hooks(){
"@PYTHON@" -m "vdsm.common.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="@LIBEXECDIR@/get-conf-item"
_mk_data_center() {
local dc
dc="$("${_GETCONFITEM}" "${_CONF_FILE}" irs repository /rhev/)"
@MKDIR_P@ "${dc}"
"@CHOWN_PATH@" @VDSMUSER@:@VDSMGROUP@ "${dc}"
}
_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
}
_mk_transient_disks_path() {
local transient_disks_path="@VDSMTRANSIENTDISKSDIR@"
@MKDIR_P@ "${transient_disks_path}"
"@CHOWN_PATH@" @VDSMUSER@:@VDSMGROUP@ "${transient_disks_path}"
}
_mk_backup_path() {
local backup_path="@VDSMRUNBACKUPDIR@"
@MKDIR_P@ "${backup_path}"
# qemu create the socket in this directory
"@CHMOD_PATH@" 0770 "${backup_path}"
"@CHOWN_PATH@" @VDSMUSER@:@VDSMGROUP@ "${backup_path}"
"@CHCON_PATH@" "system_u:object_r:qemu_var_run_t:s0" "${backup_path}" > /dev/null 2>&1
}
task_mkdirs(){
_mk_data_center
_mk_run_path
_mk_console_path
_mk_transient_disks_path
_mk_backup_path
}
_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.UTF8 "@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
}
#### pre-start tasks end ####
#### post-stop tasks ####
task_run_final_hooks(){
"@PYTHON@" -m "vdsm.common.hooks" 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_vdsm_logs \
run_init_hooks \
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