Write and deploy motd-carp-state.sh
continuous-integration/drone/push Build is failing Details

A script that checks the carp state and writes in the /etc/motd file if the
server is in backup or master state. Script is copied in /usr/share/scripts/
directory and a cron job is installed but disabled by default.
This commit is contained in:
Jérémy Dubois 2020-08-25 17:57:22 +02:00
parent deafd82337
commit b586b1fafe
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,47 @@
#!/bin/sh
if [ ! -f /etc/motd-original ]; then
cp /etc/motd /etc/motd-original
fi
if [ ! -f /tmp/carp.state ]; then
echo "unknown" > /tmp/carp.state
fi
ifconfig carp0 | grep -q master
master=$?
ifconfig carp0 | grep -q backup
backup=$?
if [ "$master" -eq 0 ]; then
if [ $(cat /tmp/carp.state) = "master" ]; then
# We already were master, no change
exit 0
fi
cat /etc/motd-original - << EOF > /etc/motd
__ ______ _____________________
/ |/ / | / ___/_ __/ ____/ __ \
/ /|_/ / /| | \__ \ / / / __/ / /_/ /
/ / / / ___ |___/ // / / /___/ _, _/
/_/ /_/_/ |_/____//_/ /_____/_/ |_|
EOF
echo "master" > /tmp/carp.state
elif [ "$backup" -eq 0 ]; then
if [ $(cat /tmp/carp.state) = "backup" ]; then
# We already were backup, no change
exit 0
fi
cat /etc/motd-original - << EOF > /etc/motd
____ ___ ________ ____ ______
/ __ )/ | / ____/ //_/ / / / __ \
/ __ / /| |/ / / ,< / / / / /_/ /
/ /_/ / ___ / /___/ /| / /_/ / ____/
/_____/_/ |_\____/_/ |_\____/_/
EOF
echo "backup" > /tmp/carp.state
else
# No CARP
exit 0
fi

View File

@ -2,3 +2,4 @@
# tasks files
- include: ldif.yml
- include: update.yml
- include: motd.yml

View File

@ -0,0 +1,14 @@
---
- name: Deploy dynamic motd script for CARP master or backup
copy:
src: motd-carp-state.sh
dest: /usr/share/scripts/motd-carp-state.sh
owner: root
group: wheel
mode: '0755'
- name: Cron job for dynamic motd script is installed
cron:
name: dynamic motd for CARP
job: "/bin/sh /usr/share/scripts/motd-carp-state.sh"
disabled: true