Simplified interface to monitor job completion status
onitake opened this issue · 1 comments
It looks like there is currently no easy way to wait for start/stop unit job completion.
The job ID returned by dbus.Conn.StartUnit
seems to be quite useless.
I see two possibilities by means of what's provided in go-systemd:
- Register for notifications with
dbus.Conn.SubscribeUnitsCustom
and filter out the desired unit and target state. - Poll for unit status with
dbug.Conn.ListUnitsByNames
.
This blog even describes a low-level approach:
https://jonathangold.ca/blog/waiting-for-systemd-job-to-complete/
It would be much more helpful if the jobid returned by StartUnit/StopUnit could be used to check or wait for completion, but it seems like such a feature is not provided by SystemD. Would it be possible to provide some sort of Wait/Join/Check function built on top of the functions above to determine when a job completes?
My bad, I completely overlooked the channel you can pass to StartUnit et al.
I still don't quite see what the job ID is for, but the channel should be sufficient for getting the job status.