I've created a service for manage some backups of my virtual machines.

This service should execute a script when the host is shutting down, and another script when the host start again.

My service file have this:




Now, my check.sh script Works fine, but my script backup.sh when I reboot or shut down my host, it doesn't work, because my service and libvirtd.service stops at the same time.

How can I make my service stops before libvirtd.service?


My service will only works if the guest machines are running, so libvirt or something (not libvirt-guests, because I disabled it) is shutting off them.

  • According to systemd.unit [manpage][1]: "Note that when two units with an ordering dependency between them are shut down, the inverse of the start-up order is applied. i.e. if a unit is configured with After= on another unit, the former is stopped before the latter if both are shut down." When you are saying it's failing, what do you mean? [1]: freedesktop.org/software/systemd/man/systemd.unit.html
    – Bigon
    Dec 23, 2016 at 21:11
  • I added new info. I think if the guest machines don't shut off, my service might work. Dec 26, 2016 at 13:17
  • Why did you disable the libvirt-guests.service? If it's disabled, I'm not sure anything will cleanly shutdown the VM's before the host is rebooted/shutdown. Did you try to use After=libvirt-guests.service instead?
    – Bigon
    Dec 26, 2016 at 14:43
  • I disabled it for testing, but the guest machines still shutting down before my service stop. Maybe, is something more shutting down the guest machines. Dec 26, 2016 at 16:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.