Advertisement
Guest User

Untitled

a guest
Dec 28th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. #!/bin/bash -x
  2.  
  3. ## Save some info on the system status
  4. get_info(){
  5.     mkdir -p "$WORKSPACE/logs/"
  6.     for option in CA e m x; do
  7.         db_stat -$option -h /var/lib/rpm \
  8.         | tee "$WORKSPACE/logs/rpmdb.${option}.log"
  9.         ls -l "$WORKSPACE/logs/"
  10.     done
  11.     echo -e "Subject: RPMDB failure\nFrom:jenkins@$HOSTNAME\nCheck job $BUILD_URL\n\n" \
  12.     | sendmail -v dcaroest@redhat.com
  13. }
  14.  
  15. ## Duplicated packages check and preemtive cleanup
  16. ## Also takes care of the stall locks
  17. rm -f /var/lib/rpm/__db*
  18. rpm --rebuilddb
  19. yum clean rpmdb
  20. package-cleanup --cleandupes --noscripts -y
  21.  
  22. duplicated="$(rpm -qa | sort | uniq -c | grep -v '^[ ]*1')"
  23. if [[ -n "$duplicated" ]]; then
  24.     echo -e "IT FAILED; STILL SOME DUPLICATED PACKAGES:\n$duplicated"
  25.     exit 1
  26. fi
  27.  
  28. ## corrupt Packages database check
  29. verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
  30. verification_res=$?
  31. if [[ $verification_res -ne 0 ]]; then
  32.     get_info
  33.     echo "FIX: rebuilding rpm database, corrupt: $verification_out"
  34.     rm -f /var/lib/rpm/__db.* || echo "No rpmdb files found"
  35.     rpm --rebuilddb
  36.     ## reverify to take some more drastic measures if needed
  37.     verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
  38.     verification_res=$?
  39.     if [[ $verification_res -ne 0 ]]; then
  40.         mv /var/lib/rpm/Packages /var/lib/rpm/Packages.backup
  41.         /usr/lib/rpm/rpmdb_dump /var/lib/rpm/Packages.backup \
  42.         | /usr/lib/rpm/rpmdb_load /var/lib/rpm/Packages
  43.         verification_out="$(/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages 2>&1)"
  44.         verification_res=$?
  45.         if [[ $verification_res -ne 0 ]]; then
  46.             echo "FAILED TO FIX rpmdb problems, please check personally."
  47.             echo "Last check error: $verification_out"
  48.             exit 1
  49.         fi
  50.     fi
  51.     echo "RPMDB FIXED! Continuing with the job."
  52. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement