Procházet zdrojové kódy

systemd support added

master
Dirk Alders před 2 roky
rodič
revize
ed4efd48c1
4 změnil soubory, kde provedl 58 přidání a 0 odebrání
  1. 14
    0
      Makefile
  2. 40
    0
      __install__.py
  3. 0
    0
      mpd_monitor.py
  4. 4
    0
      mpd_monitor.sh

+ 14
- 0
Makefile Zobrazit soubor

@@ -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 mpd_monitor.service
13
+enable:
14
+	systemctl enable mpd_monitor.service

+ 40
- 0
__install__.py Zobrazit soubor

@@ -0,0 +1,40 @@
1
+#!/bin/python
2
+#
3
+import os
4
+import sys
5
+
6
+SERVICE_FILE = """
7
+[Unit]
8
+Description=MPD Monitor Service
9
+After=mosquitto.target
10
+[Service]
11
+User=%(UID)d
12
+Group=%(GID)d
13
+ExecStart=%(MY_PATH)s/mpd_monitor.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], 'mpd_monitor.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()

mpd.py → mpd_monitor.py Zobrazit soubor


+ 4
- 0
mpd_monitor.sh Zobrazit soubor

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

Načítá se…
Zrušit
Uložit