aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-06-18 10:38:09 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-06-18 10:38:09 +0200
commit9d361e9622f87ce6425999db442b49ca5d2b65a2 (patch)
treef5e5b7d4729b29caa314037c9caa816a1c9901fe
parentdf8b80af891b3680762d45d77837a8b9c62e8a72 (diff)
download0tdns-9d361e9622f87ce6425999db442b49ca5d2b65a2.tar.gz
0tdns-9d361e9622f87ce6425999db442b49ca5d2b65a2.zip
check if 0tdns is still running every 15, 30 and 45 minutes past na hour
-rw-r--r--0tdns_crontab1
-rwxr-xr-xinstall.sh1
-rw-r--r--src/check_if_done.py21
-rwxr-xr-xuninstall.sh1
4 files changed, 24 insertions, 0 deletions
diff --git a/0tdns_crontab b/0tdns_crontab
index 3af6507..859c267 100644
--- a/0tdns_crontab
+++ b/0tdns_crontab
@@ -1,2 +1,3 @@
0 * * * * /usr/sbin/hourly.py # <AUTO_GENERATED_0TDNS_ENTRY> do not remove this '<>' tag
@reboot /usr/bin/rm /var/lib/0tdns/lockfile # <AUTO_GENERATED_0TDNS_ENTRY> do not remove this '<>' tag
+15,30,45 * * * * /usr/sbin/check_if_done.py --send-mail # <AUTO_GENERATED_0TDNS_ENTRY> do not remove this '<>' tag
diff --git a/install.sh b/install.sh
index 1e2a21c..091fd3c 100755
--- a/install.sh
+++ b/install.sh
@@ -22,6 +22,7 @@ install -D -m644 db_connection_config.yml "$INSTALL_ROOT"/etc/0tdns/db_connectio
# This one would make sense to be executed directly, so it'll go to sbin
# This happens to also be the script, that gets called by cron
install -D -m744 src/hourly.py "$INSTALL_ROOT"/usr/sbin/hourly.py
+install -D -m744 src/check_if_done.py "$INSTALL_ROOT"/usr/sbin/check_if_done.py
# This one shall be imported from other scripts
install -D -m644 src/ztdnslib.py "$INSTALL_ROOT"/usr/lib/python3/dist-packages/ztdnslib.py
diff --git a/src/check_if_done.py b/src/check_if_done.py
new file mode 100644
index 0000000..c91fea3
--- /dev/null
+++ b/src/check_if_done.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python3
+
+from sys import argv
+from time import gmtime, strftime
+from ztdnslib import log
+from os.path import isfile
+
+lockfile = '/var/lib/0tdns/lockfile'
+if isfile(lockfile):
+ msg = '{} still exists, 0tdns is probably running for too long'\
+ .format(lockfile)
+
+ print(msg)
+
+ # this script shall be run 15, 30 and 45 minutes after an hour;
+ # in all cases we want to write to logs, but only at 30 or 45 minutes
+ # we want to email the admin
+ if int(strftime('%M', gmtime())) >= 30 and '--send-mail' in argv:
+ print('Sending mail') # TODO send mail and delete this line
+
+ log(msg)
diff --git a/uninstall.sh b/uninstall.sh
index 5e8a0b8..294c151 100755
--- a/uninstall.sh
+++ b/uninstall.sh
@@ -23,6 +23,7 @@ if [ "x$1" = "x--delete-files" ]; then
rm -r /var/lib/0tdns/
rm -r /etc/netns/0tdns*
rm /usr/sbin/hourly.py
+ rm /usr/sbin/check_if_done.py
rm -r /etc/0tdns
rm /usr/lib/python3/dist-packages/ztdnslib.py
fi