Skip to content

Instantly share code, notes, and snippets.

@mark-kubacki
Created November 4, 2018 14:20
Show Gist options
  • Save mark-kubacki/7b62fbe312599c0c95462b33254a8deb to your computer and use it in GitHub Desktop.
Save mark-kubacki/7b62fbe312599c0c95462b33254a8deb to your computer and use it in GitHub Desktop.
systemd timer that runs only if another service is active (running)
[Unit]
Description=Docker garbage collection
ConditionACPower=true
ConditionDirectoryNotEmpty=/var/lib/docker
Requisite=docker.service
PartOf=docker.service
After=docker.service
[Service]
Environment=GRACE_PERIOD=1h
Type=oneshot
ExecStart=/usr/bin/docker system prune --force --filter "until=10m"
;ExecStart=/usr/bin/docker volume prune --force
ExecStart=/usr/bin/docker image prune -a --force --filter "until=${GRACE_PERIOD}"
[Unit]
Description=Docker garbage collection (timer)
PartOf=docker.service
After=docker.service
[Timer]
OnStartupSec=1h
OnUnitActiveSec=2h
AccuracySec=15min
[Install]
WantedBy=docker.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment