Protecting my sleep

My another attempt to break the habit of being up until very late into the night and as such very tired the next day.

For years I thought of configuring my computer to suspend at around night time so I will be somehow forced to go to sleep. Well, the main problem with this was that I only thought about it and never actually did any research on this subject.

At normal times under my normal user I suspend my machine with elogind loginctl command and this works fine but there might be a problem with sessions and stuff around that which I refuse to work with. So I searched a bit and found out that there is nice system API to manage power state.

The system/kernel API consist of a file located at /sys/power/state.
When I try to print the content of this file it shows the currently available states (or values it accepts) which is my case are:

$ cat /sys/power/state
freeze mem disk

And when I looked at the printed values I saw mem option which is probably what I want (I was lazy and did not look at any docs) to suspend my machine into RAM. The power state can be changed by writing desired state into /sys/power/state file.

$ echo "mem" > /sys/power/state

Sure, you need to be root to do so, but so what? This is my machine and I can. Since I figured this out I put it into a file, set it executable and configured cron to start it at 23:00 from Sunday to Thursday like this.

0 23 * * 0-4 root /usr/scripts/suspend

And done, now I hope it can help me get my desired rest.

Articles from blogs I follow:

Why is your open source project still hosted on GitHub?

Perhaps the younger generation don't know anything about the past "evils" of Microsoft and naively believe that Microsoft is now the good friend to open source, but the truth is that all Microsoft acquisitions of open source projects is a busi…

via unixdigest.com May 22, 2025

StarFive VisionFive v2 and FreeBSD

This week I powered up the StarFive VisionFive v2 board that I have. I figured I would give FreeBSD another whirl on it, in the vague hope that RISC-V boards are a more cohesive family than ARM boards were five years ago. tl;dr: I didn’t get it to work as…

via [bobulate] May 20, 2025

Steve Ballmer was an underrated CEO

There's a common narrative that Microsoft was moribund under Steve Ballmer and then later saved by the miraculous leadership of Satya Nadella. This is the dominant narrative in every online discussion about the topic I've seen and it's a commo…

via danluu.com October 28, 2024

Generated by openring