-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatpak: Stop time tracking on shutdown (using systemd) #684
Comments
Meanwhile I could solve the original problem – now facing another one – and thus completely overhauled my initial post above as well as the issue title. |
Assuming that what you want is to run hamster for your user "salim", you should be at least using user units in I also think a better approach would be to use a DBus message via |
Yeah, initially I thought the same. But this is not possible in the current systemd world – at least not for sleep/shutdown/etc.-related stuff – because "'user' instances currently have no way to depend on systemwide services". Besides,
Awesome, thanks for pointing out this alternative! I'll test this. Is there also a D-Bus message/call to query the currently running Hamster activity? Or – more generally – where is Hamster's D-Bus service API documented? |
Good point. I didn't think about this yet (rather irrelevant for my use case since I'm the only user on my system). |
See https://github.com/projecthamster/hamster/blob/master/src/hamster-service.py for Hamster's D-Bus service API. |
Perhaps you could use dbus-monitor to listen for org.freedesktop.login1 PrepareForShutdown and PrepareForSleep signals? Maybe they get sent before your flatpak hamster process gets killed. (Warning: I know nothing about this stuff!) |
I don't think this ticket is a proper issue with Hamster itself. I'd like to see it closed. |
Goal
I've tried to hack together an alternative for the removed GNOME session idle detection running the Hamster Flatpak app (GH actions artifact).
I'm using Ubuntu 20.04, but I think all the stuff described below should apply to any recent Linux distro that uses systemd and GNOME 3.
The approach basically consists of
a bash script that regularly polls user session inactivity from GNOME's window manager Mutter and stops time tracking if the specified threshold is reached and resumes time tracking as soon as user activity is detected again. This works fine. The script is found here.
some more scripts to run from systemd service units with the goal of a) stopping time tracking when the system is powered off and b) suspending and resuming time tracking before and after the system is put to sleep. While b) works fine, a) doesn't do what it's supposed to.
Details
For the second point above, consider the following bash script
/usr/local/bin/hamster_tracking/hamster_stop.sh
and systemd service unit/etc/systemd/system/hamster_stop.service
that executes the former before the system powers off:hamster_stop.sh
hamster_stop.service
Test
Place the above two files at the mentioned filesystem locations and make the bash script executable (
sudo chmod +x /usr/local/bin/hamster_tracking/hamster_stop.sh
).In
/etc/systemd/system/hamster_stop.service
, replacesalim
with your actual username and1000
with your actual user ID (UID).Activate the above service unit using
sudo systemctl enable hamster_stop.service
Either reboot or manually start the above service unit using:
Problem
My main problem now is: Although the systemd unit
hamster_stop.service
seems to basically work – tested by a) manually starting and stopping it usingsudo systemctl start hamster_stop.service; sudo systemctl stop hamster_stop.service
and b) writing a string to file instead of runninghamster_stop.sh
inExecStop=
– neitherflatpak run org.gnome.Hamster stop
nornotify-send
inhamster_stop.sh
seem to work as supposed.The cause of Hamster not stopping is most probably that systemd already killed the process responsible for the Hamster Flatpak at the time
hamster_stop.service
is stopped.Running something on shutdown before systemd starts to kill a specific user process is already tricky. But at least the systemd unit belonging to a specific process ID (PID) can be determined using
systemctl status <PID>
. Then this unit can be configured as a reverse ordering dependency of a "on shutdown" unit (i.e. putting it inAfter=
). But for the Hamster-related Flatpak processes on my system,systemctl status
always revealed only[email protected]
which is simply the instance responsible for starting user processes. Setting[email protected]
(together with[email protected]
) didn't help.Statements from 2016, 2017 and even systemd author Lennart Poettering himself in 2020 seem to indicate this is impossible to solve with current systemd... ☹
Note that I've put together more stuff I've learned in relation to this venture in this README.
Thanks in advance for any help!
The text was updated successfully, but these errors were encountered: