Browse Source

[config] suppression du runtime directory, utilisation de /var/lib/pyheatpump

Maxime Alves LIRMM@home 3 years ago
parent
commit
d2c1e5aeda
2 changed files with 21 additions and 10 deletions
  1. 18
    7
      config/pre-exec.sh
  2. 3
    3
      config/pyheatpump_supervise.service

+ 18
- 7
config/pre-exec.sh View File

@@ -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;

+ 3
- 3
config/pyheatpump_supervise.service View File

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

Loading…
Cancel
Save