Follow

I use on my laptops, so I have a few helper scripts that will run when I suspend and resume the laptop.

All of this is documented in man.openbsd.org/apmd.8 so please check out the documentation in the man page.

/etc/apm/suspend:
/usr/bin/pkill -USR1 -x xidle
# EOF

by sending the USR1 signal to xidle, it will automatically run xlock. When I suspend, my laptop will require a password to get access to X after resume.

(yes, xlock is not 100% secure, but this is a good step)

· · Web · 1 · 6 · 12

my resume script is a bit more complicated.

/etc/apm/resume:
pkill -x ssh ftp
/sbin/ifconfig em0 -inet down
/sbin/ifconfig iwm0 -nwid
/sbin/ifconfig iwm0 lladdr random
(sleep 60; smtpctl schedule all) &

I kill off any ssh and ftp connections immediately, instead of waiting for them to time out.

I down the em0 interface, which I hardly ever use for $reasons.

-nwid will remove any manual wifi config, so auto-join will kick in and join any network I have saved.

(cont)

cont

lladdr random changes my mac address of my network interface, which will trigger new IPv4 and IPv6 addresses for my laptop, hopefully preventing any network-based tracking. (this is also why I pkill ssh and ftp. with new IPs, those *cannot* keep their sessions after I wake.)

I will occasionally write emails on my laptop; so scheduling all email will ensure that everything is pushed out. I sleep 60s there in case I need to play with a captive portal.

by running those two scripts when I suspend (put to sleep) my laptop, and when I resume (wake up) my laptop; I have the behaviours I want to see.

If you want to write your own, keep in mind that the scripts are ran by root with a sanitized environment, and need to be executable.

And to finish this up, I have

apmd_flags=-A -z 5

in my rc.conf.local config file.

This tells apmd to run in automatic performance mode, so it will adjust your cpu frequency up when you are using cpu, and adjust it down when your machine is idle. slower cpu frequencies will save a lot of power, potentially up to another 50%-100% of batt life!

-z 5 will suspend my laptop when battery percentage is below 5. KEEP IN MIND that this value is inexact, and is checked less often than you may hope.

@phessler Thanks for the detail. I'm unfortunately not using my personal laptop anywhere near as much as I would like, and 95% of the time it's used at home, so my needs wrt. suspend/hibernate are not critical at all. However, it's interesting and useful to understand how people with much more demanding requirements set it up :flan_wave:

Sign in to participate in the conversation
BSD Network

bsd.network is a *BSD-adjacent Mastodon Instance. We have a code of conduct.