0

I created a systemd service file to run two rsync commands sequentially and I need to retry until successful. Sometimes the rsync server is down. Systemd tells me Restart=on-failure is not allowed for Type=oneshot services. What other Type of service can I use?

[Unit]
Description=Sync

[Service]
Type=oneshot
Restart=on-failure
ExecStart=/usr/bin/rsync -atvzq --no-owner --no-group --delete rsync://(some address) /srv/www/
ExecStart=/usr/bin/rsync -atvzq --no-owner --no-group --delete rsync://(some address) /srv/www1/
0

You could, for example, try to use two services A and B, where B depends on A and A is a oneshot service.

With the set-up shown in the example below, service B is pulled in when the multi-user target is reached (or any other target you specify in the [Install] section). Service B won't start before service A because it has a dependency on service A and is set to start after service A. Also, service B will wait for service A to terminate due to service A being type oneshot.

Because service A is requisite to service B, service B will fail to start if service A fails. Should service B fail, it will restart. Note that default settings put a limit on how many unsuccessful restart attempts (in a given time interval) are allowed before systemd will stop any further attempts to restart.

B.service

[Unit]
Description=Sync Task B Service
Requisite=A.service
After=A.service

[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/bin/rsync -atvzq --no-owner --no-group --delete rsync://(some address) /srv/www/

[Install]
WantedBy=multi-user.target

A.service

[Unit]
Description=Sync Task A Service

[Service]
Type=oneshot
ExecStart=/usr/bin/rsync -atvzq --no-owner --no-group --delete rsync://(some address) /srv/www/
|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.