Last active
August 21, 2016 10:54
-
-
Save agross/9100171893adef2ea1060d336bf037a9 to your computer and use it in GitHub Desktop.
Trigger cron for owncloud docker containers, more info: https://matthiasadler.info/blog/running-scheduled-tasks-in-docker-containers-with-systemd/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %n == The full unit name, e.g. "nginx.service". | |
# %p == The unit's prefix, e.g. "nginx". | |
[Unit] | |
Description=Trigger cron for ownCloud | |
After=owncloud.service | |
# See http://northernlightlabs.se/systemd.status.mail.on.unit.failure | |
OnFailure=unit-status-mail@%n.service | |
[Service] | |
# Read variables used below from this file. | |
EnvironmentFile=/etc/conf.d/%n.conf | |
ExecStart=/usr/local/bin/cron-owncloud "$URL" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL=https://your-owncloud-server.example.com/cron.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=cron-owncloud timer | |
# Stop if owncloud.service is not available. | |
Requires=owncloud.service | |
[Timer] | |
# Runs cron-owncloud.service relative to when this timer unit was activated. | |
OnActiveSec=5min | |
# Runs cron-owncloud.service relative to when the cron-owncloud.service unit was last deactivated. | |
# This makes cron-owncloud.service run every 15 minutes. | |
OnUnitInactiveSec=15min | |
[Install] | |
WantedBy=timers.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %n == The full unit name, e.g. "nginx.service". | |
# %p == The unit's prefix, e.g. "nginx". | |
[Unit] | |
Description=ownCloud Server | |
Requires=docker.service | |
After=docker.service | |
OnFailure=unit-status-mail@%n.service | |
# Start timer to run cron inside ownCloud container. | |
Wants=cron-%p.timer | |
[Service] | |
# docker stop/rm just in case the container has not been removed (e.g. the system crashed). | |
ExecStartPre=-/usr/bin/docker stop "%p" | |
ExecStartPre=-/usr/bin/docker rm "%p" | |
ExecStart=/usr/bin/docker run --name "%p" --rm --publish 8015:80 --volume /var/data/owncloud:/var/www/html:z owncloud | |
# Restart 2 seconds after docker run exited with an error status. | |
Restart=always | |
RestartSec=2s | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment