Add Ubuntu user service support

This commit is contained in:
ltadeu6 2026-05-11 18:47:10 -03:00
parent 2b47db77eb
commit 0d61eb6311
No known key found for this signature in database
GPG key ID: FB9FDAB6B6F3418D
5 changed files with 95 additions and 5 deletions

View file

@ -1,7 +1,12 @@
PY ?= python3
VENV ?= .venv
SERVICE_NAME ?= music-light.service
SYSTEMD_USER_DIR ?= $(HOME)/.config/systemd/user
SERVICE_FILE := $(SYSTEMD_USER_DIR)/$(SERVICE_NAME)
CONFIG_DIR ?= $(HOME)/.config/music-light
ENV_FILE ?= $(CONFIG_DIR)/env
.PHONY: venv deps run
.PHONY: venv deps run service-env install-service uninstall-service start-service stop-service restart-service status-service logs-service
venv:
$(PY) -m venv $(VENV)
@ -13,3 +18,32 @@ deps: venv
run: deps
$(VENV)/bin/python luz-musica.py
service-env:
install -d $(CONFIG_DIR)
test -f $(ENV_FILE) || install -m 600 music-light.env.example $(ENV_FILE)
install-service: deps service-env
install -d $(SYSTEMD_USER_DIR)
printf '%s\n' '[Unit]' 'Description=Music Light album-art color sync' 'After=graphical-session.target' 'Wants=graphical-session.target' '' '[Service]' 'Type=simple' 'WorkingDirectory=$(CURDIR)' 'Environment=PYTHONUNBUFFERED=1' 'Environment=PLAYERCTL_BIN=/usr/bin/playerctl' 'EnvironmentFile=-%h/.config/music-light/env' 'ExecStart=$(abspath $(VENV))/bin/python $(CURDIR)/luz-musica.py' 'Restart=always' 'RestartSec=5' '' '[Install]' 'WantedBy=default.target' > $(SERVICE_FILE)
systemctl --user daemon-reload
systemctl --user enable --now $(SERVICE_NAME)
uninstall-service:
systemctl --user disable --now $(SERVICE_NAME) || true
rm -f $(SERVICE_FILE)
systemctl --user daemon-reload
start-service:
systemctl --user start $(SERVICE_NAME)
stop-service:
systemctl --user stop $(SERVICE_NAME)
restart-service:
systemctl --user restart $(SERVICE_NAME)
status-service:
systemctl --user status $(SERVICE_NAME)
logs-service:
journalctl --user -u $(SERVICE_NAME) -f