Open dbrgn opened 4 years ago
Hmm. That is probably because it will run as root which won't have access to the dbus session of the user.
But I should definitely fix the panic :slightly_smiling_face:
@dbrgn Can you try setting $DBUS_SESSION_BUS_ADDRESS
to something like unix:path=/run/user/1000/bus
where 1000
is your UID
?
We can't set env vars in the hook files. Someone on Arch IRC suggested to either hardcode the UID (or make it configurable), or to try to detect users with an active login session (could maybe be detected through DBUS as well).
Checking for D-Bus service presence of rfjakob/systembus-notify, and utilizing it to alert the user when available would resolve this issue.
I found a solution:
/etc/pacman.d/scripts/reboot-arch-btw-hook.sh
#!/bin/bash
sudo -u $SUDO_USER DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$SUDO_UID/bus /usr/bin/reboot-arch-btw
/etc/pacman.d/hooks/99-reboot-arch-btw.hook
[Trigger]
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Check whether a reboot is required
Depends = reboot-arch-btw
When = PostTransaction
Exec = /etc/pacman.d/scripts/reboot-arch-btw-hook.sh
This works perfectly fine if you run upgrades with sudo pacman -Syu
. If you run upgrades in a cron job or similar you probably need to hard-code the user-name and user-id in the script above.
Edit: If you hardcode it, it also works as a one-liner in the .hook
file:
Exec = /usr/bin/sudo -u your-user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/your-uid/bus /usr/bin/reboot-arch-btw
@rnestler great, it works! I'm not sure if this is something that could be part of the AUR package? (Or maybe just a separate package that depends on reboot-arch-btw
.)
great, it works! I'm not sure if this is something that could be part of the AUR package? (Or maybe just a separate package that depends on reboot-arch-btw.)
It's hard to write it in a generic way such that it works for all use cases.
Something like this might work:
#!/bin/bash
# go through all logged in users and check if we find a D-BUS bus for them
for user in $(users|tr ' ' '\n'|sort -u); do
uid=$(id -u "$user")
if [[ -f "/run/user/$uid/bus" ]]; then
/usr/bin/sudo -u "$user" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus /usr/bin/reboot-arch-btw
exit 0
fi
done
# if not run with notifications disabled
/usr/bin/reboot-arch-btw --disable-notification
Checking for D-Bus service presence of rfjakob/systembus-notify, and utilizing it to alert the user when available would resolve this issue.
@emansom This looks interesting as well, but I don't use systembus-notify
myself, so PR welcome :)
This hook runs reboot-arch-btw when linux is upgraded:
Unfortunately DBUS cannot be accessed from the hook right now: