-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-autoheal.service
40 lines (33 loc) · 972 Bytes
/
docker-autoheal.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[Unit]
Description=Restart unhealthy docker container
After=docker.service
Wants=docker.service
[Service]
Type=simple
# Security hardening
CapabilityBoundingSet=
DevicePolicy=closed
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectClock=yes
ProtectControlGroups=yes
ProtectHome=read-only
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectProc=invisible
ProtectSystem=full
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
Restart=on-failure
RestartSec=60
ExecSearchPath=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Environment="autoheal_interval_seconds=5"
EnvironmentFile=-/etc/docker-autoheal.env
ExecStart=sh -c "while true; do docker ps --filter 'health=unhealthy' --format '{{.Names}}' | xargs --no-run-if-empty docker restart; sleep $autoheal_interval_seconds; done"
[Install]
WantedBy=docker.service