Add quick MOTD for docker containers

This commit is contained in:
Salt 2021-03-10 10:41:40 -06:00
parent 171d769d17
commit a9235f0e2d
3 changed files with 29 additions and 0 deletions

View File

@ -81,6 +81,8 @@
motd_watch_services_extra:
- docker
- isc-dhcp-server
motd_watch_containers_extra:
- unbound
tags: [ pis, mp, motd ]
# And also serving DHCP
- hosts: pi-mp-1.desu.ltd

View File

@ -22,3 +22,7 @@ motd_watch_services:
- ansible-pull
- backup
motd_watch_services_extra: []
# Docker images to look for. Matches a simple glob (*{{ item }}*)
# If Docker is not running, this section will be omitted
motd_watch_containers: []
motd_watch_containers_extra: []

View File

@ -13,6 +13,11 @@ declare -a services
services+=("{{ item }}")
{% endfor %}
declare -a containers
{% for item in (motd_watch_containers + motd_watch_containers_extra)|sort %}
containers+=("{{ item }}")
{% endfor %}
## Now, we actually put this info to use
# Starting with services
if [ -n "${services[*]}" ]; then
@ -43,6 +48,24 @@ if [ -n "${services[*]}" ]; then
done
fi
# Containers, if docker is running
if [ -n "${containers[*]}" ] && systemctl -q is-active docker; then
printf "\e[1mContainer Statuses\e[0m\n"
len=20
for container in "${containers[@]}"; do
status="\e[33mUnknown\e[0m"
image="$(docker ps | tail -n +2 | awk '{print $2}' | grep -ie "$container")"
if [ -n "$image" ]; then
status="\e[1;32mRunning\e[0m - $image"
fi
if [ -z "$image" ]; then
status="\e[1;31mNot Running\e[0m"
fi
printf " * \e[37m%-${len}.${len}s\e[0m - $status " "$container"
printf "\n"
done
fi
## And some generic system status stuff
printf "\e[1mSystem Status\e[0m\n"
if [ -f /var/run/reboot-required ]; then