Add quick MOTD for docker containers
This commit is contained in:
parent
171d769d17
commit
a9235f0e2d
@ -81,6 +81,8 @@
|
|||||||
motd_watch_services_extra:
|
motd_watch_services_extra:
|
||||||
- docker
|
- docker
|
||||||
- isc-dhcp-server
|
- isc-dhcp-server
|
||||||
|
motd_watch_containers_extra:
|
||||||
|
- unbound
|
||||||
tags: [ pis, mp, motd ]
|
tags: [ pis, mp, motd ]
|
||||||
# And also serving DHCP
|
# And also serving DHCP
|
||||||
- hosts: pi-mp-1.desu.ltd
|
- hosts: pi-mp-1.desu.ltd
|
||||||
|
@ -22,3 +22,7 @@ motd_watch_services:
|
|||||||
- ansible-pull
|
- ansible-pull
|
||||||
- backup
|
- backup
|
||||||
motd_watch_services_extra: []
|
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: []
|
||||||
|
@ -13,6 +13,11 @@ declare -a services
|
|||||||
services+=("{{ item }}")
|
services+=("{{ item }}")
|
||||||
{% endfor %}
|
{% 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
|
## Now, we actually put this info to use
|
||||||
# Starting with services
|
# Starting with services
|
||||||
if [ -n "${services[*]}" ]; then
|
if [ -n "${services[*]}" ]; then
|
||||||
@ -43,6 +48,24 @@ if [ -n "${services[*]}" ]; then
|
|||||||
done
|
done
|
||||||
fi
|
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
|
## And some generic system status stuff
|
||||||
printf "\e[1mSystem Status\e[0m\n"
|
printf "\e[1mSystem Status\e[0m\n"
|
||||||
if [ -f /var/run/reboot-required ]; then
|
if [ -f /var/run/reboot-required ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user