taburineagle / NeewerLite-Python

NeewerLite-Python is an un-official cross-platform Neewer LED light control app - written in Python, originally based off of the NeewerLite macOS Swift project by @keefo (Xu Lian)
MIT License
60 stars 11 forks source link

TIP: Deamon modification to start on user session login #60

Open Desaydrone opened 1 year ago

Desaydrone commented 1 year ago

I use your script on my personal computer, and i want to only start deamon when my account logon, so i do a little modification on the daemon version.

No need to change the ownership of the files in the folder

Instead put the service file in /etc/systemd/system/ i put it in :

~/.config/systemd/user/

it's my user systemd service launch, in the service file i put this :

[Unit]
Description=Run NeewerLite-Python HTTP Daemon as a service

[Service]
ExecStart=python3 /opt/NeewerLite-Python/NeewerLite-Python.py --http
Restart=on-failure
RestartSec=10
StandardOutput=null
StandardError=journal

[Install]
WantedBy=default.target

I remove the two line of user and group, add the restart line (may be i need to add a force_instance in the exexstart line see with time)

and after that enable the systemd user

systemctl --user daemon-reload
systemctl --user enable neewerlite-python.service
systemctl --uset start neewerlite-python.service

and of course to be sure:

systemctl --user status neewerlite-python.service

result :

 neewerlite-python.service - Run NeewerLite-Python HTTP Daemon as a service
     Loaded: loaded (/home/my_user/.config/systemd/user/neewerlite-python.service; enabled; preset: disabled)
     Active: active (running) since Tue 2023-01-03 09:26:48 CET; 2s ago
   Main PID: 36296 (python3)
      Tasks: 1 (limit: 38264)
     Memory: 35.7M
        CPU: 174ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/neewerlite-python.service
             └─36296 python3 /opt/NeewerLite-Python/NeewerLite-Python.py --http

And voila it works only for my user :)

taburineagle commented 1 year ago

Excellent, thank you for posting about how you set this up!