frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Terence Tao's NSF grants suspended

https://bsky.app/profile/dangaristo.bsky.social/post/3lvc7ldavhk2o
82•xqcgrek2•44m ago•31 comments

Every satellite orbiting earth and who owns them (2023)

https://dewesoft.com/blog/every-satellite-orbiting-earth-and-who-owns-them
158•jonbaer•6h ago•71 comments

Slow

https://michaelnotebook.com/slow/index.html
815•calvinfo•17h ago•194 comments

How to Secure a Linux Server

https://github.com/imthenachoman/How-To-Secure-A-Linux-Server
38•redbell•1h ago•32 comments

Releasing weights for FLUX.1 Krea

https://www.krea.ai/blog/flux-krea-open-source-release
318•vmatsiiako•22h ago•92 comments

How Hyper Built a 1m-Accurate Indoor GPS

https://andrewhart.me/hyper/
18•AndrewHart•2d ago•16 comments

The anti-abundance critique on housing is wrong

https://www.derekthompson.org/p/the-anti-abundance-critique-on-housing
387•rbanffy•14h ago•562 comments

PHP-ORT: Machine learning inference for the web

https://krakjoe.github.io/ort/
58•Bogdanp•2d ago•13 comments

Living with an Apple Lisa [video]

https://www.youtube.com/watch?v=KISxcJ2DydY
28•zdw•3d ago•0 comments

QUIC for the kernel

https://lwn.net/Articles/1029851/
292•Bogdanp•20h ago•197 comments

Ubiquiti launches UniFi OS Server for self-hosting

https://lazyadmin.nl/home-network/unifi-os-server/
333•speckx•20h ago•264 comments

MacBook Pro Insomnia

https://manuel.bernhardt.io/posts/2025-07-24-macbook-pro-insomnia
439•speckx•22h ago•203 comments

“No tax on tips” is an industry plant

https://www.newyorker.com/magazine/2025/08/04/no-tax-on-tips-is-an-industry-plant
148•littlexsparkee•14h ago•309 comments

Gemini Embedding: Powering RAG and context engineering

https://developers.googleblog.com/en/gemini-embedding-powering-rag-context-engineering/
244•simonpure•19h ago•82 comments

Show HN: I made a website that makes you cry

https://www.cryonceaweek.com
236•johnnymaroney•4d ago•175 comments

Many countries that said no to ChatControl in 2024 are now undecided

https://digitalcourage.social/@echo_pbreyer/114946559233051667
420•nickslaughter02•1d ago•305 comments

You might not need tmux

https://bower.sh/you-might-not-need-tmux
84•elashri•3h ago•82 comments

Pride Versioning 0.3.0

https://pridever.org/
36•laacz•2h ago•9 comments

Programmers aren’t so humble anymore, maybe because nobody codes in Perl

https://www.wired.com/story/programmers-arent-humble-anymore-nobody-codes-in-perl/
114•Timothee•2d ago•134 comments

Rao Reading Algorithm (2024)

https://raohacker.com/rao-reading-algorithm/
14•surprisetalk•2d ago•6 comments

Show HN: Rewindtty – Record and replay terminal sessions as structured JSON

https://github.com/debba/rewindtty
4•debba•3d ago•4 comments

Show HN: Mcp-use – Connect any LLM to any MCP

https://github.com/mcp-use/mcp-use
130•pzullo•19h ago•61 comments

Raspberry Pi 5 Gets a MicroSD Express Hat

https://www.cnx-software.com/2025/07/28/raspberry-pi-5-gets-a-microsd-express-hat/
76•geerlingguy•4d ago•54 comments

Show HN: AgentMail – Email infra for AI agents

https://chat.agentmail.to/
95•Haakam21•22h ago•59 comments

Face it: you're a crazy person

https://www.experimental-history.com/p/face-it-youre-a-crazy-person
622•surprisetalk•3d ago•332 comments

Show HN: KubeForge – A GUI for Kubernetes YAMLs

https://github.com/kubenote/KubeForge
51•rakeda•9h ago•16 comments

Scientists and engineers craft radio telescope bound for the moon

https://www.bnl.gov/newsroom/news.php?a=122408
32•gnabgib•3d ago•4 comments

Launch HN: Gecko Security (YC F24) – AI That Finds Vulnerabilities in Code

58•jjjutla•20h ago•29 comments

The Math Is Haunted

https://overreacted.io/the-math-is-haunted/
389•danabramov•1d ago•181 comments

Carbon Language: An experimental successor to C++

https://docs.carbon-lang.dev/
132•samuell•21h ago•141 comments
Open in hackernews

How to trigger a command on Linux when power switches from AC to battery

https://dataswamp.org/~solene/2025-05-31-linux-killswitch-on-power-disconnect.html
77•Mr_Minderbinder•1d ago

Comments

Apreche•23h ago
The headline is a bit misleading. I thought it meant it was about triggering a command on a computer that has no power, which is obviously impossible.

What it’s actually about how to automatically automatically trigger a command on a Linux computer (almost certainly a laptop) in the event that it switches from AC power to battery power.

The example given is your laptop is plugged it at a café. Someone steals it, which involves unplugging it from the wall. At the moment it is unplugged it automatically shuts down, locks itself, etc.

I wonder if the same approach will also work for a computer connected to a UPS. Probably not!

nisegami•23h ago
Computers connected a UPS can use tools like NUT or more specific tools like apcupsd. It's much more common to need to know when a UPS powered device switches to battery to trigger stuff than it is to need to know when a laptop switches to battery, so there's a lot more tooling in that area.
netsharc•23h ago
Maybe you know this, but UPSs have signaling software to tell whomever it may concern if it has lost power and is running on battery.

For big servers, the UPS's batteries might only give minutes of power, so they'd listen for such a signal to do an orderly shutdown.

LoganDark•23h ago
"on power disconnection" (event) probably would've worked better than "when disconnected from power" (time period).
1718627440•23h ago
That's exactly how I understood the headline.
Rooster61•22h ago
+1 to this.

This is still a logical use case, but it's not the mental image that immediately got conjured up after reading the title for me.

NooneAtAll3•22h ago
+1?
Rooster61•21h ago
Yes, thank you. Fatfingered
wkjagt•21h ago
It's a way of signaling agreement.
Rooster61•21h ago
They were correcting my initial "1+"
tenthirtyam•19h ago
Shouldn't we programmers be just typing "++"?
yndoendo•9h ago
i++
wildzzz•20h ago
With that example, why not just remove the battery entirely?

As for a UPS, I have a Synology NAS that can monitor an APC UPS over its serial USB port. When the UPS loses power or is told to gracefully shutdown, the NAS also gracefully shuts down.

piperswe•20h ago
> I wonder if the same approach will also work for a computer connected to a UPS. Probably not!

Considering that my UPS appears as a battery in KDE when I plug the USB cable in, I wouldn't be surprised if it's treated the same as a laptop battery across most of the stack

telotortium•20h ago
Was the title changed since this comment? It now says “How to trigger a command on Linux when power switches from AC to battery”, which seems perfectly clear. I’m guessing “from AC to battery” was not present initially?
nemomarx•19h ago
Yeah, it was when disconnected from power at first
mrheosuper•10h ago
>. Someone steals it, which involves unplugging it from the wall. At the moment it is unplugged it automatically shuts down

You could achieve same thing if you unplug your battery.

ajross•23h ago
So for those who want the tl;dr: The answer is just "use a udev rule".

Udev is one of those classic open source tools that is immensely powerful and gracefully well designed, with all sorts of emergent power...

...that ends up being an obscure bit of graybeard prestidigitation purely because of it's awful syntax.

No really, there's a very clean mapping between the state in sysfs and the resulting uevents produced. You just can't tell because of the way it looks.

M95D•16h ago
If you don't like udev (and I don't blame you, I hate it too), you can do the exact same thing with mdev or acpid.
ajross•8h ago
Oh, I like udev! I'm just sad that so few people know anything about how sysfs/uevents/udev work, because it seems so ugly and arcane when you're exposed to your first udev rule.
sigwinch•23h ago
udev is useful for customizing all sorts of ergonomics. My example: when my keyboard/mouse switches from one machine to another, control signals are sent to each monitor. This mimics a very expensive 8k DisplayPort KVM.

So that’s an option rather than power. Devise where you’d place a YubiKey on an extension cord, with its removal triggering logout and shutdown.

Const-me•22h ago
Interestingly, a few months ago I wanted a similar thing for Windows. Ended up developing a simple tray utility for that. Probably the most important method is the handler of WM_POWERBROADCAST message: https://github.com/Const-me/SleepOnUnplug/blob/0.4/SleepOnUn...
sgt•21h ago
On macOS this is elegant and efficient by listening to OS level notifications into userland. Tapping into IOKit - namely IOPowerSources and IOPSNotificationCreateRunLoopSource - is trivial and will notify you when there is a power source event.

I believe Windows has something similar - also an event.

masom•19h ago
This is pretty much what this solution does, but through udev.

Systemd, D-Bus, and udev can be used separately or together to make this easier to listen in userland, it will just be dependent on your distribution or setup.

The kernel essentially flags the power source through udev, and the rule triggers the script. That can be done programmatically instead of a script as well. libudev is there for that: https://www.freedesktop.org/software/systemd/man/latest/libu...

https://wiki.archlinux.org/title/Udev (userland /dev is what udev does)

jahrichie•20h ago
I use an APC with a management cable, triggers graceful shutdown and startup on reconnection. It also e-mails me and stores a log. I prefer this approach so 99% of ecosystem isn't on the server, you can let your server do server things and not be the battery police.
hamandcheese•20h ago
How does it trigger the shutdown? Does it have a power switch connection to the motherboard?
treve•20h ago
shutdowns can be done in software like 'sudo systemctl halt', so it doesn't need a line straight to the motherboard. That's the desired path because it lets running applications gracefully close and finish writing to disk.
e40•18h ago
Yep, I have used apcupsd on Linux, Windows and macOS for more than a decade. It’s been triggered many times, too!
ge96•20h ago
I remembering profiling battery life on a chromebook that I put GalliumOS on. When it would be on timestamp, off timestmap and then it would tally up runtime in hours/minutes, nasty bash
Theodores•19h ago
It is interesting how laptops, whether running a consumer operating system or Linux, are poorly protected from theft. There is the Kensington lock hole that nobody uses and that is about it. Really, any laptop needs to be a brick without the magic password or bio-id, if the owner has configured it to be so when stolen, as identified by a change of power source or other cause.

As it is, all you need is a screwdriver to take out the disc, put it in another box, format it and put it back. Then you have a machine good to sell on eBay.

NFC could be another way of protecting a PC so you need your phone to unlock it.

PCs used to have a low grade lock on them originally, that locked the power button and disks behind a flimsy piece of plastic. This feature was soon dropped.

Clearly the market does not demand theft proofing. Otherwise we would have a little bit more than noble efforts like this udev script.

Doohickey-d•19h ago
M1 Macs are more theft-proof than most: it's useless if it's attached to someone else's iCloud account.

It even has parts pairing, so the e.g. the screen has some features disabled if you swap it.

jauntywundrkind•14h ago
There's much much better Secure Boot and encrypted disk options than there used to be, which is good!!

But it does feel like the security regime is pretty lax. I feel like some BLE tracker system is a natural fit for laptops. I'd love a motion sensor alarm built in.

Framework laptop's embedded controller is open source, run Zephyr. I don't think there's a ton of peripherals it has access too, but I love the idea that one could potentially make their own firmware that has their own security designs built in.

gorgoiler•19h ago
Pah! Shut the system down like a real BOFH! Use the Magic SysRq Key interface to instantly crash the system:

  echo 1 > /proc/sys/kernel/sysrq
  echo o > /proc/sysrq-trigger
https://docs.redhat.com/en/documentation/red_hat_enterprise_...
47282847•17h ago
Wouldn’t this potentially leave e.g. disk encryption keys in memory?
kees99•2h ago
You'd probably want to do the filesystem unmount dance first:

  echo 1 > /proc/sys/kernel/sysrq
  echo u > /proc/sysrq-trigger
  dmesg --follow \
  | grep -qm1 'Emergency Remount complete'
  echo o > /proc/sysrq-trigger
...least putting a bit too much trust in ext4/btrfs/zfs journalling.
jauntywundrkind•14h ago
That's neat, I'd never considered one could use udev reactively like this! Very nice.

Not nearly as elegant, but I keep running into problems where I want to run some command when X happens. I've been trying to lean into systemd, creating a service for whatever it is I want run (perhaps just a oneshot if it's a a one off command). Then have a separate program that detects for the desired condition (polling?) and runs systemd-notify to signal that it's healthy. Then you can just BindTo=, so that the desired command runs whenever the condition-detector thing goes green.

PeterStuer•4h ago
I'm using NUT ( https://networkupstools.org/index.html ) to distribute the backup power events from the one usb connected system to all other machines relying on the batteries.

Works pretty well so far.