summaryrefslogtreecommitdiff
path: root/roles/common
diff options
context:
space:
mode:
Diffstat (limited to 'roles/common')
-rw-r--r--roles/common/files/onmon.service10
-rw-r--r--roles/common/files/onmon.sh21
-rw-r--r--roles/common/tasks/main.yml21
3 files changed, 52 insertions, 0 deletions
diff --git a/roles/common/files/onmon.service b/roles/common/files/onmon.service
new file mode 100644
index 0000000..8ac3020
--- /dev/null
+++ b/roles/common/files/onmon.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Online monitor
+Requires=network-online.target
+After=network-online.target
+
+[Service]
+ExecStart=/usr/local/bin/onmon.sh
+
+[Install]
+WantedBy=default.target
diff --git a/roles/common/files/onmon.sh b/roles/common/files/onmon.sh
new file mode 100644
index 0000000..66a7974
--- /dev/null
+++ b/roles/common/files/onmon.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1
+state=$?
+oldstate=$state
+
+while true; do
+ ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1
+ state=$?
+
+ if [[ $oldstate -ne $state ]]; then
+ if [[ $state -eq 0 ]]; then
+ echo "Device went back online"
+ else
+ echo "Device went offline"
+ fi
+ fi
+
+ oldstate=$state
+ sleep 5
+done
diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml
index 20d7ddf..02d9392 100644
--- a/roles/common/tasks/main.yml
+++ b/roles/common/tasks/main.yml
@@ -10,6 +10,7 @@
- ldnsutils
- htop
- unattended-upgrades
+ - jq
state: present
- name: Install mailer
package:
@@ -19,3 +20,23 @@
when:
- mail_nullmailer is defined
- mail_nullmailer
+- name: Copy service executable
+ copy:
+ src: files/onmon.sh
+ dest: /usr/local/bin/onmon.sh
+ mode: "0750"
+ owner: "root"
+ group: "root"
+- name: Copy service file
+ copy:
+ src: files/onmon.service
+ dest: /etc/systemd/system/onmon.service
+ mode: "0640"
+ owner: "root"
+ group: "root"
+- name: Ensure online monitor is enabled
+ systemd:
+ name: onmon.service
+ enabled: true
+ state: started
+ daemon_reload: true