aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md16
-rw-r--r--energyscripts-SCRIPT@ADDRESS.service26
-rw-r--r--esphomeapi@.service17
-rw-r--r--mqtt_listener.service17
-rw-r--r--neohub_listener.service17
-rw-r--r--queue_runner.service17
-rw-r--r--scripts/common/queue.py5
-rw-r--r--scripts/queue_runner.py2
9 files changed, 49 insertions, 70 deletions
diff --git a/.gitignore b/.gitignore
index cc50e13..0c8da06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@
litequeue.db
litequeue.db-shm
litequeue.db-wal
+queue/
+
# test
test.py
diff --git a/README.md b/README.md
index 4c3444a..d0a9f96 100644
--- a/README.md
+++ b/README.md
@@ -47,8 +47,22 @@ pg_dump --schema-only --no-owner --no-privileges el
```
+## Systemd
-TODO:
+Example:
+
+```
+ln -s /opt/energyscripts/energyscripts-SCRIPT@ADDRESS.service /etc/systemd/system/energyscripts-mqtt_listener.service
+ln -s /opt/energyscripts/energyscripts-SCRIPT@ADDRESS.service /etc/systemd/system/energyscripts-esphomeapi@airgradient.local.net.service
+
+systemctl enable energyscripts-mqtt_listener.service energyscripts-esphomeapi@airgradient.local.net.service
+systemctl start energyscripts-mqtt_listener.service energyscripts-esphomeapi@airgradient.local.net.service
+journalctl -fu "energyscripts-*"
+
+```
+
+
+## TODO:
Put every state in `states`-table. Entities in an entity-table, and devices in
a device-table.
diff --git a/energyscripts-SCRIPT@ADDRESS.service b/energyscripts-SCRIPT@ADDRESS.service
new file mode 100644
index 0000000..ab26429
--- /dev/null
+++ b/energyscripts-SCRIPT@ADDRESS.service
@@ -0,0 +1,26 @@
+[Unit]
+Description = Simple service to start mqtt-listener
+StartLimitIntervalSec = 100
+StartLimitBurst = 5
+
+[Service]
+User = energy
+Group = energy
+
+Type = simple
+EnvironmentFile = /opt/energyscripts/.env
+WorkingDirectory = /opt/energyscripts
+ExecStart = /opt/energyscripts/venv/bin/python3 -u scripts/%j.py -a %i
+Restart = on-failure
+TimeoutStopSec = 70
+RestartSec = 30
+SyslogIdentifier = %N
+
+NoNewPrivileges = true
+ProtectHome = tmpfs
+ProtectSystem = full
+PrivateDevices = true
+ReadWritePaths = /opt/energyscripts/queue
+
+[Install]
+WantedBy = default.target
diff --git a/esphomeapi@.service b/esphomeapi@.service
deleted file mode 100644
index d10f8b4..0000000
--- a/esphomeapi@.service
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=Simple service to start esphomeapi
-StartLimitIntervalSec=100
-StartLimitBurst=5
-
-[Service]
-Type=simple
-EnvironmentFile=%h/energyscripts/.env
-WorkingDirectory=%h/energyscripts
-ExecStart=%h/energyscripts/venv/bin/python3 -u scripts/esphomeapi.py -a %i
-Restart=on-failure
-TimeoutStopSec=70
-RestartSec=30
-SyslogIdentifier=%N
-
-[Install]
-WantedBy=default.target
diff --git a/mqtt_listener.service b/mqtt_listener.service
deleted file mode 100644
index 1ae79ca..0000000
--- a/mqtt_listener.service
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=Simple service to start mqtt-listener
-StartLimitIntervalSec=100
-StartLimitBurst=5
-
-[Service]
-Type=simple
-EnvironmentFile=%h/energyscripts/.env
-WorkingDirectory=%h/energyscripts
-ExecStart=%h/energyscripts/venv/bin/python3 -u scripts/mqtt_listener.py
-Restart=on-failure
-TimeoutStopSec=70
-RestartSec=30
-SyslogIdentifier=%N
-
-[Install]
-WantedBy=default.target
diff --git a/neohub_listener.service b/neohub_listener.service
deleted file mode 100644
index 880d08f..0000000
--- a/neohub_listener.service
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=Simple service to start neohub listener
-StartLimitIntervalSec=100
-StartLimitBurst=5
-
-[Service]
-Type=simple
-EnvironmentFile=%h/energyscripts/.env
-WorkingDirectory=%h/energyscripts
-ExecStart=%h/energyscripts/venv/bin/python3 -u scripts/neohub.py
-Restart=on-failure
-TimeoutStopSec=70
-RestartSec=30
-SyslogIdentifier=%N
-
-[Install]
-WantedBy=default.target
diff --git a/queue_runner.service b/queue_runner.service
deleted file mode 100644
index 6b78068..0000000
--- a/queue_runner.service
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=Simple service to start queue-runner
-StartLimitIntervalSec=100
-StartLimitBurst=5
-
-[Service]
-Type=simple
-EnvironmentFile=%h/energyscripts/.env
-WorkingDirectory=%h/energyscripts
-ExecStart=%h/energyscripts/venv/bin/python3 -u scripts/queue_runner.py
-Restart=on-failure
-TimeoutStopSec=70
-RestartSec=30
-SyslogIdentifier=%N
-
-[Install]
-WantedBy=default.target
diff --git a/scripts/common/queue.py b/scripts/common/queue.py
index b4fa369..35abeaa 100644
--- a/scripts/common/queue.py
+++ b/scripts/common/queue.py
@@ -6,7 +6,10 @@ import pickle
import logging
from litequeue import SQLQueue
-QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
+QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
+QUEUE_DIR = os.environ.get('el_QUEUE_dir', 'queue')
+
+QUEUE_DB = QUEUE_DIR + "/" + QUEUE_DB
log = logging.getLogger(__name__)
diff --git a/scripts/queue_runner.py b/scripts/queue_runner.py
index fad223d..0264d83 100644
--- a/scripts/queue_runner.py
+++ b/scripts/queue_runner.py
@@ -10,6 +10,8 @@ from litequeue import SQLQueue
from common.postgres import dbi
QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
+QUEUE_DIR = os.environ.get('el_QUEUE_dir', 'queue')
+QUEUE_DB = QUEUE_DIR + "/" + QUEUE_DB
QUEUE_SLEEP = int(os.environ.get('el_QUEUE_sleep', 15)) # Default sleep 15 seconds when queue empty
# Unlock all