1

Running Ubuntu 18.04 on an older Dell machine, one of those mini machines that mounts on the back on a monitor. Thing is, it's a headless system, and I removed the GUI since I won't be needing it anyway.

The PC sleeps after a certain time. Haven't really timed it, but after a while idling, it goes to sleep. I'd like to configure that timing a bit so it works better for this particular case.

Question is: who is issuing that sleep command, and where is the timing configured? Most info sources on power management in ubuntu direct me to gnome-power-manager. But on this machine, there's no GUI, so.. no gnome-power-manager. I've checked ps for sleepd or powerdevil, nothing.

dmesg |grep sleep shows:

[ 5453.702143] ACPI: Preparing to enter system sleep state S3
[ 5453.726769]  cache: parent cpu1 should not be sleeping
[ 5453.727509] ACPI: Waking up from system sleep state S3
[10865.469908] ACPI: Preparing to enter system sleep state S3
[10865.492327]  cache: parent cpu1 should not be sleeping
[10865.493067] ACPI: Waking up from system sleep state S3
[16297.564114] ACPI: Preparing to enter system sleep state S3
[16297.586192]  cache: parent cpu1 should not be sleeping
[16297.586924] ACPI: Waking up from system sleep state S3

Anybody know where I can configure this thing?

Also, a few years back (I think it was on Ubuntu 14 or so) I remember I used to have a power management package for the command line, which was really nice. You could set sleep, hibernate, etc. time in a config file, and you could also create conditions for no sleep... worked like a charm. I remember I used to have a condition where the system wouldn't sleep if a program called "stayawake" was running. So when I needed it to stay on, I would just run a blank endless script called "stayawake" and that was that. But, I can't remember what package it was. Can anyone refresh my memory?

Stgauss
  • 31

2 Answers2

2

Found it! Turns out it was the oldest trick in the book: logind. I'd been there a whole bunch of times when tweaking sleep events on laptops, I hadn't thought of going there until today.

I happened to be looking at the PC, and at that precise moment it went to sleep. So I brought it back up, looked through syslog, and saw:

Jul 12 13:01:07 mediapc systemd[1]: Reached target Sleep.
Jul 12 13:01:07 mediapc systemd[1]: Starting Suspend...

A Google search for "systemd reached target sleep" took me to this blogpost from 2018, on Debian. But Debian's a relative of Ubuntu, so I though I'd give it a read.

Then I checked /etc/systemd/logind.conf and found:

IdleAction=suspend
IdleActionSec=90min

Another look through the syslog file, I found that sure enough, the sleep events were ocurring at 90 minute intervals. So I gave it a savage tweak:

IdleAction=poweroff
IdleActionSec=10min

And rebooted. And sure enough, 10 minutes later, the system powered off.

Finally I set the lines in /etc/systemd/login.conf to:

IdleAction=suspend
IdleActionSec=180min

So now my system sleeps after 3 hours of inactivity.

The other power management package I was looking for, I believe, was powernap. That one lets you not only set sleep event times, but also events to keep from sleeping. So, in the future I'll probably end up disabling the event in logind, and letting powernap do all the handling.

Stgauss
  • 31
  • 1
    That's all good except your server will suspend even though someone is signed on and typing in the terminal or running a job: https://askubuntu.com/questions/1256363/shutdown-ubuntu-server-when-idle/1256386#1256386 – WinEunuuchs2Unix Jul 12 '20 at 23:37
  • 1
    BTW that script I wrote was recently upgraded on July 6, 2020 but I haven't updated the linked answer yet. – WinEunuuchs2Unix Jul 12 '20 at 23:46
  • Nice, gonna try it out, because you're right. I have to keep waking the machine if I'm still using it. Makes for some annoying interruptions while streaming movies. – Stgauss Jul 14 '20 at 17:08
0

Use dconf. It is a commandline tool that will show and set all necessary values for gnome.

In your case execute in a terminal session (no GUI involved)

dconf write /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout 0

should help.

The alternative is to set:

dconf write /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type "'nothing'"

Observe the dashes ....

This is for ac only. Replace ac with batteryif needed

You should be aware, that there are native server installations that have that setting already correct. But once installed, this should be the fastest way out...

kanehekili
  • 6,402
  • But there's no GUI running at the present on the system. It just boots to command line, and works at command line all the time. Does dconf still apply in that case? – Stgauss Jul 04 '20 at 22:31
  • yes. dconf is a command line tool, NOT gui. That's what i wrote in my first line... The GUI part would be dconf.editor. But you said explicitly you don't have a gui – kanehekili Jul 04 '20 at 22:48
  • Problem is, I don't have a /org directory, or a settings-daemon directory, or a gnome directory for that matter.

    If it helps, here's the output from lsb_release:

    No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.4 LTS Release: 18.04 Codename: bionic

    It's an ubuntu desktop installation.

    – Stgauss Jul 05 '20 at 14:38
  • Ok, but dconf is a registry, so you don't need a "directory". Since you have Ubuntu installed check what you get with: dconf read /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type. – kanehekili Jul 05 '20 at 17:34
  • Cool, would have never imagined it was a registry from the command format. Output is nothing... no errors, but no other output either. Tried "dconf list /org/" to see what I could find there... nothing either. – Stgauss Jul 05 '20 at 20:06
  • From syslog, ACPI messages are coming from the kernel, nothing interesting there. Couple of sleep messages are coming from systemd-sleep, but I'm not sure if there's something in systemd that could define time before sleep. From what I've seen, systemd is just the guy saying "go to sleep" after someone else tells it to say that. – Stgauss Jul 05 '20 at 20:11