#!/bin/sh # Mount a persistent storage in DLS Live CD. # # chkconfig: 2345 11 89 # description: DLS LiveCD Utility # Source function library. . /etc/rc.d/init.d/functions MOUNT_DIR='/mnt/storage' NAME="dlscdmount" get_partitions() { cat /proc/partitions | tail +3 | grep -v loop | awk '{print "/dev/"$4;}' } # Start this script. start() { #gprintf "Starting ${NAME}: " test -d $MOUNT_DIR || mkdir $MOUNT_DIR # Make sure that all disk partitions are not mounted. This is necessary because the initrd produced by mklivecd # mounts some partitions automatically. for partition in `get_partitions`; do cat /proc/mounts | grep "^$partition" | cut -f2 -d' ' | xargs -r umount done # Find a dls partition. for partition in `get_partitions`; do if mount -o ro $partition $MOUNT_DIR 2>/dev/null; then if test -f $MOUNT_DIR/.dlscd; then # Found. . $MOUNT_DIR/.dlscd umount $MOUNT_DIR break else umount $MOUNT_DIR fi fi done # Mount the storage. if test "x$storage_name" = "x"; then true else # Detect RAID devices automatically. if echo $storage_name | grep -q md; then echo 'DEVICE /dev/hd*[0-9] /dev/sd*[0-9]' > /etc/mdadm.conf /sbin/mdadm --examine --scan --config=/etc/mdadm.conf >> /etc/mdadm.conf /sbin/mdadm --assemble --scan fi if mount -o rw $storage_name $MOUNT_DIR; then cp -f $MOUNT_DIR/config.xml /home/dlsadmin/nexedi-dls if test -f $MOUNT_DIR/passwd -a -f $MOUNT_DIR/group; then /usr/sbin/dlscd_fixid $MOUNT_DIR/passwd $MOUNT_DIR/group /etc/passwd /etc/group $MOUNT_DIR/var rm -f $MOUNT_DIR/passwd $MOUNT_DIR/group fi cp -f /etc/passwd $MOUNT_DIR cp -f /etc/group $MOUNT_DIR rm -rf $MOUNT_DIR/var/lock/* cp -a /var/lock/* $MOUNT_DIR/var/lock/ rm -rf $MOUNT_DIR/var/run/* cp -a /var/run/* $MOUNT_DIR/var/run/ mount --bind $MOUNT_DIR/var /var # See if Upgrade is necessary if [ ! -e /var/log/upgrade.log ]; then touch /var/log/upgrade.log fi if [ -e $MOUNT_DIR/nexedi-release ]; then Old_Vers=`cat $MOUNT_DIR/nexedi-release` New_Vers=`cat /initrd/loopfs/etc/nexedi-release` if [ "$Old_Vers" != "$New_Vers" ]; then gprintf "Upgrade Detected" gprintf "see /var/log/upgrade.log for result" date >> /var/log/upgrade.log echo "Upgrade Detected !" >> /var/log/upgrade.log /bin/sh /home/dlsadmin/nexedi-dls/Upgrade.sh 1>>/var/log/upgrade.log 2>>/var/log/upgrade.log cp -f /initrd/loopfs/etc/nexedi-release $MOUNT_DIR/ fi else gprintf "Upgrade Detected" gprintf "see /var/log/upgrade.log for result" date >> /var/log/upgrade.log echo "Upgrade Detected !" >> /var/log/upgrade.log /bin/sh /home/dlsadmin/nexedi-dls/Upgrade.sh 1>>/var/log/upgrade.log 2>>/var/log/upgrade.log cp -f /initrd/loopfs/etc/nexedi-release $MOUNT_DIR/ fi # Make a lock file. touch /var/lock/subsys/dlscdmount exit fi fi # Failed. exit 1 } # Stop this script. Quite simple. Just stop services and unmount the filesystem. stop() { #gprintf "Stopping ${NAME}: " if test -f $MOUNT_DIR/.dlscd; then . $MOUNT_DIR/.dlscd # Backup /etc before shutdown tar czf $MOUNT_DIR/etc.tar.gz /etc chmod 600 $MOUNT_DIR/etc.tar.gz if umount /var 2>/dev/null; then rm -rf /var/* cp -a $MOUNT_DIR/var/* /var/ fi home=/home/$host_id umount $home 2>/dev/null umount $MOUNT_DIR 2>/dev/null fi # Remove the lock file. rm -f /var/lock/subsys/dlscdmount } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) gprintf "Usage: %s {start|stop|restart}\n" "$0" exit 1 esac