[Solved] dbus-send error....

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Pastcal
Level 3
Level 3
Posts: 180
Joined: Tue May 07, 2013 12:06 pm

[Solved] dbus-send error....

Post by Pastcal »

LM 19 64 bit, Xfce.

Objective, to shut the system down from a shell script.
This command line, as found in shell script that worked in LM 18.3, no longer works.:
dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

Error message returned.
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.ConsoleKit was not provided by any .service files

Attempts at self help: Google, no significant help, just references to Gnome power manager. Perusal of the man page for dbus-send, Too terse and lacking in examples or diagnostic help. Advice please. Thanks.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
gm10

Re: dbus-send error....

Post by gm10 »

What's wrong with

Code: Select all

shutdown
?
Pastcal
Level 3
Level 3
Posts: 180
Joined: Tue May 07, 2013 12:06 pm

Re: dbus-send error....

Post by Pastcal »

gm10 wrote: Tue Aug 28, 2018 10:13 am What's wrong with

Code: Select all

shutdown
?
That's a bloody good question. However it only works from the console, not from shell scripts, even if you change permissions.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: dbus-send error....

Post by rene »

Pastcal wrote: Tue Aug 28, 2018 10:52 am That's a bloody good question. However it only works from the console, not from shell scripts, even if you change permissions.
Can assure you that shutdown now and systemctl poweroff work fine here, in the case of an admin user with or without sudo, and from command line as well as any script.

I expect you are are talking about a for example cron invoked script? Those get a very limited environment by default and specifically do not have /sbin in their PATH. If that's the issue just use /sbin/shutdown explicitly.

Failing all else, the correct dbus-send command is

Code: Select all

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true
but don't use that...
gm10

Re: dbus-send error....

Post by gm10 »

rene wrote: Tue Aug 28, 2018 11:08 am I expect you are are talking about a for example cron invoked script? Those get a very limited environment by default and specifically do not have /sbin in their PATH. If that's the issue just use /sbin/shutdown explicitly.
If this is about cron then you need to put it into the root crontab, a user's crontab lacks permissions for a shutdown:

Code: Select all

sudo crontab -e
Pastcal
Level 3
Level 3
Posts: 180
Joined: Tue May 07, 2013 12:06 pm

Re: dbus-send error....

Post by Pastcal »

rene wrote: Tue Aug 28, 2018 11:08 am
Pastcal wrote: Tue Aug 28, 2018 10:52 am That's a bloody good question. However it only works from the console, not from shell scripts, even if you change permissions.
Can assure you that shutdown now and systemctl poweroff work fine here, in the case of an admin user with or without sudo, and from command line as well as any script.

I expect you are are talking about a for example cron invoked script? Those get a very limited environment by default and specifically do not have /sbin in their PATH. If that's the issue just use /sbin/shutdown explicitly.

Failing all else, the correct dbus-send command is

Code: Select all

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true
but don't use that...
Blow me down, so it does. I mean, that's what you would expect, but a while ago I had a struggle making it work, that's why I picked up on all that dbus-send nonsense. Gah. Anyway thanks.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: dbus-send error....

Post by rene »

gm10 wrote: Tue Aug 28, 2018 11:33 am If this is about cron then you need to put it into the root crontab, a user's crontab lacks permissions for a shutdown
... which i didn't think to mention since I forgot I already adjusted this behaviour in the context of allowing me to shutdown the system from an SSH login. If you/anyone wants to do likewise, create e.g. /etc/polkit-1/localauthority/50-local.d/org.freedesktop.login1.pkla containing

Code: Select all

[org.freedesktop.login1]
Identity=unix-user:0;unix-group:sudo;unix-group:admin
Action=org.freedesktop.login1.*
ResultAny=yes
The Action glob is a little wide but Works For Me; see pkaction | grep org.freedesktop.login1 for the individual actions. I don't believe you need to reboot to have it active.

This as mentioned works for shutting down from an SSH login but also for the here apparently falsely expected cron scenario. Test with, as your admin user,

Code: Select all

date +"%M %_H" | awk '{ print $1+1 " " $2 " * * * /sbin/shutdown now" }' | crontab
so as to schedule a shutdown for the next minute. crontab -r to remove your crontab again.
Last edited by rene on Tue Aug 28, 2018 2:32 pm, edited 1 time in total.
gm10

Re: dbus-send error....

Post by gm10 »

rene wrote: Tue Aug 28, 2018 2:28 pm The Action glob is a little wide but Works For Me; see pkaction | grep org.freedesktop.login1 for the individual actions. I don't believe you need to reboot to have it active.
Yes, I had previously suggested to just modify the policy for org.freedesktop.login1.power-off here:
viewtopic.php?p=1508097#p1508097

Won't need a reboot indeed.
Last edited by gm10 on Tue Aug 28, 2018 2:33 pm, edited 2 times in total.
Locked

Return to “Beginner Questions”