Skip to content

Instantly share code, notes, and snippets.

@agross
Last active August 21, 2016 10:54
Show Gist options
  • Save agross/9100171893adef2ea1060d336bf037a9 to your computer and use it in GitHub Desktop.
Save agross/9100171893adef2ea1060d336bf037a9 to your computer and use it in GitHub Desktop.
# %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"
URL=https://your-owncloud-server.example.com/cron.php
[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
# %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