7

I'm using Linux Mint Debian v2, 64-bit.

I want the computer to sleep shortly after I stop using it, so I've set the inactivity timeout to 10 minutes.

But, when I'm connected to my computer using my laptop via SSH, even while I'm doing stuff like copying files or watching a video via samba, it goes to sleep.

How can I stop this without changing the sleep time setting? What exactly constitutes "no-activity" for the computer to go to sleep? Perhaps the opposite is easier to explain, what constitutes activity to keep the computer awake?

My laptop is also LMDE v2.

2
  • 1
    Can you add how you configured the inactivity timeout?
    – Bram
    Oct 12, 2015 at 17:43
  • Through the menus: Preferences -> Power Management -> On AC Power tab -> Put the computer to sleep when inactive for.
    – linstar
    Oct 19, 2015 at 11:29

1 Answer 1

4

Init.d all scripts in /etc/pm/sleep.d will be executed before going into sleep-mode and if any of them returns a non-zero state sleep-mode will not be entered.

So you could place a script there that looks for all processes that you wan't to be recogniced as 'PC is still in use' and simply return 1 if any of these are still running - or any other conditions you are able to script.

For ssh you could use netstat -tnpa | grep ESTABLISHED.*sshd to check for open connections and for samba you could parse the output of smbstatus


Edit: If you are using

systemd: create a /etc/systemd/system/dontsleep.service like this

[Unit]
Description=Inhibit suspend in case of [some] activity
Before=sleep.target

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "some command that that returns an failure exit status if you don't want the pc to go into sleep mode (e.g exit 1)"

[Install]
RequiredBy=sleep.target

Now with RequiredBy= & Before=sleep.target your new dontsleep.service has become a dependencie for the sleep.target and systemd can't go into sleep mode until this service executes successfully (e.g. exit 0)

Don't forget to enable it with systemctl enable dontsleep.service

(Idea stolen from here: https://bbs.archlinux.org/viewtopic.php?pid=1380080#p1380080)

6
  • Thanks. It could work, but, I just don't know enough to modify the script in there. I'll have to study it a bit more and get back to everyone if it works.
    – linstar
    Oct 15, 2015 at 3:01
  • Don't modify jus't create a new one... I'll write you an example when I get home today...
    – Fabian N.
    Oct 15, 2015 at 5:43
  • @FabianN. That's one hell of a commute! :p Could you please write up an example? Thank you.
    – Sparhawk
    Feb 16, 2016 at 21:05
  • @FabianN. Oh, I think that /etc/pm/sleep.d is not used in systemd? I'm using Arch Linux, so perhaps this solution won't work for me anyway.
    – Sparhawk
    Feb 16, 2016 at 21:57
  • 2
    @FabianN. Oh brilliant! Excellent theft! :) Works perfectly. FWIW I didn't have netstat but had iproute2 installed, so I used ExecStart=/usr/bin/sh -c "if [ $(ss state established '( dport = 22 or sport = 22 )' | wc -l) -gt 1 ]; then exit 1; else exit 0; fi", which works perfectly
    – Sparhawk
    Feb 17, 2016 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .