Timed job to tell listener to upload images to NextCloud
authorJacob Casper <dev@jacobcasper.com>
Sun, 5 Apr 2020 08:07:45 +0000 (03:07 -0500)
committerJacob Casper <dev@jacobcasper.com>
Sun, 5 Apr 2020 09:06:19 +0000 (04:06 -0500)
mercuryms-send.service [new file with mode: 0644]
mercuryms-send.timer [new file with mode: 0644]
send.sh [new file with mode: 0755]
setup.sh

diff --git a/mercuryms-send.service b/mercuryms-send.service
new file mode 100644 (file)
index 0000000..2aebec6
--- /dev/null
@@ -0,0 +1,17 @@
+[Unit]
+Description=MercuryMS Send Service
+After=network.target mercuryms-send.timer
+Requires=mercuryms-send.timer
+
+[Service]
+Type=oneshot
+User=mercuryms
+Group=mercuryms
+WorkingDirectory=/usr/share/mercuryms
+ExecStart=/opt/mercuryms/send.sh
+Environment="HOST=localhost"
+Environment="PORT=9099"
+Environment="TIMEOUT_SECONDS=45"
+
+[Install]
+WantedBy=multi-user.target
diff --git a/mercuryms-send.timer b/mercuryms-send.timer
new file mode 100644 (file)
index 0000000..314ce39
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=MercuryMS Timed Media Send
+After=network.target
+
+[Timer]
+OnActiveSec=1m
+Unit=mercuryms-send.service
+
+[Install]
+WantedBy=multi-user.target
diff --git a/send.sh b/send.sh
new file mode 100755 (executable)
index 0000000..e38559c
--- /dev/null
+++ b/send.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+sqlite3 mercuryms.sqlite "$(awk '/received/ {print "INSERT INTO SENT_MEDIA (MEDIA_ID) VALUES("$1");";}' <(sqlite3 mercuryms.sqlite "SELECT ID, PHONE_NUMBER, URI FROM MEDIA WHERE ID NOT IN (SELECT MEDIA_ID FROM SENT_MEDIA)" | timeout $TIMEOUT_SECONDS netcat $HOST $PORT))"
index 999d449..a950de8 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -9,3 +9,4 @@ sqlite3 /usr/share/mercuryms/mercuryms.sqlite "$(cat migrations/*)"
 chown mercuryms:mercuryms /usr/share/mercuryms/mercuryms.sqlite
 cp mercuryms.service /etc/systemd/system/
 cp mercuryms-listen* /etc/systemd/system/
+cp mercuryms-send* /etc/systemd/system/