From 18cc489b037f576dd2c746ed3945975733ea2cc8 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 8 Jul 2023 11:52:13 +0200 Subject: [PATCH] ncd-mqtt.service Run from systemd for startup, timestamps and logging --- mqtt-pgsql.sh | 4 +++- systemd/ncd-mqtt.service | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 systemd/ncd-mqtt.service diff --git a/mqtt-pgsql.sh b/mqtt-pgsql.sh index 2f8c2e8..1d66f99 100755 --- a/mqtt-pgsql.sh +++ b/mqtt-pgsql.sh @@ -1,8 +1,10 @@ #!/bin/sh -e +cd /home/dpavlin/eg5120 + mosquitto_sub -h localhost -t eg5120 | while read json ; do date=$( date +%Y-%m-%dT%H:%M:%S ) - echo -n $date ' ' + #echo -n $date ' ' echo $json | tee data/$date.json | tee /dev/shm/last-eg5120.json psql --quiet -c "copy eg5120 (json) from '/dev/shm/last-eg5120.json'" eg5120 done diff --git a/systemd/ncd-mqtt.service b/systemd/ncd-mqtt.service new file mode 100644 index 0000000..237d027 --- /dev/null +++ b/systemd/ncd-mqtt.service @@ -0,0 +1,12 @@ +[Unit] +Description=NCD MQTT + +[Service] +User=dpavlin +WorkingDirectory=/home/dpavlin +ExecStart=/home/dpavlin/eg5120/mqtt-pgsql.sh +Restart=always +RestartSec=1s + +[Install] +WantedBy=multi-user.target -- 2.20.1