From: Jacob Casper Date: Sun, 5 Apr 2020 08:07:45 +0000 (-0500) Subject: Timed job to tell listener to upload images to NextCloud X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=c9716b9597ab2274dc8f4448fd8d50a548d79ef5;p=mercuryms.git Timed job to tell listener to upload images to NextCloud --- 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/