I am about to write service that rsync --delete directory /mnt/foo to remote server. However because of --delete option, I'd like to not run it unless /mnt/foo is mounted, as this might result in deletion of all files on remote.

What to achieve it with ConditionX (e.g. ConditionPathIsDirectory) and RequiresMountsFor= directives, and what is the difference (pros and cons of each) ?

Draft: Here is my current sketch:



# assuming there is `bar_only_on_foo` subdirectory on monted directory, which does not exis on unmounted one.

To add to .service file:

# /etc/systemd/system/rsync_to_remotey.service
# or : /home/$USER/.config/systemd/user/rsync_to_remotey.service
Description=rsync USER X data to REMOTE Y


For correctness, here is .timer file:

# /etc/systemd/system/rsync_to_remotey.timer
# or : /home/$USER/.config/systemd/user/rsync_to_remotey.timer
Description=Runs every 30 minutes rsync USER X data to REMOTE Y


  • See also rsync's --max-delete=NUM option. Also, systemd's AssertPathIsDirectory (differs from Condition… in whether its an error). – derobert May 7 '16 at 8:17

I was also looking for an explanation and the man-pages on a recent Raspberry Pi Jessie image sort of gave me one.

I first looked here: man 7 systemd which then lead me to look at: man 5 systemd.unit

which provided the following:


Takes a space-separated list of absolute paths. Automatically adds dependencies of type Requires= and After= for all mount units required to access the specified path.

Mount points marked with noauto are not mounted automatically and will be ignored for the purposes of this option. If such a mount should be a requirement for this unit, direct dependencies on the mount units may be added (Requires= and After= or some other combination).

A little farther down in the man page,

ConditionArchitecture=, ConditionVirtualization=, ConditionHost=, ConditionKernelCommandLine=, ConditionSecurity=, ConditionCapability=, ConditionACPower=, ConditionNeedsUpdate=, ConditionPathExists=, ConditionPathExistsGlob=, ConditionPathIsDirectory=, ConditionPathIsSymbolicLink=, ConditionPathIsMountPoint=, ConditionPathIsReadWrite=, ConditionDirectoryNotEmpty=, ConditionFileNotEmpty=, ConditionFileIsExecutable=, ConditionNull=

Before starting a unit verify that the specified condition is true. If it is not true, the starting of the unit will be skipped, however all ordering dependencies of it are still respected. A failing condition will not result in the unit being moved into a failure state. The condition is checked at the time the queued start job is to be executed.

For what it's worth, I'm going with ConditionPathIsMountPoint=:

ConditionPathIsMountPoint= is similar to ConditionPathExists= but verifies whether a certain path exists and is a mount point.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.