Write and deploy motd-carp-state.sh
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
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:
parent
deafd82337
commit
b586b1fafe
47
roles/post-install/files/motd-carp-state.sh
Executable file
47
roles/post-install/files/motd-carp-state.sh
Executable 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
|
|
@ -2,3 +2,4 @@
|
|||
# tasks files
|
||||
- include: ldif.yml
|
||||
- include: update.yml
|
||||
- include: motd.yml
|
||||
|
|
14
roles/post-install/tasks/motd.yml
Normal file
14
roles/post-install/tasks/motd.yml
Normal 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
|
Loading…
Reference in a new issue