Re: [systemd-devel] mount-on-demand for backups; hooks for indicating success/failure
On Fri, Mar 31, 2017 at 12:01:11PM +0200, Lennart Poettering wrote: > On recent systemd versions you can plug in a script in ExecStop= of > your backup service, and check the $SERVICE_RESULT env var which tells > you the success state of the service, which you can then use to set > any LEDs you like. This looks very useful, thanks - but the issue here is that I don't think systemd provides a guarantee that if my backup service Requires a mount unit, and that mount unit is marked StopWhenUnneeded=true, that the this script will fire after the unmount has finished (and succeeded). I think Michal's solution of having a separate service for the LEDs might work, perhaps with After=media-ipod.mount, but I need to experiment some more. -- Jonathan Dowland ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] mount-on-demand for backups; hooks for indicating success/failure
On Thu, 09.03.17 15:53, Jonathan Dowland (jon+systemd-de...@alcopop.org) wrote: > Hey, > > I have some backup services which depend on mounts. I want those > filesystems unmounted when the backup jobs are not running. This is > easily achieved with StopWhenUnneeded. > > I also want to trigger the backup jobs to start when I attach my > external HDD. This is reasonably simple by adding WantedBy= > to the backup service (*not* the mount unit, or it will never be > auto-unmounted). > > So far so good! > > However, this is a headless box and I want to blink an LED when certain > jobs are running, finish or fail. So I need to execute commands in > certain situations. Job failure is easy, I can use OnFailure= and set up > a oneshot service. Job started isn't too bad, I add a ExecStart=- > to my backup service before the real one. > > Signalling "device is safe to remove" I have not figured out. > Using a chain of blah.device -> blah.mount -> backup-blah.service units, > "safe to remove" LED should only happen after the mount has completed > unmounting, successfully. Is there an existing "hook" or place that I > could put that in this situation? On recent systemd versions you can plug in a script in ExecStop= of your backup service, and check the $SERVICE_RESULT env var which tells you the success state of the service, which you can then use to set any LEDs you like. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] mount-on-demand for backups; hooks for indicating success/failure
On Thu, Mar 9, 2017 at 4:53 PM, Jonathan Dowlandwrote: > Hey, > > I have some backup services which depend on mounts. I want those > filesystems unmounted when the backup jobs are not running. This is > easily achieved with StopWhenUnneeded. > > I also want to trigger the backup jobs to start when I attach my > external HDD. This is reasonably simple by adding WantedBy= > to the backup service (*not* the mount unit, or it will never be > auto-unmounted). WantedBy=device sounds like a weird hack to me. I think that it would be better to use SYSTEM_WANTS in udev rules instead. > > So far so good! > > However, this is a headless box and I want to blink an LED when certain > jobs are running, finish or fail. So I need to execute commands in > certain situations. Job failure is easy, I can use OnFailure= and set up > a oneshot service. Job started isn't too bad, I add a ExecStart=- > to my backup service before the real one. OnFailure is fine and ExecStart before starting backup also sounds reasonable. > > Signalling "device is safe to remove" I have not figured out. > Using a chain of blah.device -> blah.mount -> backup-blah.service units, > "safe to remove" LED should only happen after the mount has completed > unmounting, successfully. Is there an existing "hook" or place that I > could put that in this situation? It should be possible to achieve this with normal dependencies. For example, you would have blink-successful.service that would Require backup service and would be ordered after it. Dependencies should then look like this, # backup.service [Unit] Wants=blink-successful.service # blink-successful.service, [Unit] Requires=backup.service After=backup.service backup.service pulls in blink service and that will run only when backup succeeded. > > My temporary solution is to remove the mount unit entirely, define the > mount point in /etc/fstab and use ExecStart and ExecStop in the backup > service to mount and umount before and after the job runs: > > [Unit] > OnFailure=blinkstick-fail.service > [Service] > ExecStart=/bin/mount /media/ipod I'd leave fstab entry in place and replace ExecStart=/bin/mount with RequiresMountsFor=/media/ipod (this belongs to [Unit] section). So when this service is started it will pull in mount unit to transaction and gets ordered after the mount unit. Michal ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] mount-on-demand for backups; hooks for indicating success/failure
Hey, I have some backup services which depend on mounts. I want those filesystems unmounted when the backup jobs are not running. This is easily achieved with StopWhenUnneeded. I also want to trigger the backup jobs to start when I attach my external HDD. This is reasonably simple by adding WantedBy= to the backup service (*not* the mount unit, or it will never be auto-unmounted). So far so good! However, this is a headless box and I want to blink an LED when certain jobs are running, finish or fail. So I need to execute commands in certain situations. Job failure is easy, I can use OnFailure= and set up a oneshot service. Job started isn't too bad, I add a ExecStart=- to my backup service before the real one. Signalling "device is safe to remove" I have not figured out. Using a chain of blah.device -> blah.mount -> backup-blah.service units, "safe to remove" LED should only happen after the mount has completed unmounting, successfully. Is there an existing "hook" or place that I could put that in this situation? My temporary solution is to remove the mount unit entirely, define the mount point in /etc/fstab and use ExecStart and ExecStop in the backup service to mount and umount before and after the job runs: [Unit] OnFailure=blinkstick-fail.service [Service] ExecStart=/bin/mount /media/ipod # vvv this is a "backup in progress" colour vvv ExecStart=/usr/local/bin/blinkstick --index 1 --limit 10 --set-color 33c280 ExecStart=/usr/bin/rsync ... # the backup job ExecStop=/bin/umount /media/ipod ExecStop=/usr/local/bin/blinkstick --index 1 --limit 10 --set-color green This works for this simple use-case, but is not very elegant, and I don't think I can scale this up to my next task: do the same but for an *encrypted* filesystem. So here I have to have -> systemd-crpytsetup@.service -> .mount (or not?) -> backup-black.service. Any advice appreciated. Thanks! -- Jonathan Dowland ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel