sys: explain how to fix the issue on "debconf-get-selections missing" error
[matthijs/upstream/backupninja.git] / handlers / sys.in
index b6c7fbcb4297417dcf3f3cf258a41ff6407cd1e2..f293840157b323004092ffac8db97309a272ddb7 100755 (executable)
@@ -3,18 +3,25 @@
 # this handler will save various reports of vital system information.
 # by default, all the reports are enabled and are saved in /var/backups.
 #
-# (1) a list of all the packages installed and removed.
+# (1) a capture of the debconf package selection states. This file
+#     can be used to restore the answers to debconf questions for
+#     packages that you will be installing through (2) below. To
+#     do this, run: "debconf-set-selections < debconfsel.txt"
+#
+# (2) a list of all the packages installed and removed.
 #     this file can be used to restore the state of installed packages
-#     by running "dpkg --set-selections < dpkg-selections.txt
+#     by running "dpkg --set-selections < dpkg-selections.txt and
+#     then run "apt-get -u dselect-upgrade". If you have the 
+#     debconf-set-selections file from (1), you should restore those first.
 # 
-# (2) the partition table of all disks. 
+# (3) the partition table of all disks. 
 #     this partition table can be used to format another disk of
 #     the same size. this can be handy if using software raid and 
 #     you have a disk go bad. just replace the disk and partition it
 #     by running "sfdisk /dev/sdb < partitions.sdb.txt"
 #     (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
 #
-# (3) hardware information. 
+# (4) hardware information. 
 #     write to a text file the important things which hwinfo can gleen.
 #
 
@@ -46,6 +53,8 @@ then
    getconf packagesfile $parentdir/dpkg-selections.txt
    getconf packagemgr   `which dpkg`
    getconf packagemgroptions ' --get-selections *'
+   getconf selectionsfile $parentdir/debconfsel.txt
+   getconf debconfgetselections `which debconf-get-selections`
 elif [ $os = "redhat" ]
 then
    getconf packagesfile  $parentdir/rpmpackages.txt 
@@ -73,11 +82,18 @@ getconf HWINFO `which hwinfo`
 getconf sfdisk_options ""
 getconf hwinfo_options ""
 
-# See if vservers are configured
+getconf vsnames all
+
+# If vservers are configured, check that the ones listed in $vsnames are running.
 local usevserver=no
-if [ $vservers_are_available = yes ]
-then
-   info "vserver method enabled"
+if [ $vservers_are_available = yes ]; then
+   if [ "$vsnames" = all ]; then
+      vsnames="$found_vservers"
+   fi
+   if ! vservers_running "$vsnames" ; then
+      fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
+   fi
+   info "Using vservers '$vsnames'"
    usevserver=yes
 fi
 
@@ -91,24 +107,40 @@ if [ "$packages" == "yes" ]; then
 
    if [ $usevserver = yes ]; then
       info "vserver root directory set to: $VROOTDIR"
-      for vserver in $found_vservers; do
+      for vserver in $vsnames; do
          info "examining vserver: $vserver"
          # is it running ?
-         $VSERVERINFO -q $vserver RUNNING
+         vservers_running $vserver
          if [ $? -ne 0 ]; then
             warning "The vserver $vserver is not running."
             continue
          fi
          # is $packagemgr available inside $vserver ?
-         if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
+         if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
             warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
-            continue
+         else
+            # don't expand * since it can be used in $packagemgroptions
+            set -o noglob
+            debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
+           $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
+            set +o noglob
+         fi
+         # is $debconfgetselections available inside $vserver ?
+         found=no
+         # case #1: it is available on the host, is it available inside $vserver ?
+         if [ -n "$debconfgetselections" ]; then
+            [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
+         # case #2: it is not available on the host, is it available inside $vserver ?
+         else
+            [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
          fi
-         # don't expand * since it can be used in $packagemgroptions
-         set -o noglob
-        debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
-        $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
-         set +o noglob
+         if [ "$found" != yes ]; then
+            warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
+         else
+            debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
+            $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
+         fi
+         unset found
       done
    fi
    
@@ -122,7 +154,12 @@ if [ "$packages" == "yes" ]; then
       $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
       set +o noglob
    fi
-
+   if [ -z "$debconfgetselections" ]; then
+      warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
+   else
+      debug "$debconfgetselections > $selectionsfile"
+      $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
+   fi
 fi
 
 ## System report ##############################
@@ -160,10 +197,12 @@ catiffile () {
 } 
 
 catifexec () {
-   echo $HASHES >> $sysreportfile
-   echo "# $STATUS" >> $sysreportfile
-   echo $HASHES >> $sysreportfile
-   $1  >> $sysreportfile 2>&1 || info "executing of $1 failed"
+   if [ -x $1 ]; then
+      echo $HASHES >> $sysreportfile
+      echo "# $STATUS" >> $sysreportfile
+      echo $HASHES >> $sysreportfile
+      $*  >> $sysreportfile 2>&1 || info "executing of $1 failed"
+   fi
 }
    
 
@@ -187,7 +226,7 @@ catifexec "/bin/df" "-al"
 
 STATUS="Collecting what services run at what run level:"
 if [ $os = "redhat" ]; then
-   catifexec "/sbin/chkconfig --list"
+   catifexec "/sbin/chkconfig" "--list"
    STATUS="Collecting information about /etc/rc.d:"
    catiffile "/bin/ls /etc/rc.d/rc*.d/"
 
@@ -206,7 +245,7 @@ elif [ $os = "debian" ]; then
 fi
 
 STATUS="Getting bootloader information:"
-catifexec "/bin/ls -alR /boot"
+catifexec "/bin/ls" "-alR /boot"
 
 # This covers sparc, alpha, and intel (respectively)
 # updated for grub -mpg
@@ -221,7 +260,7 @@ fi
 if [ -f /etc/lilo.conf ]; then
   STATUS="Collecting information about the boot process (lilo):"
   catiffile "/etc/lilo.conf"
-  catifexec "/sbin/lilo -q"
+  catifexec "/sbin/lilo" "-q"
 fi
 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
   STATUS="Collecting information about the boot process (grub.conf):"
@@ -247,13 +286,13 @@ STATUS="Gathering sysctl information (/etc/sysctl.conf):"
 catiffile "/etc/sysctl.conf"
 
 STATUS="Gathering IP information (/sbin/ifconfig):"
-catifexec "/sbin/ifconfig -a"
+catifexec "/sbin/ifconfig" "-a"
 
 STATUS="Gathering additional IP information (/bin/ip addr list):"
-catifexec "/bin/ip addr list"
+catifexec "/bin/ip" "addr list"
 
 STATUS="Checking network routes:"
-catifexec "/sbin/route -n"
+catifexec "/sbin/route" "-n"
 
 STATUS="Collecting Name Service Switch config information:"
 catiffile "/etc/nsswitch.conf"
@@ -272,12 +311,9 @@ catifexec "/sbin/lsmod"
 for x  in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null 
 ) ; do
   STATUS="Checking module information $x:"
-  catifexec "/sbin/modinfo  $x"
+  catifexec "/sbin/modinfo" "$x"
 done
 
-STATUS="Currently getting ksysms information:"
-catifexec "/sbin/ksyms"
-
 STATUS="Gathering information about your filesystems:"
 catiffile "/proc/filesystems"
 
@@ -288,7 +324,7 @@ STATUS="Gathering information about your partitions:"
 catiffile "/proc/partitions"
 
 STATUS="Gathering information about your ksyms:"
-catiffile "/proc/ksyms"
+catiffile "/proc/kallsyms"
 
 STATUS="Gathering information about slabinfo:"
 catiffile "/proc/slabinfo"
@@ -355,7 +391,7 @@ STATUS="Gathering information about your ide drivers:"
 catiffile "/proc/ide"
 
 STATUS="Gathering information about your bus:"
-catifexec lspci
+catifexec "/usr/bin/lspci"
 catiffile "/proc/bus"
 
 echo
@@ -366,7 +402,7 @@ STATUS="Collecting information from /etc/fstab:"
 catiffile "/etc/fstab"
 
 STATUS="Collecting disk partition information:"
-catifexec "fdisk -l"
+catifexec "/sbin/fdisk" "-l"
 
 STATUS="Checking mounted file systems (mount) "
 catifexec "/bin/mount"
@@ -383,6 +419,9 @@ catiffile "/etc/raidtab"
 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
 catiffile "/etc/mdadm.conf"
 
+STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
+catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
+
 STATUS="Collecting Automount information (auto.master)"
 catiffile "/etc/auto.master"