Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -x
- ## Save some info on the system status
- get_info(){
- mkdir -p "$WORKSPACE/logs/"
- for option in CA e m x; do
- db_stat -$option -h /var/lib/rpm \
- | tee "$WORKSPACE/logs/rpmdb.${option}.log"
- ls -l "$WORKSPACE/logs/"
- done
- echo -e "Subject: RPMDB failure\nFrom:jenkins@$HOSTNAME\nCheck job $BUILD_URL\n\n" \
- | sendmail -v dcaroest@redhat.com
- }
- ## Duplicated packages check and preemtive cleanup
- ## Also takes care of the stall locks
- rm -f /var/lib/rpm/__db*
- rpm --rebuilddb
- yum clean rpmdb
- package-cleanup --cleandupes --noscripts -y
- duplicated="$(rpm -qa | sort | uniq -c | grep -v '^[ ]*1')"
- if [[ -n "$duplicated" ]]; then
- echo -e "IT FAILED; STILL SOME DUPLICATED PACKAGES:\n$duplicated"
- exit 1
- fi
- ## corrupt Packages database check
- verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
- verification_res=$?
- if [[ $verification_res -ne 0 ]]; then
- get_info
- echo "FIX: rebuilding rpm database, corrupt: $verification_out"
- rm -f /var/lib/rpm/__db.* || echo "No rpmdb files found"
- rpm --rebuilddb
- ## reverify to take some more drastic measures if needed
- verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
- verification_res=$?
- if [[ $verification_res -ne 0 ]]; then
- mv /var/lib/rpm/Packages /var/lib/rpm/Packages.backup
- /usr/lib/rpm/rpmdb_dump /var/lib/rpm/Packages.backup \
- | /usr/lib/rpm/rpmdb_load /var/lib/rpm/Packages
- verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
- verification_res=$?
- if [[ $verification_res -ne 0 ]]; then
- echo "FAILED TO FIX rpmdb problems, please check personally."
- echo "Last check error: $verification_out"
- exit 1
- fi
- fi
- echo "RPMDB FIXED! Continuing with the job."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement