mdhiggins / PlexAutoSkip

Automatically skip content in Plex
MIT License
198 stars 11 forks source link

Run as a service? #35

Closed DevMan01 closed 1 year ago

DevMan01 commented 1 year ago

Hey there, looking for the best recommendations / instructions for installing this program as a service at boot up?

Build:

OS:

Distributor ID: Ubuntu Description: Ubuntu 22.04.2 LTS Release: 22.04 Codename: jammy

PMS:

Plex Server Version: 1.31.1.6716

Python:

Version: 3.10.6

mdhiggins commented 1 year ago

https://askubuntu.com/questions/905749/running-python-script-as-a-service-and-start-on-system-start-up

I use system.d inside the docker container with combination of s6 to run the script as service, I'd probably recommend creating a system.d service in a similar fashion. The s6 part isn't required but is just how the parent linuxserver container is setup but it should translate to Ubuntu fine

DevMan01 commented 1 year ago

Steps to solve for the next chap:

  1. Go to /etc/systemd/system/
  2. Create a new service: sudo vim PlexAutoSkip.service
  3. Paste this template and modify accordingly:
# Plex Auto Skip Service
[Unit]
Description=Plex Autoskip

[Service]
#User=YOUR_USER
#Group=YOUR_USER_GROUP
Type=simple
Environment=LC_ALL=C.UTF-8
Environment=LANG=C.UTF-8
WorkingDirectory=/PATH/TO/MAIN.PY
ExecStart=/usr/bin/python3 /PATH/TO/MAIN/main.py
Restart=always
RestartSec=10

[Install]
WantedBy=default.target
  1. Load the new service: sudo systemctl --system daemon-reload
  2. Enable for boot up: sudo systemctl enable PlexAutoSkip.service
  3. Start the service: sudo systemctl start PlexAutoSkip.service
  4. To debug / look under the hood: sudo journalctl -f -u PlexAutoSkip.service
mdhiggins commented 1 year ago

Nice write up, I copied this over to the wiki for future users, thanks for sharing

https://github.com/mdhiggins/PlexAutoSkip/wiki/Run-as-Service-Linux