"Screensaver" without Xserver or DE

There is a laptop with OpenSUSE Slowroll installed as minimal server configuration without any display server or desktop environment

  1. How to automatically turn off a monitor which connected to a computer after some timeout on an idle computer?
  2. How to make OS not to send the computer to hibernation or sleep mode when after its lid been close?

@Owlsun Hi, so for 1. Why have a monitor connected, any management can be done remotely? Is this a laptop based on your second question? I have a remote laptop, I use consoleblank grub option as I don’t need access.

For 2. edit /etc/systemd/logind.conf and uncomment the line HandleLidSwitch and change to ignore

Because it is a laptop.

@Owlsun so do you need access to it once the lid is closed, or can work via ssh etc?

Yes, I need to use it as a nextcloud “server” and to manage it via ssh.

@Owlsun then I would use consoleblank=100 (is what I use and I close it) in the grub kernel options.

There is no “etc/systemd/logind.conf” on my system, but there is a “/usr/lib/systemd/logind.conf”.
I made there the following change:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

but the system steel going to suspend when i close the lid.
Even after sudo systemctl restart systemd-logind.

I managed to disable sleep, suspend and hibernate completely with:

systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

source: How to Disable Suspend and Hibernation Modes In Linux

Now the laptop stay awake when I close the lid but I get journalctl polluted with endless entries like:

Dec 23 22:46:32 msi systemd-logind[10191]: Suspending...                                                                                                                                      
Dec 23 22:46:32 msi systemd-logind[10191]: Unit suspend.target is masked, refusing operation.                                                                                                 
Dec 23 22:46:32 msi systemd-logind[10191]: Failed to execute suspend operation: Permission denied   

@Owlsun that’s not right, disable and mask the service associated with the target,
eg

systemctl stop systemd-suspend.service
systemctl disable systemd-suspend.service
systemctl mask systemd-suspend.service
....
systemctl list-unit-files --state=masked

systemd-hibernate.service                       masked disabled     
systemd-hybrid-sleep.service                    masked disabled     
systemd-suspend.service                         masked disabled 

I wasn’t been able to disable systemd-suspend.service

> sudo systemctl disable systemd-suspend
Unit /etc/systemd/system/systemd-suspend.service is masked, ignoring.
The unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,
Also=, or Alias= settings in the [Install] section, and DefaultInstance= for
template units). This means they are not meant to be enabled or disabled using systemctl.
 
Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.

But I could mask it.
When I closed the lid the computer stayed awake but disconnected the network:

Dec 24 18:24:41 systemd-logind[1101]: Lid closed.
Dec 24 18:24:41 systemd-logind[1101]: Suspending...
Dec 24 18:24:41 ModemManager[1193]: <info>  [sleep-monitor-systemd] system is about to suspend
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.7605] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.7609] device (wlp2s0): state change: unavailable -> unmanaged (reason 'sleeping', sys-iface-state: 'managed')
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.7621] device (wlp2s0): set-hw-addr: reset MAC address to  (unmanage)
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.7642] manager: NetworkManager state is now ASLEEP
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.7646] device (enp3s0): state change: activated -> deactivating (reason 'sleeping', sys-iface-state: 'managed')
Dec 24 18:24:41 dbus-daemon[1081]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.5' (u>
Dec 24 18:24:41 systemd[1]: Starting Network Manager Script Dispatcher Service...
Dec 24 18:24:41 dbus-daemon[1081]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Dec 24 18:24:41 systemd[1]: Started Network Manager Script Dispatcher Service.
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8249] device (enp3s0): state change: deactivating -> disconnected (reason 'sleeping', sys-iface-state: 'managed')
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8276] dhcp4 (enp3s0): canceled DHCP transaction
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8277] dhcp4 (enp3s0): activation: beginning transaction (timeout in 45 seconds)
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8277] dhcp4 (enp3s0): state changed no lease
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8279] dhcp6 (enp3s0): canceled DHCP transaction
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8280] dhcp6 (enp3s0): activation: beginning transaction (timeout in 45 seconds)
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8280] dhcp6 (enp3s0): state changed no lease
Dec 24 18:24:41 NetworkManager[1202]: <info>  [1703435081.8647] device (enp3s0): state change: disconnected -> unmanaged (reason 'sleeping', sys-iface-state: 'managed')
Dec 24 18:24:41 kernel: r8169 0000:03:00.0 enp3s0: Link is Down

@Owlsun reverse the masks you added and leave the target ones alone, then disable and mask the others should sort that out.

For NetworkManager, you will probably need to add some config options…