Re: Suspend to RAM

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

 



On Wed, 15 Dec 2004 15:35:49 -0600 (CST), Satish Balay
<balay@xxxxxxxxxxx> 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
running.

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:
#!/bin/sh

# 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`
                        done
                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|127.0.0.1:|: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|127.0.0.1:|:80 |:443 |:6000 )'
`"
                        done
                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
else
        echo 'No network; skipping checks'
        fi

# 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
        apm

        # 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...'
                fi

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

        fi

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

        echo "Press enter to revive"
        read

        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
                do
                echo "Looking for $TRY network"
                /usr/local/etc/iwkey $TRY
                if dhcpcd -t 10 eth0 ; then break ; fi
                done

        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 127.0.0.1:25.  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


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux