From ed4efd48c167d517b8e1052224379e76953be893 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 4 Aug 2022 08:13:35 +0200 Subject: [PATCH] systemd support added --- Makefile | 14 ++++++++++++++ __install__.py | 40 ++++++++++++++++++++++++++++++++++++++++ mpd.py => mpd_monitor.py | 0 mpd_monitor.sh | 4 ++++ 4 files changed, 58 insertions(+) create mode 100644 Makefile create mode 100644 __install__.py rename mpd.py => mpd_monitor.py (100%) create mode 100755 mpd_monitor.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a44774d --- /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 mpd_monitor.service +enable: + systemctl enable mpd_monitor.service diff --git a/__install__.py b/__install__.py new file mode 100644 index 0000000..e1746f5 --- /dev/null +++ b/__install__.py @@ -0,0 +1,40 @@ +#!/bin/python +# +import os +import sys + +SERVICE_FILE = """ +[Unit] +Description=MPD Monitor Service +After=mosquitto.target +[Service] +User=%(UID)d +Group=%(GID)d +ExecStart=%(MY_PATH)s/mpd_monitor.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], 'mpd_monitor.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/mpd.py b/mpd_monitor.py similarity index 100% rename from mpd.py rename to mpd_monitor.py diff --git a/mpd_monitor.sh b/mpd_monitor.sh new file mode 100755 index 0000000..6157e15 --- /dev/null +++ b/mpd_monitor.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# +BASEPATH=`dirname $0` +$BASEPATH/venv/bin/python $BASEPATH/mpd_monitor.py \ No newline at end of file