Ver código fonte

systemd support added

master
Dirk Alders 2 anos atrás
pai
commit
13efc23f2d
3 arquivos alterados com 58 adições e 0 exclusões
  1. 14
    0
      Makefile
  2. 40
    0
      __install__.py
  3. 4
    0
      spotify.sh

+ 14
- 0
Makefile Ver arquivo

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

+ 40
- 0
__install__.py Ver arquivo

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

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

Carregando…
Cancelar
Salvar