From 13efc23f2dafd8c97470471a221ee00a9c3e86d2 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 4 Aug 2022 08:14:04 +0200 Subject: [PATCH] systemd support added --- Makefile | 14 ++++++++++++++ __install__.py | 40 ++++++++++++++++++++++++++++++++++++++++ spotify.sh | 4 ++++ 3 files changed, 58 insertions(+) create mode 100644 Makefile create mode 100644 __install__.py create mode 100755 spotify.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..476cb32 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +UID=1000 +GID=1000 +SERVICE_PATH="/etc/systemd/system" + +help: + @echo "make install (with root priviliges) - to install service" + @echo "make start (with root priviliges) - to start service" + @echo "make enable (with root priviliges) - to enable service on boot" +install: + python __install__.py $(UID) $(GID) $(SERVICE_PATH) +start: + systemctl start spotify.service +enable: + systemctl enable spotify.service diff --git a/__install__.py b/__install__.py new file mode 100644 index 0000000..2a1f598 --- /dev/null +++ b/__install__.py @@ -0,0 +1,40 @@ +#!/bin/python +# +import os +import sys + +SERVICE_FILE = """ +[Unit] +Description=Spotify Service +After=mosquitto.target +[Service] +User=%(UID)d +Group=%(GID)d +ExecStart=%(MY_PATH)s/spotify.sh +Type=simple +[Install] +WantedBy=default.target +""" + + +def help(): + print("Usage: prog ") + +if __name__ == "__main__": + if len(sys.argv) == 4: + try: + uid = int(sys.argv[1]) + gid = int(sys.argv[2]) + except ValueError: + help() + else: + if os.path.isdir(sys.argv[3]): + with open(os.path.join(sys.argv[3], 'spotify.service'), "w") as fh: + fh.write(SERVICE_FILE % { + "MY_PATH": os.path.dirname(os.path.abspath(__file__)), + "UID": uid, + "GID": gid}) + else: + help() + else: + help() diff --git a/spotify.sh b/spotify.sh new file mode 100755 index 0000000..9755903 --- /dev/null +++ b/spotify.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# +BASEPATH=`dirname $0` +$BASEPATH/venv/bin/python $BASEPATH/spotify.py \ No newline at end of file