This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Task Scheduler / pm utils / root password

Tags: None
(comma "," separated)
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Hi.

It's been a while since I used this but I used to put the PC to sleep at a set time and used sudo pm-suspend command in Task Scheduler. Now I notice it doesn't work because it needs the root password. So I'm guessing you can't add anything to "sudo pm-suspend" command in TS and have to alter the sudoers file in /etc/sudoers? I've read an Arch wiki page on it but the page is out of date and opensuse might be different. What is the correct way to do this?

Thanks
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You'll need to adjust the /etc/sudoers file manually i'm afraid in order for Task Scheduler to be able to work. If Task Scheduler is running commands from your session you might also want to consider a command such as the following instead, which does not require root access (but does require a running KDE session):
Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement org.kde.Solid.PowerManagement.suspendToRam


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Thanks, ok so I modified the command to :

Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement org.kde.Solid.PowerManagement.suspendToRam


and ran it from TS and it returned:

Code: Select all
Error: org.freedesktop.DBus.Error.UnknownMethod
No such method 'suspendToRam' in interface 'org.kde.Solid.PowerManagement' at object path '/org/kde/Solid/PowerManagement' (signature '')
-------------------------------------------------------------------------
End of script execution. Type Enter or Ctrl+C to exit.
-------------------------------------------------------------------------


I don't mind editing sudoer if I have to but if it can be done from TS all the better.
wolfi323
Registered Member
Posts
1129
Karma
11
OS
Sundance Kid wrote:Thanks, ok so I modified the command to :

Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement org.kde.Solid.PowerManagement.suspendToRam


and ran it from TS and it returned:

Code: Select all
Error: org.freedesktop.DBus.Error.UnknownMethod
No such method 'suspendToRam' in interface 'org.kde.Solid.PowerManagement' at object path '/org/kde/Solid/PowerManagement' (signature '')
-------------------------------------------------------------------------
End of script execution. Type Enter or Ctrl+C to exit.
-------------------------------------------------------------------------


The correct command should be:
Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/SuspendSession suspendToRam


Or just use "systemctl suspend" instead of "pm-suspend", this should work as user as well.
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Much obliged, first one does indeed now work (not tried second one yet), thanks.

For future reference does the same command apply for suspending to disk? Like..

Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/SuspendSession suspendToDisk


And does this sudoers method still apply? https://wiki.archlinux.org/index.php/pm ... ion_method

Thanks again
wolfi323
Registered Member
Posts
1129
Karma
11
OS
Sundance Kid wrote:For future reference does the same command apply for suspending to disk? Like..

Code: Select all
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/SuspendSession suspendToDisk

Yes, exactly. Or "systemctl hibernate".

And does this sudoers method still apply? https://wiki.archlinux.org/index.php/pm ... ion_method

Yes, except that there's no "power" group on openSUSE AFAICS.
But pm-utils is deprecated, better use the systemctl method I'd say.

PS: You could also have a look at kshutdown:
http://kshutdown.sourceforge.net/
luebking
Karma
0
alternative command (in case you need this outside KDE or don't want to run powerdevil on a desktop box)

Code: Select all
qdbus --system org.freedesktop.login1 /org/freedesktop/login1 Suspend false

resp.
Code: Select all
qdbus --system org.freedesktop.login1 /org/freedesktop/login1 Hibernate false
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Humm, so things take a turn for the weird.

The commands that will run from Task Scheduler work when clicking the Run Now button but left to work at the selected time do not, the command isn't executed or something. I don't see anything untoward, any ideas?
wolfi323
Registered Member
Posts
1129
Karma
11
OS
Sundance Kid wrote:The commands that will run from Task Scheduler work when clicking the Run Now button but left to work at the selected time do not, the command isn't executed or something. I don't see anything untoward, any ideas?

Well, the commands are run by cron (a system daemon), not KDE. So probably they don't find the (user's) DBUS session then.

Have you tried the system bus method luebking posted?
"systemctl xxx" should work as well I suppose, but I'm not sure whether it would have the required permissions when run as user by cron (normally only a user logged in at the active console is allowed to suspend/hibernate).

You could of course also add your command (i.e. either "systemctl suspend" or "pm-suspend") to root's crontab, by launching systemsettings as root:
Code: Select all
kdesu kcmshell4 cron


Or try kshutdown, that seems to offer exactly what you want to achieve.
Packages for openSUSE are available in the KDE:Extra repo:
http://software.opensuse.org/package/kshutdown
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Things is I've got VLC to close using pkill vlc one minute before the suspend is supposed to happen, and that works fine, so just assumed..

When I run (Run Now) qdbus --system org.freedesktop.login1 /org/freedesktop/login1 Suspend false it returns..

Code: Select all
Error: org.freedesktop.DBus.Error.AccessDenied
Rejected send message, 4 matched rules; type="method_call", sender=":1.728" (uid=1000 pid=4011 comm="qdbus --system org.freedesktop.login1 /org/freedes") interface="(unset)" member="Suspend" error name="(unset)" requested_reply="0" destination="org.freedesktop.login1" (uid=0 pid=741 comm="/usr/lib/systemd/systemd-logind ")
-------------------------------------------------------------------------
End of script execution. Type Enter or Ctrl+C to exit.
-------------------------------------------------------------------------


I'll give try crontab in a bit, but does that error message indicate a larger problem?
wolfi323
Registered Member
Posts
1129
Karma
11
OS
Sundance Kid wrote:When I run (Run Now) qdbus --system org.freedesktop.login1 /org/freedesktop/login1 Suspend false it returns..

Code: Select all
Error: org.freedesktop.DBus.Error.AccessDenied
Rejected send message, 4 matched rules; type="method_call", sender=":1.728" (uid=1000 pid=4011 comm="qdbus --system org.freedesktop.login1 /org/freedes") interface="(unset)" member="Suspend" error name="(unset)" requested_reply="0" destination="org.freedesktop.login1" (uid=0 pid=741 comm="/usr/lib/systemd/systemd-logind ")
-------------------------------------------------------------------------
End of script execution. Type Enter or Ctrl+C to exit.
-------------------------------------------------------------------------


I'll give try crontab in a bit, but does that error message indicate a larger problem?

I think that's because when cron runs the command on behalf as your user, the session is not registered with logind, therefore the command has no permissions to call that method.

So I guess the only options then are to run either "systemctl suspend" or "pm-suspend" as root by using "sudo" or adding the command to the system cron (you have to run the Task Scheduler as root for this, as mentioned in my previous post). You can of course kill vlc as root as well.
Sundance Kid
Registered Member
Posts
103
Karma
0
OS
Ok, I think we've got this covered now. Just to confirm that the little KShutdown program works well, as does systemctl suspend as root (kdesu kcmshell4 cron). Hopefully someone else finds this thread helpful in future. Thanks for all the help, very informative!


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]