4 Ревизии

Автор SHA1 Съобщение Дата
  Maxime Alves LIRMM@home 8a4438bdf6 ajout de StateDirectoryMode 0700 преди 3 години
  Maxime Alves LIRMM@home 65d78031ba [config] fix du path de la DB преди 3 години
  Maxime Alves LIRMM@home d2c1e5aeda [config] suppression du runtime directory, utilisation de /var/lib/pyheatpump преди 3 години
  Maxime Alves LIRMM e78946877c [isssue #25] add except for socket.gaierror преди 3 години
променени са 4 файла, в които са добавени 32 реда и са изтрити 15 реда
  1. 18
    7
      config/pre-exec.sh
  2. 1
    1
      config/pyheatpump.prod.ini.dist
  3. 4
    3
      config/pyheatpump_supervise.service
  4. 9
    4
      pyheatpump/cli.py

+ 18
- 7
config/pre-exec.sh Целия файл

@@ -1,19 +1,30 @@
1 1
 #!/bin/sh
2
+REPO_DIR=/opt/pyHeatpump
3
+LIB_DIR=/var/lib/pyheatpump
4
+
2 5
 
3
-# If directory exists don't run the script
4 6
 # cd /opt/pyheatpump git clone https://git.yannweb.net/cli/pyHeatpump.git
5
-[ ! -d /opt/pyHeatpump/ ] && echo "Missing /opt/pyHeatpump/" && exit 1;
6
-[ ! -d /run/pyheatpump/ ] && echo "Missing /run/pyheatpump/" && exit 1;
7
+[ ! -d $REPO_DIR ] \
8
+  && echo "Missing $REPO_DIR" \
9
+  && exit 1;
7 10
 
8
-[ -f /run/pyheatpump/pyheatpump.sqlite3 ] && [ -f /run/pyheatpump/pyheatpump.ini ] \
9
-        && echo "Incorrect runtime directory" && exit 1;
11
+[ ! -d /var/lib/pyheatpump ] && mkdir --mode 0700 /var/lib/pyheatpump
12
+# If files already exist don't var/lib the script
13
+[ -f $LIB_DIR/pyheatpump.sqlite3 ] && [ -f $LIB_DIR/pyheatpump.ini ] \
14
+  && exit 0;
10 15
 
11 16
 # Database initialization
12
-sqlite3 -init /opt/pyHeatpump/db/pyheatpump.sql /run/pyheatpump/pyheatpump.sqlite3 .quit \
17
+if [ ! -f $LIB_DIR/pyheatpump.sqlite3 ];
18
+then
19
+  sqlite3 -init $REPO_DIR/db/pyheatpump.sql $LIB_DIR/pyheatpump.sqlite3 .quit \
13 20
     || (echo "Failed to initialize database" && exit 1);
21
+fi
14 22
 
15 23
 # Default configuration setup
16
-cp /opt/pyHeatpump/config/pyheatpump.prod.ini.dist /run/pyheatpump/pyheatpump.ini \
24
+if [ ! -f $LIB_DIR/pyheatpump.ini ];
25
+then
26
+  cp $REPO_DIR/config/pyheatpump.prod.ini.dist $LIB_DIR/pyheatpump.ini \
17 27
     || (echo "Failed to initialized configuration file" && exit 1);
28
+fi
18 29
 
19 30
 exit 0;

+ 1
- 1
config/pyheatpump.prod.ini.dist Целия файл

@@ -4,7 +4,7 @@ baudrate = 19200
4 4
 mac_address = None
5 5
 ip_address = dhcp
6 6
 read_only = True
7
-database = /run/pyheatpump/pyheatpump.sqlite3
7
+database = /var/lib/pyheatpump/pyheatpump.sqlite3
8 8
 
9 9
 [supervisor]
10 10
 scheme = https

+ 4
- 3
config/pyheatpump_supervise.service Целия файл

@@ -4,11 +4,12 @@ Wants=dev-rs485.device
4 4
 
5 5
 [Service]
6 6
 Type=simple
7
-RuntimeDirectory=pyheatpump
8
-WorkingDirectory=/run/pyheatpump
7
+StateDirectory=pyheatpump
8
+StateDirectoryMode=0700
9
+WorkingDirectory=/var/lib/pyheatpump
9 10
 Environment="LOGLEVEL=INFO"
10 11
 ExecStartPre=/opt/pyHeatpump/config/pre-exec.sh
11 12
 ExecStart=/usr/bin/env pyheatpump supervise --since
12 13
 KillMode=mixed
13 14
 TimeoutStopSec=30sec
14
-PrivateTmp=true
15
+PrivateTmp=false

+ 9
- 4
pyheatpump/cli.py Целия файл

@@ -7,6 +7,7 @@ import time
7 7
 import json
8 8
 import os
9 9
 import re
10
+import socket
10 11
 import sys
11 12
 import time
12 13
 import urllib
@@ -191,10 +192,14 @@ def supervise(since):
191 192
         **{'path': get_path}
192 193
     }
193 194
 
194
-    get_resp = requests.get(
195
-        url=build_url(get_url),
196
-        verify=False
197
-    )
195
+    try:
196
+        get_resp = requests.get(
197
+            url=build_url(get_url),
198
+            verify=False
199
+        )
200
+    except socket.gaierror as exc:
201
+        logger.error('Socket error : %s', exc)
202
+        sys.exit(-1)
198 203
 
199 204
     control_data = get_resp.json()
200 205
     if Heatpump(mac_address).control(control_data):

Loading…
Отказ
Запис