#!/bin/bash # swsusp - invokes software suspend # # Configuration # # mounts, interfaces, and modules are all strings with single quotes. # If there is more than one item in the list, then seperate it by spaces. # see UMOUNTS below for the best example. # These mount points should be umounted before suspend UMOUNTS='/mnt/floppy /mnt/cdrom /mnt/ntfs' # These interfaces should be stopped before suspend DOWNIFS='eth0 eth1' # These modules should be removed before suspend REMOVEMODS='serial' # These mount points should be mounted after suspend # (provided that they were umounted) REMOUNTS='/mnt/ntfs' # These interfaces should be started after suspend # (provided that they were stopped) UPIFS='eth0 eth1' # These modules should be loaded after suspend # (provided that they were removed) INSERTMODS='serial' # # Generally, there's no need to modify below this comment # T_MNTS= T_IFS= T_MODS= T_GPM="no" T_PCMCIA="no" echo Preparing to suspend... # Shared mounnts for MNT in `echo $UMOUNTS` do if [ `/bin/mount | grep -c " $MNT "` = 1 ]; then echo Unmounting $MNT umount $MNT if [ `echo $REMOUNTS | grep -c $MNT` = 1 ]; then T_MNTS="$T_MNTS $MNT" fi fi done # smbfs (Samba over network) for MNT in `mount | grep " smbfs "` do MNTPLC=`echo $MNT | cut -d \ -f 3` echo Unmounting $MNTPLC umount $MNTPLC done # nfs (Network File System) for MNT in `mount | grep " nfs "` do MNTPLC=`echo $MNT | cut -d \ -f 3` echo Unmounting $MNTPLC umount $MNTPLC done # interfaces for IF in `echo $DOWNIFS` do if [ `/sbin/ifconfig | grep -c "^$IF "` = 1 ]; then echo Bringing $IF down /etc/sysconfig/network-scripts/ifdown $IF if [ `echo $UPIFS | grep -c $IF` = 1 ]; then T_IFS="$T_IFS $IF" fi fi done # modules for MOD in `echo $REMOVEMODS` do if [ `/sbin/lsmod | grep -c $MOD` = 1 ]; then echo Removing $MOD /sbin/rmmod $MOD if [ `echo $INSERTMODS | grep -c $MOD` = 1 ]; then T_MODS="$T_MODS $MOD" fi fi done # stop gpm if [ -f /var/lock/subsys/gpm ]; then T_GPM="yes" /etc/init.d/gpm stop fi # stop pcmcia if [ -f /var/lock/subsys/pcmcia ]; then T_PCMCIA="yes" /etc/init.d/pcmcia stop fi # stop named if [ -f /var/lock/subsys/named ]; then T_NAMED="yes" /etc/init.d/named stop fi # stop smb if [ -f /var/lock/subsys/smb ]; then T_SMB="yes" /etc/init.d/smb stop fi #sync the clock echo Syncing to hardware clock /sbin/hwclock --systohc #sync the disk sync #now, do the suspend echo Suspending echo "#########################" echo 1 0 > /proc/sys/kernel/swsusp #wait on resume echo Waiting to resume sleep 5 echo Starting resume #sync the clock echo Syncing from hardware clock /sbin/hwclock --hctosys #start pcmcia if [ $T_PCMCIA == "yes" ]; then /etc/init.d/pcmcia start fi #start gpm if [ $T_GPM == "yes" ]; then /etc/init.d/gpm start fi #modules for MOD in `echo $T_MODS` do echo Adding $MOD /sbin/modprobe $MOD done #interfaces for IF in `echo $T_IFS` do echo Bringing up $IF /etc/sysconfig/network-scripts/ifup $IF done #start named if [ $T_NAMED == "yes" ]; then /etc/init.d/named start fi #start named if [ $T_SMB == "yes" ]; then /etc/init.d/smb start fi #mounts for MNT in `echo $T_MNTS` do echo Mounting $MNT /bin/mount $MNT done echo Done resuming!