4 Commits

Author SHA1 Message Date
  Maxime Alves LIRMM@home 8a4438bdf6 ajout de StateDirectoryMode 0700 3 years ago
  Maxime Alves LIRMM@home 65d78031ba [config] fix du path de la DB 3 years ago
  Maxime Alves LIRMM@home d2c1e5aeda [config] suppression du runtime directory, utilisation de /var/lib/pyheatpump 3 years ago
  Maxime Alves LIRMM e78946877c [isssue #25] add except for socket.gaierror 3 years ago
4 changed files with 32 additions and 15 deletions
  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 View File

1
 #!/bin/sh
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
 # cd /opt/pyheatpump git clone https://git.yannweb.net/cli/pyHeatpump.git
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
 # Database initialization
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
     || (echo "Failed to initialize database" && exit 1);
20
     || (echo "Failed to initialize database" && exit 1);
21
+fi
14
 
22
 
15
 # Default configuration setup
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
     || (echo "Failed to initialized configuration file" && exit 1);
27
     || (echo "Failed to initialized configuration file" && exit 1);
28
+fi
18
 
29
 
19
 exit 0;
30
 exit 0;

+ 1
- 1
config/pyheatpump.prod.ini.dist View File

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

+ 4
- 3
config/pyheatpump_supervise.service View File

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

+ 9
- 4
pyheatpump/cli.py View File

7
 import json
7
 import json
8
 import os
8
 import os
9
 import re
9
 import re
10
+import socket
10
 import sys
11
 import sys
11
 import time
12
 import time
12
 import urllib
13
 import urllib
191
         **{'path': get_path}
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
     control_data = get_resp.json()
204
     control_data = get_resp.json()
200
     if Heatpump(mac_address).control(control_data):
205
     if Heatpump(mac_address).control(control_data):

Loading…
Cancel
Save