-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is expected to happen when the service restarts while a container is running, as we don't have a graceful cleanup in the service. It can also happen unexpectedly during a crash. For some reason, this also happens when the service hasn't restarted (naturally or unexpectedly) and I haven't had a chance to hunt that down yet.
- Loading branch information
1 parent
2499fe2
commit ce8b5e4
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# {{ ansible_managed }} | ||
# | ||
|
||
# {% raw %} | ||
|
||
set -euv -o pipefail | ||
|
||
# How long a container must be running to be killed. | ||
# Number of seconds. | ||
MAX_TIME=3600 | ||
|
||
now=$(date "+%s") | ||
to_kill=() | ||
|
||
readarray -t container_ids < <(docker ps --format '{{ .ID }}' --no-trunc) | ||
|
||
while read -r id started_at; do | ||
started_at=$(date --date "${started_at}" "+%s") | ||
running_time=$((now - started_at)) | ||
|
||
if [[ "${running_time}" -gt "${MAX_TIME}" ]]; then | ||
to_kill+=("${id}") | ||
fi | ||
done < <(docker inspect "${container_ids[@]}" --format '{{ .ID }} {{ .State.StartedAt }}') | ||
|
||
if [[ ${#to_kill[@]} -gt 0 ]]; then | ||
docker kill "${to_kill[@]}" | ||
fi | ||
|
||
# {% endraw %} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# {{ ansible_managed }} | ||
# | ||
|
||
[Unit] | ||
Description=Garbage collect dead playground containers | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart={{ vars_playground_gc_path }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# {{ ansible_managed }} | ||
# | ||
|
||
[Unit] | ||
Description = Garbage collect playground containers every 15 minutes | ||
|
||
[Timer] | ||
OnBootSec = 15min | ||
OnUnitActiveSec = 15min | ||
|
||
[Install] | ||
WantedBy = timers.target |