systemd.unit 'RequiresMountsFor =' vs 'ConditionPathIsDirectory ='

7

Estou prestes a gravar o serviço que rsync --delete directory / mnt / foo para o servidor remoto. No entanto, devido à opção --delete , gostaria de não executá-lo, a menos que / mnt / foo esteja montado, pois isso pode resultar na exclusão de todos os arquivos no remoto.

O que fazer com as diretivas ConditionX (por exemplo, ConditionPathIsDirectory ) e RequiresMountsFor= e qual é a diferença (vantagens e desvantagens de cada uma)?

Esboço: Aqui está meu esboço atual:

RequiresMountsFor=/mnt/foo

vs

# assuming there is 'bar_only_on_foo' subdirectory on monted directory, which does not exis on unmounted one.
ConditionPathIsDirectory=/mnt/foo/bar_only_on_foo

Para adicionar ao arquivo .service :

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

[Service]
Type=simple
ExecStart=/home/USERX/rsync_userx_to_remotey.sh

Para correção, aqui está o arquivo .timer :

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

[Timer]
OnBootSec=30min
AccuracySec=1h
OnCalendar=*:0/30
Unit=rsync_to_remotey.service

[Install]
WantedBy=multi-user.target
    
por Grzegorz Wierzowiecki 07.05.2016 / 08:24

1 resposta

3

Eu também estava procurando uma explicação e as man-pages de uma imagem recente do Raspberry Pi Jessie me deram uma.

Eu olhei pela primeira vez aqui: man 7 systemd o que então me leva a olhar:      man 5 systemd.unit

que forneceu o seguinte:

RequiresMountsFor=

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).

Um pouco mais abaixo na página do manual,

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.

Por que vale a pena, vou com ConditionPathIsMountPoint= :

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

    
por 19.12.2016 / 22:12