Selaa lähdekoodia

systemd support added

master
Dirk Alders 2 vuotta sitten
vanhempi
commit
cd9ab64d54
3 muutettua tiedostoa jossa 58 lisäystä ja 0 poistoa
  1. 14
    0
      Makefile
  2. 40
    0
      __install__.py
  3. 4
    0
      powerplug.sh

+ 14
- 0
Makefile Näytä tiedosto

@@ -0,0 +1,14 @@
1
+UID=1000
2
+GID=1000
3
+SERVICE_PATH="/etc/systemd/system"
4
+
5
+help:
6
+	@echo "make install (with root priviliges) - to install service"
7
+	@echo "make start (with root priviliges) - to start service"
8
+	@echo "make enable (with root priviliges) - to enable service on boot"
9
+install:
10
+	python __install__.py $(UID) $(GID) $(SERVICE_PATH)
11
+start:
12
+	systemctl start powerplug.service
13
+enable:
14
+	systemctl enable powerplug.service

+ 40
- 0
__install__.py Näytä tiedosto

@@ -0,0 +1,40 @@
1
+#!/bin/python
2
+#
3
+import os
4
+import sys
5
+
6
+SERVICE_FILE = """
7
+[Unit]
8
+Description=Powerplug Service
9
+After=mosquitto.target
10
+[Service]
11
+User=%(UID)d
12
+Group=%(GID)d
13
+ExecStart=%(MY_PATH)s/powerplug.sh
14
+Type=simple
15
+[Install]
16
+WantedBy=default.target
17
+"""
18
+
19
+
20
+def help():
21
+    print("Usage: prog <UID> <GID> <TARGET_PATH>")
22
+
23
+if __name__ == "__main__":
24
+    if len(sys.argv) == 4:
25
+        try:
26
+            uid = int(sys.argv[1])
27
+            gid = int(sys.argv[2])
28
+        except ValueError:
29
+            help()
30
+        else:
31
+            if os.path.isdir(sys.argv[3]):
32
+                with open(os.path.join(sys.argv[3], 'powerplug.service'), "w") as fh:
33
+                    fh.write(SERVICE_FILE % {
34
+                        "MY_PATH": os.path.dirname(os.path.abspath(__file__)),
35
+                        "UID": uid,
36
+                        "GID": gid})
37
+            else:
38
+                help()
39
+    else:
40
+        help()

+ 4
- 0
powerplug.sh Näytä tiedosto

@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+#
3
+BASEPATH=`dirname $0`
4
+$BASEPATH/venv/bin/python $BASEPATH/powerplug.py

Loading…
Peruuta
Tallenna