[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Suspend to RAM

On Wed, 15 Dec 2004 15:35:49 -0600 (CST), Satish Balay
<balay fastmail fm> wrote:
> ... [suspend to ram]

Here's some stuff that may be useful to folks:

I like to suspend the machine with a command, and not lid close.  I
prefer lid close to put the machine in low power state, but keep it

for my lid close, I do:

if (lid open...)
                killall -CONT mozilla-bin
else (lid closed...)
                killall -STOP mozilla-bin

and for suspend, I do far more:

# usage: $0 [-f] [-n]
# -f = force. no network checks
# -n = not really. do everything but actual suspend

# presumption: eth0 is always the pcmcia.
# my config: builtin ethernet isn't insmod'ed by default, so the system
# just doesn't know it's there.
if ifconfig eth0 >/dev/null 2>&1 ; then

        # check if there is any pending network activity
        if [ " $1" = ' -f' ] ; then
                # -f is specified, skip the network checks
                echo 'Skipping network checks'
                shift 1
        else # no -f found; normal code path

                # check mailq
                MAILQ=`mailq -Ac`
                # rh6.2: while [ "$MAILQ" != 'Mail queue is empty' ] ; do
                # rh7.0: while [ "$MAILQ" != '/var/spool/mqueue is empty' ] ; do
                # rh8.0: while [ "$MAILQ" != '/var/spool/mqueue is empty
#               Total requests: 0' ] ; do
                # rh8.0 client mqueue: (yes, multiline. WHITESPACE IMPORTANT)
                while [ "$MAILQ" != '/var/spool/clientmqueue is empty
                Total requests: 0' ] ; do
                        echo 'mail pending. press enter to retry, or
-f to override'
                        echo "$MAILQ"
                        read LINE
                        if [ "$LINE" = '-f' ] ; then break ; fi
                        MAILQ=`mailq -Ac`
                service sendmail stop

                # check for active tcp connections
                # ignore :25 connections, as the mailq test has that covered
                # ignore web, other 'pending close' states
                # ignore X11 connections. only thing I ever use is x2x
                NETSTAT="`netstat -n --inet 2>&1 | egrep -v '(:25
|TIME_WAIT|FIN_WAIT|CLOS|LAST_ACK||:80 |:443 |:6000 )' `"
                while [ `echo "$NETSTAT" | wc -l` != 2 ] ; do
                        echo 'network connections still active. press
enter to retry, or -f to override'
                        # by default, only print out the filtered netstat
                        echo "$NETSTAT"
                        read LINE
                        if [ "$LINE" = '-f' ] ; then break ; fi
                        NETSTAT="`netstat -n --inet 2>&1 | egrep -v
'(:25 |TIME_WAIT|FIN_WAIT|CLOS|LAST_ACK||:80 |:443 |:6000 )'
                fi # endif cmd line -f

        # shut down networking
        killall dhcpcd
        ifconfig eth0 down
        # sometimes the wired ethernet is there, but since it's not my
        # normal connection, it must've been temporary
        ifconfig eth1 >/dev/null 2>&1 && ifconfig eth1 down
        rmmod 3c59x
        echo 'No network; skipping checks'

# since I can't suspend with 2.4 acpi, additionally disable certain
# daemons because they eat cpu, and thus power
# lpd reads from disk every minute
# fetchmail is how I get my mail. obviously useless if the network is down.
# PAUSE it only
killall -STOP fetchmail

# if I can suspend
if false ; then
        # eject card if possible
        #cardctl eject

        # report on battery condition

        # suspend
        if [ " $1" != ' -n' ] ; then
                sleep 2
                # -n not found; normal code path
                apm --suspend
        else # -n is specified, skip the actual suspend process
                echo 'Not really suspending...'

        # TODO: wait for eth0 to be up! else all below will fail


# if I can acpi low-power
if true ; then
        # enter low power state
        echo 3 >/proc/acpi/sleep

        echo "Press enter to revive"

        echo "Getting new dhcp lease"

        # Work network is doubled, because sometimes the dhcp server
        # isn't responsive.
        # NOTE: you can press ctrl-c to skip over various networks
        # without interrupting this script
        for TRY in any Work Work any Work Work any Work Work
                echo "Looking for $TRY network"
                /usr/local/etc/iwkey $TRY
                if dhcpcd -t 10 eth0 ; then break ; fi


# communicate to the user that eth0 is up now
ifconfig eth0

# resume fetchmail
killall -CONT fetchmail

# kjw hack - I can't send mail directly from my laptop any more because
# of 1- dynamic addresses being blocked and 2- firewall at work, so
# sm-client starts the sendmail client, and an ssh-tunnel to my colo box,
# listening on  This way I can locally queue messages for
# later delivery, yet still deliver through the colo, which is a trusted
# mail server.
#service sendmail start
service sm-client start

service lpd start

# immediately switch back into X
chvt 7

exit 0

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]