27 lines
809 B
Bash
27 lines
809 B
Bash
#! /usr/bin/env nix
|
|
#! nix shell nixpkgs#docker nixpkgs#bash nixpkgs#gawk --command bash
|
|
|
|
outdated_msg="Project code is out of date and needs to be upgraded. To remedy this problem immediately, you may reboot your warrior."
|
|
|
|
label="$1"
|
|
label_val="$2"
|
|
|
|
if (($# != 2)); then
|
|
echo "usage: $0 label label_value"
|
|
fi
|
|
|
|
containers=$(docker ps --format '{{.Names}}' -f "label=${label}=${label_val}")
|
|
|
|
for container in ${containers[@]}; do
|
|
echo "checking ${container}"
|
|
|
|
last_msg=$(docker logs -n 1 "${container}")
|
|
|
|
if [[ $last_msg =~ $outdated_msg ]]; then
|
|
echo "${container} is outdated, restarting"
|
|
imageTag=$(docker ps --format '{{.Names}}\t{{.Image}}' -f "name=$container" | grep -w "$container" | awk '{print $NF}')
|
|
docker pull "$imageTag"
|
|
systemctl restart "docker-${container}"
|
|
fi
|
|
done
|