/usr/sbin/ccs_update_schema is in cman 3.1.8-1.2+b1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | #!/bin/bash
set +e
export LC_ALL=C
rngdir=/usr/share/cluster/relaxng
rasdir=/usr/share/cluster
fasdir=/usr/sbin
vardir=/var/lib/cluster
force=""
verbose=""
print_usage() {
echo "Usage:"
echo ""
echo "ccs_update_schema [options]"
echo ""
echo "Options:"
echo " -h Print this help, then exit"
echo " -V Print program version information, then exit"
echo " -v Produce verbose output"
echo " -f Force schema regeneration and ignore cache"
}
lecho() {
[ -n "$verbose" ] && echo "$@"
return 0
}
check_opts() {
while [ "$1" != "--" ]; do
case $1 in
-h)
print_usage
exit 0
;;
-V)
echo "ccs_update_schema version 3.1.8"
exit 0
;;
-v)
verbose=1
;;
-f)
force=1
;;
esac
shift
done
}
opts=$(getopt hvVf $@)
if [ "$?" != 0 ]; then
print_usage >&2
exit 1
fi
check_opts $opts
tmpdir="$(mktemp -d -q)" || {
echo "unable to create tempdir" >&2
exit 1
}
export tmpdir
# need to be careful (might have to mask traps on exit)
cleanup() {
[ "$1" != "0" ] && rm -f $vardir/*.cache $vardir/*.hash
[ -n "$tmpdir" ] && [ -d "$tmpdir" ] && rm -rf "$tmpdir"
rm -f $vardir/rng_update.lock
exit $1
}
trap "cleanup 1" ABRT
trap "cleanup 1" QUIT
trap "cleanup 1" TERM
trap "cleanup 1" INT
trap "cleanup 1" ERR
filter_file_list() {
filelist="$@"
for i in $filelist; do
[ "${i%\~}" != "${i}" ] && continue
[ "${i%,}" != "${i}" ] && continue
[ "${i%.orig}" != "${i}" ] && continue
[ "${i%.cfsaved}" != "${i}" ] && continue
[ "${i%.rpmsave}" != "${i}" ] && continue
[ "${i%.rpmorig}" != "${i}" ] && continue
[ "${i%.rpmnew}" != "${i}" ] && continue
[ "${i%.swp}" != "${i}" ] && continue
[ "${i%,v}" != "${i}" ] && continue
[ "${i%.dpkg-old}" != "${i}" ] && continue
[ "${i%.dpkg-dist}" != "${i}" ] && continue
[ "${i%.dpkg-new}" != "${i}" ] && continue
echo "$i"
done
}
filter_fence_list() {
filelist="$@"
for i in $faslist; do
[ "${i}" = "$fasdir/fence_legacy" ] && continue
[ "${i}" = "$fasdir/fence_node" ] && continue
[ "${i}" = "$fasdir/fence_nss_wrapper" ] && continue
[ "${i}" = "$fasdir/fence_pcmk" ] && continue
[ "${i}" = "$fasdir/fence_tool" ] && continue
[ "${i}" = "$fasdir/fence_vmware_helper" ] && continue
echo "$i"
done
}
generate_hash() {
outputfile="$1"
shift
filelist="$@"
if [ -n "$filelist" ]; then
md5sum $filelist > $outputfile
return $?
else
echo -n > $outputfile
return $?
fi
}
create_ras_stubs() {
lecho " ras: cannot find rng files. Creating stubs"
touch "$outputdir/resources.rng.hash"
cat > "$outputdir/resources.rng.cache" << EOF
<!-- STUB resource-agents definitions -->
<define name="SERVICE">
<element name="service" rha:description="Stub service">
<optional>
<ref name="CHILDREN"/>
</optional>
</element>
</define>
<define name="VM" >
<element name="vm" rha:description="Stub VM">
<optional>
<ref name="CHILDREN"/>
</optional>
</element>
</define>
<define name="CHILDREN">
<zeroOrMore>
<choice>
<ref name="SERVICE"/>
<ref name="VM"/>
</choice>
</zeroOrMore>
</define>
<!-- end STUB resource-agents definitions -->
EOF
}
generate_ras() {
outputdir="$1"
raslist=""
lecho " ras: checking required files"
doras_stub=""
for i in ra2rng.xsl ra2ref.xsl \
resources.rng.head resources.rng.mid resources.rng.tail; do
if [ ! -f "$rngdir/$i" ]; then
doras_stub=yes
fi
done
for i in service.sh vm.sh; do
if [ ! -x "$rasdir/$i" ]; then
doras_stub=yes
fi
done
[ "$doras_stub" = yes ] && create_ras_stubs && return 0
lecho " ras: looking for agents"
if [ -d "$rasdir" ]; then
raslist=$(find $rasdir \
-mindepth 1 -maxdepth 1 -type f -executable | sort -u)
raslist=$(filter_file_list $raslist)
# ordering is important apparently
[ -x $rasdir/service.sh ] && \
raslist="$rasdir/service.sh \
$(echo $raslist | sed -e 's#'$rasdir'/service.sh##g')"
fi
lecho " ras: generating hashes"
if ! generate_hash \
"$outputdir/resources.rng.hash" \
"$raslist $rngdir/ra2*.xsl $rngdir/resources.rng.* $0"; then
echo "Unable to generate resource agents hash" >&2
return 1
fi
if [ -z "$force" ] && \
[ -f $vardir/resources.rng.hash ] && \
[ -f $vardir/resources.rng.cache ] && \
[ "$(cat $vardir/resources.rng.hash | md5sum -)" = \
"$(cat "$outputdir/resources.rng.hash" | md5sum -)" ]; then
lecho " ras: using local cache"
cp $vardir/resources.rng.cache $outputdir/resources.rng.cache
return 0
fi
lecho " ras: generating rng data"
cat $rngdir/resources.rng.head > "$outputdir/resources.rng.cache"
lecho " ras: generating rng data"
for i in $raslist; do
lecho " ras: processing $(basename $i)"
$i meta-data 2>/dev/null | xsltproc $rngdir/ra2rng.xsl - >> \
"$outputdir/resources.rng.cache" 2>/dev/null
done
cat $rngdir/resources.rng.mid >> "$outputdir/resources.rng.cache"
lecho " ras: generating ref data"
for i in $raslist; do
lecho " ras: processing $(basename $i)"
$i meta-data 2>/dev/null | xsltproc $rngdir/ra2ref.xsl - >> \
"$outputdir/resources.rng.cache" 2>/dev/null
done
cat $rngdir/resources.rng.tail >> "$outputdir/resources.rng.cache"
}
create_fas_stubs() {
lecho " fas: cannot find rng files. Creating stubs"
touch "$outputdir/fence_agents.rng.hash"
cat > "$outputdir/fence_agents.rng.cache" << EOF
<!-- STUB fence-agents definitions -->
<define name="FENCEDEVICEOPTIONS">
<element name="service" rha:description="Stub fence device options">
<optional>
<ref name="STUBFENCEDEVICEOPTIONS"/>
</optional>
</element>
</define>
<define name="STUBFENCEDEVICEOPTIONS">
<zeroOrMore>
<choice>
<ref name="FENCEDEVICEOPTIONS"/>
</choice>
</zeroOrMore>
</define>
<!-- end STUB fence-agents definitions -->
EOF
}
generate_fas() {
outputdir="$1"
faslist=""
lecho " fas: checking required files"
dofas_stub=""
for i in fence2rng.xsl fence.rng.head fence.rng.tail; do
if [ ! -f "$rngdir/$i" ]; then
dofas_stub=yes
fi
done
[ "$dofas_stub" = yes ] && create_fas_stubs && return 0
lecho " fas: looking for agents"
if [ -d "$fasdir" ]; then
faslist=$(ls -1 $fasdir/fence_*)
faslist=$(filter_file_list $faslist)
faslist=$(filter_fence_list $faslist)
fi
lecho " fas: generating hashes"
if ! generate_hash \
"$outputdir/fence_agents.rng.hash" \
"$faslist $rngdir/fence2*.xsl $rngdir/fence.rng.* $0"; then
echo "Unable to generate fence agents hash" >&2
return 1
fi
if [ -z "$force" ] && \
[ -f $vardir/fence_agents.rng.hash ] && \
[ -f $vardir/fence_agents.rng.cache ] && \
[ "$(cat $vardir/fence_agents.rng.hash | md5sum -)" = \
"$(cat "$outputdir/fence_agents.rng.hash" | md5sum -)" ]; then
lecho " fas: using local cache"
cp $vardir/fence_agents.rng.cache \
$outputdir/fence_agents.rng.cache
return 0
fi
lecho " fas: generating new cache"
cat $rngdir/fence.rng.head > "$outputdir/fence_agents.rng.cache"
for i in $faslist; do
lecho " fas: processing $(basename $i)"
$i -o metadata 2>/dev/null | \
xsltproc $rngdir/fence2rng.xsl - >> \
"$outputdir/fence_agents.rng.cache" 2>/dev/null
[ "$?" != 0 ] && \
echo " <!-- No metadata for $i -->" >> \
"$outputdir/fence_agents.rng.cache"
done
cat $rngdir/fence.rng.tail >> "$outputdir/fence_agents.rng.cache"
}
build_schema() {
cat $rngdir/cluster.rng.in.head \
$outputdir/resources.rng.cache \
$outputdir/fence_agents.rng.cache \
$rngdir/cluster.rng.in.tail \
> $outputdir/cluster.rng || {
echo "generic error linking relaxng schema" >&2
return 1
}
xmllint --noout $outputdir/cluster.rng || {
echo "generated schema does not pass xmllint validation" >&2
return 1
}
return 0
}
# NOTE
# failure to delete cache and hash or failure to install them
# is not fatal and will result in both being regenerated at the next run
install_schema() {
mkdir -p $outputdir/backup || {
echo "Unable to create backup dir" >&2
return 1
}
cp -a $vardir/*rng* $outputdir/backup/ || {
echo "Unable to perform backup of current schema" >&2
return 1
}
rm -f $vardir/*.cache $vardir/*.hash
cp -f $outputdir/cluster.rng $vardir/ || {
cp -a $outputdir/backup/* $vardir/
echo "Failed to update relaxng ondisk data" >&2
return 1
}
cp $outputdir/*.cache $outputdir/*.hash $vardir/
return 0
}
(
flock --exclusive 200
lecho "Generating resource-agents cache"
generate_ras "$tmpdir" || {
echo "generic error creating resource agents relaxng schema" >&2
cleanup 1
}
lecho "Generating fence-agents cache"
generate_fas "$tmpdir" || {
echo "generic error creating fence agents relaxng schema" >&2
cleanup 1
}
lecho "Building final relaxng schema"
build_schema || cleanup 1
lecho "Installing schema in $vardir"
install_schema || cleanup 1
lecho "all done. have a nice day!"
cleanup 0
) 200>$vardir/rng_update.lock
|