From c9716b9597ab2274dc8f4448fd8d50a548d79ef5 Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sun, 5 Apr 2020 03:07:45 -0500 Subject: [PATCH] Timed job to tell listener to upload images to NextCloud --- mercuryms-send.service | 17 +++++++++++++++++ mercuryms-send.timer | 10 ++++++++++ send.sh | 2 ++ setup.sh | 1 + 4 files changed, 30 insertions(+) create mode 100644 mercuryms-send.service create mode 100644 mercuryms-send.timer create mode 100755 send.sh diff --git a/mercuryms-send.service b/mercuryms-send.service new file mode 100644 index 0000000..2aebec6 --- /dev/null +++ b/mercuryms-send.service @@ -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 index 0000000..314ce39 --- /dev/null +++ b/mercuryms-send.timer @@ -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 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))" diff --git a/setup.sh b/setup.sh index 999d449..a950de8 100755 --- 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/ -- 2.20.1