You are not logged in.
Pages: 1
Topic closed
I configured logind to susped the computer when it's idle for some time. That works reasonable well when i'm working with it, but file serving with samba is not detected as activity. The man page of logind service says it makes use of the idle status that is reported by the user session. What does that mean? Is there a way to reset that idle status?
/etc/systemd/logind.conf:
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# See logind.conf(5) for details
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
HandlePowerKey=suspend
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
IdleAction=suspend
IdleActionSec=15min
Last edited by mash (2014-02-10 22:07:13)
Offline
The idle status is probably passed by some sort of dbus mechanism. I saw a button for this in transmission. I don't think that samba has this feature (yet).
What you could do is creating a new service in /etc/systemd/system which checks for Samba activity and fails if there is:
[Unit]
Description=Inhibit suspend in case of samba activity
Before=sleep.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'"
[Install]
RequiredBy=sleep.target
I quickly adapted this with one of my own scripts. You might need to tweak it before it will even work.
EDIT: If you call it /etc/systemd/system/dontkillsamba.service , then you have to do:
systemctl enable dontkillsamba.service
for it to work.
Last edited by Rexilion (2014-02-10 12:03:43)
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Thank you so much, that helped a lot! Didn't notice that it is that easy to hook into these targets. Cool thing..
Again Thanks.. will save me some money..
Last edited by mash (2014-02-11 09:49:06)
Offline
Really, that worked? nice! . Did you have to adapt the above script to make it work or did it just work as is?
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Nope.. I just did some ajustment to grep because i like the idea better to grep for my internal ip range.. but that was all..
with Wake on Lan to remotely power the maschine up and this suspend thingy it's all i needed.
Offline
Hi, i'm using my arch pc as a file server for my xbmc FireTv, and it's really annoying that my pc goes to sleep after "x" time
so i tried the "dontkillsamba" service but it gives me this error
This is the systemctl status
dontkillsamba.service - Inhibit suspend in case of samba activity
Loaded: loaded (/etc/systemd/system/dontkillsamba.service; enabled)
Active: failed (Result: exit-code) since vie 2014-10-31 22:34:12 ART; 6min ago
Process: 6037 ExecStart=/usr/bin/sh -c ! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*' (code=exited, status=1/FAILURE)
Main PID: 6037 (code=exited, status=1/FAILURE)
oct 31 22:34:12 A10 systemd[1]: dontkillsamba.service: main process exited, code=exited, status=1/FAILURE
oct 31 22:34:12 A10 systemd[1]: Failed to start Inhibit suspend in case of samba activity.
oct 31 22:34:12 A10 systemd[1]: Unit dontkillsamba.service entered failed state.
my pc doesn't go to sleep but the conection to the file server gets lost for a bit.
Any Ideas?
Offline
Did you try the command from the commandline?
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Did you try the command from the commandline?
Rexilion Thanks for the reply!
I tried from diferent ways. this is the result (i was streaming from xbmc via samba when i did this)
[sa@A10 ~]$ sudo smbstatus -nb | tail -n +5 | grep '^[0-9]*'
1078 1000 100 10.0.0.101 (ipv4:10.0.0.101:45883)
1077 1000 100 10.0.0.101 (ipv4:10.0.0.101:45882)
here without quiet grep
[sa@A10 ~]$ sudo /usr/bin/sh -c ! smbstatus -nb | tail -n +5 | grep '^[0-9]*'
[sa@A10 ~]$
as in dontkillsamba.service
[sa@A10 ~]$ sudo /usr/bin/sh -c ! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'
[sa@A10 ~]$
without (!) ?
[sa@A10 ~]$ sudo /usr/bin/sh -c smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'
[sa@A10 ~]$
Offline
The failing is intended. The service fails if samba is busy -> no s2disk.
If it succeeds, then samba is idle -> exec s2disk.
The disruption is caused by systemd restarting samba??? (I don't know).
Baseline: It's working as intended.
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Yes, i think that systemd restarts samba, but i dont know how to prevent that.
i think this is the cleanest way to do this,
the other option will be a cronjob that makes a keypress or something to prevent the suspension if samba is busy....
something like
if smbstatus -nb | tail -n +5 | grep '^[0-9]*' (returns not null)
then
(keypress)
else
(nothing)
but im having trouble with that too.
Any ideas how to do that?
Thanks
Offline
Please note that our magic command is not providing it's intel by /dev/stdout or /dev/stderr output.
Systemd looks at the return code of the last command. Read bash for pipeline and return code semantics.
Also note the exclamation mark at the beginning of the command, it inverts the return code. Do not forget that.
As for your request. This is why I don't like systemd, it does too much. We do not know what's going on 'under the hood'. But for now, you could try to move the .service file earlier up the suspend chain. Something like:
[Unit]
Description=Inhibit suspend in case of samba activity
Before=hibernate.target
Before=hybrid-sleep.target
Before=suspend.target
Before=smbd.service # who knows?
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'"
[Install]
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target
WantedBy=suspend.target
Last edited by Rexilion (2014-11-02 14:30:19)
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Please note that our magic command is not providing it's intel by /dev/stdout or /dev/stderr output.
Systemd looks at the return code of the last command. Read bash for pipeline and return code semantics.
Also note the exclamation mark at the beginning of the command, it inverts the return code. Do not forget that.
As for your request. This is why I don't like systemd, it does too much. We do not know what's going on 'under the hood'. But for now, you could try to move the .service file earlier up the suspend chain. Something like:
[Unit] Description=Inhibit suspend in case of samba activity Before=hibernate.target Before=hybrid-sleep.target Before=suspend.target Before=smbd.service # who knows? [Service] Type=oneshot ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'" [Install] WantedBy=hibernate.target WantedBy=hybrid-sleep.target WantedBy=suspend.target
This .service suspends my pc in the set time. so the other one is better
I tried this one too but still no luck. (pc powerd on but network fails)
also tried to set bigger buffer to xbmc but the problem persist (network conection lost)
[Unit]
Description=Inhibit suspend in case of samba activity
Before=sleep.target
Before=smbd.target
Before=nmbd.target
Before=dbus-org.freedesktop.nm-dispatcher.target
Before=dbus-org.freedesktop.NetworkManager.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'"
[Install]
RequiredBy=sleep.target
Offline
[Unit]
Description=Inhibit suspend in case of samba activity
Before=hibernate.target
Before=hybrid-sleep.target
Before=suspend.target
Before=smbd.service # who knows?
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'"
[Install]
RequiredBy=hibernate.target
RequiredBy=hybrid-sleep.target
RequiredBy=suspend.target
Perhaps a combo of both?
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
[Unit] Description=Inhibit suspend in case of samba activity Before=hibernate.target Before=hybrid-sleep.target Before=suspend.target Before=smbd.service # who knows? [Service] Type=oneshot ExecStart=/usr/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'" [Install] RequiredBy=hibernate.target RequiredBy=hybrid-sleep.target RequiredBy=suspend.target
Perhaps a combo of both?
still gets suspended
i'm under gnome shell but i'm going to change DE to kde soon... kde has a LOT of power options maybe with it i'll solve this. ¿?
Thanks for the reply!
Offline
i'm on KDE now and the error persist changing every energy option available... BUT... i get a status message that notfies that's not samba stoping. it's my ethernet port that's down and up in less than 5 seconds. but it's enough for xbmc to stop working after the buffer consumes.
Any ideas how to prevent systemd to stop my ethernet conection before suspension?
Offline
i'm not into this issue at all, but the comment on the same line in systemd "Type" field makes it just ignores the whole line, so i'd write this instead,(just in case):
# who knows?
Before=smbd.service
Last edited by kokoko3k (2014-11-11 19:33:29)
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
i'm not into this issue at all, but the comment on the same line in systemd "Type" field makes it just ignores the whole line, so i'd write this instead,(just in case):
# who knows? Before=smbd.service
Yes, I noticed that.
also i tried adding the Before=systemd-networkd.target and RequiredBy=systemd-networkd.target
but no luck
Any Ideas?
Offline
I'm a bit late to the party, but since this still is one of the first returned results when searching for this issue id like to share my solutions.
dbus SimulateUserActivity
This will simulate user activity and reset the suspend timeout, you can invoke this method with:
qdbus org.kde.screensaver /ScreenSaver SimulateUserActivity
qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
dbus-send --print-reply=literal --dest="org.freedesktop.ScreenSaver" /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
Different DEs implement different namespaces, the examples above works on Debian 9 with KDE. I suspect the freedesktop one to be the generic one.
The Gnome specific one is:
qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity
Example python script that will connect to dbus:
from dbus import SessionBus
foo = True
if foo:
session = SessionBus()
screensaver = session.get_object('org.freedesktop.ScreenSaver', '/org/freedesktop/ScreenSaver')
screensaver.SimulateUserActivity()
Unfortunately this doesn't work for Ubuntu 18.04, both freedesktop and gnome namespaces are present but the freedesktop one is not implemented and the gnome one doesn't provide SimulateUserActivity.
qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
Error: org.freedesktop.DBus.Error.NotSupported
This method is not implemented
systemd-inhibit
This will create a inhibit lock that will persist as long as the script is running. A custom script would need to perform a loop until the condition is resolved, exit, and ultimately remove the lock.
systemd-inhibit --what=sleep --who="me" --why="because i can" --mode=block command
Scheduling could be done with systemd-run. This will create a systemd timer and a unit file that is executed every 15 minutes:
systemd-run --user --on-calendar="*:0/15" systemd-inhibit --what=sleep --who="me" --why="because i can" --mode=block command
Systemd will only start a new instance if the previous one has exited.
Timers created with systemd-run will not survive a reboot, you would have to recreate then with a startup script or write your own unit/timer combo.
Offline
Thanks for the relevant and informative contribution, however as it is an old thread I'm going to close it now.
If you want to archive this more visibly, you might want to contribute this info on the wiki.
Offline
Pages: 1
Topic closed