Added script to monitor upsc status and reboot as necessary

main
WhatTheMike 2 years ago
parent 33c0d5bd5f
commit 546874eea8

@ -136,6 +136,21 @@
src: /root/ansible/templates/nut-telegraf.conf.j2 src: /root/ansible/templates/nut-telegraf.conf.j2
become: true become: true
become_method: sudo become_method: sudo
- name: Verify monitoring template is deployed
ansible.builtin.template:
dest: /home/pi/nutmon.sh
src: /root/ansible/templates/nutmon.sh.j2
mode: '0755'
- name: Ensure monitoring script is scheduled
ansible.builtin.cron:
name: "Check on the UPS"
minute: "*/5"
job: "/home/pi/nutmon.sh"
user: root
state: present
become: true
become_method: sudo
- name: Enable and restart services - name: Enable and restart services
ansible.builtin.service: ansible.builtin.service:

@ -0,0 +1,22 @@
#!/bin/bash
upsname="{{ upsname }}"
retries=5
retry_delay=30
# Check dependencies
which upsc >/dev/null || exit 1
upsstat=1 # just to bootstrap the loop
while [ $upsstat -ne 0 ]; do
upsc $upsname
upsstat=$?
if [ $upsstat -eq 1 ]; then
let retries=retries-1
if [ $retries -le 0 ]; then
reboot
fi
sleep $retry_delay
fi
done
Loading…
Cancel
Save