소스 검색

systemd support added

master
Dirk Alders 2 년 전
부모
커밋
cd9ab64d54
3개의 변경된 파일58개의 추가작업 그리고 0개의 파일을 삭제
  1. 14
    0
      Makefile
  2. 40
    0
      __install__.py
  3. 4
    0
      powerplug.sh

+ 14
- 0
Makefile 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

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

Loading…
취소
저장