systemd support added
This commit is contained in:
parent
8a4e7f4f37
commit
13efc23f2d
14
Makefile
Normal file
14
Makefile
Normal file
@ -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
|
40
__install__.py
Normal file
40
__install__.py
Normal file
@ -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 <UID> <GID> <TARGET_PATH>")
|
||||||
|
|
||||||
|
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()
|
4
spotify.sh
Executable file
4
spotify.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
BASEPATH=`dirname $0`
|
||||||
|
$BASEPATH/venv/bin/python $BASEPATH/spotify.py
|
Loading…
x
Reference in New Issue
Block a user