Skip to content

Services

Services

Enable and start Service:

systemctl enable --now docker.service

Docker Service:

cat /etc/systemd/system/docker-compose-mail.service

[Unit]
Description=Mail service with docker compose
PartOf=docker.service
After=docker.service network-online.target
Requires=docker.service network-online.target

[Service]
Restart=always
RuntimeMaxSec=7d #Update this every week
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/home/generalzero/docker/
ExecStartPre=-/usr/local/bin/docker-compose pull --quiet
ExecStart=/usr/local/bin/docker-compose up -d --remove-orphans

ExecStop=/usr/local/bin/docker-compose down

ExecReload=/usr/local/bin/docker-compose pull --quiet
ExecReload=/usr/local/bin/docker-compose up -d

[Install]
WantedBy=multi-user.target

Docker Cleanup Service:

>>> cat /etc/systemd/system/docker-cleanup.service
[Unit]
Description=Docker cleanup
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
WorkingDirectory=/tmp
User=root
Group=root
ExecStart=/usr/bin/docker system prune -af

[Install]
WantedBy=multi-user.target

>>> cat /etc/systemd/system/docker-cleanup.timer
[Unit]
Description=Docker cleanup timer

[Timer]
OnUnitInactiveSec=1w

[Install]
WantedBy=timers.target

Certificate Renewal Service: