Taxel / PlexTraktSync

A python script that syncs the movies, shows and ratings between trakt and Plex (without needing a PlexPass or Trakt VIP subscription)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watch doesn't work via systemd

ronilaukkarinen opened this issue · comments

Confirmation

  • I have read the README.md on the project homepage
  • I have checked if identical issue already exists
  • I have tried downgrading to find version that can be used as a workaround

The problem

The command works, if I run it directly:

/home/rolle/apps/PlexTraktSync/plextraktsync.sh watch

But for some reason systemd service (user level) doesn't work, my template is:

[Unit]
Description=PlexTraktSync watch daemon
After=network-online.target

[Service]
ExecSearchPath=%h/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStart=/home/rolle/apps/PlexTraktSync/plextraktsync.sh watch
Restart=on-failure
RestartSec=10
User=user
Group=user

[Install]
WantedBy=multi-user.target

Daemon reloaded and everything but it always fails. Why?

$ systemctl --user status plextraktsync
● plextraktsync.service - PlexTraktSync watch daemon
   Loaded: loaded (/home/rolle/.config/systemd/user/plextraktsync.service; enabled; vendor preset: e
   Active: activating (auto-restart) (Result: exit-code) since Tue 2024-02-27 12:02:47 CET; 7s ago
  Process: 47301 ExecStart=/home/rolle/apps/PlexTraktSync/plextraktsync.sh watch (code=exited, statu
 Main PID: 47301 (code=exited, status=217/USER)

Feb 27 12:02:47 leda systemd[2075]: plextraktsync.service: Failed with result 'exit-code'.

Steps to reproduce the behavior

  1. Install normally
  2. Add systemd service with the instructions on the README (user level)

Error trace / logs

No response

Expected behavior

Should continue running on background.

Inspect of problematic items

No response

Workarounds

No response

Install method

git clone (not supported)

Config file contents

No response

Version

0.28.0dev0: 22866de

Python Version

3.8.18

Plex Server Version

1.40.0.7998-c29d4c0c8

Operating System and Version

Debian 5.10.179-5~deb10u1 (2023-08-08) x86_64 GNU/Linux

  1. fix typos in your bugreport (title)
  2. use pipx installation (do not use git install unless you're a developer)
  3. follow systemd user installation from readme, it also includes commands how to obtain journal logs

I do not have root or pipx access, and user journalctl displays nothing. Git version works fine via command so I do not see the issue here in that regard.

$ journalctl -u "plextraktsync.service"
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
-- Logs begin at Tue 2024-02-27 21:42:06 CET, end at Wed 2024-02-28 13:32:15 CET. --
-- No entries --

obvuously you need --user to journalctl as well. and pipx can be installed as user

typo not fixed in title

obvuously you need --user to journalctl as well. and pipx can be installed as user

Typo not fixed in the comment. 🤪
Nitpicking in things like this really serves no purpose.

Managed to get it working myself. The correct user log command is (to skip to the end like with tail):

journalctl -u --user --user-unit=plextraktsync --all -f

This reveals more about the issue:

Feb 29 12:25:07 <hidden> systemd[2774]: plextraktsync.service: Failed at step USER spawning /home/rolle/apps/PlexTraktSync/plextraktsync.sh: No such process

And later:

Feb 29 12:38:48 <hidden> systemd[128514]: plextraktsync.service: Failed to determine supplementary groups: Operation not permitted
Feb 29 12:38:48 <hidden> systemd[128514]: plextraktsync.service: Failed at step GROUP spawning /home/rolle/.local/bin/plextraktsync: Operation not permitted
Feb 29 12:38:48 <hidden> systemd[2075]: plextraktsync.service: Main process exited, code=exited, status=216/GROUP
Feb 29 12:38:48 <hidden> systemd[2075]: plextraktsync.service: Failed with result 'exit-code'.

What I did I installed pipx locally, then installed plextraktsync via that way, then simplified my systemdservice:

nano ~/.config/systemd/user/plextraktsync.service

As:

[Unit]
Description=PlexTraktSync watch daemon
After=network-online.target

[Service]
ExecStart=/home/rolle/.local/bin/plextraktsync watch
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Obviously then:

systemctl --user daemon-reload
systemctl --user restart plextraktsync
$ systemctl --user status plextraktsync.service
● plextraktsync.service - PlexTraktSync watch daemon
   Loaded: loaded (/home/rolle/.config/systemd/user/plextraktsync.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2024-02-29 12:39:44 CET; 5s ago
 Main PID: 9038 (plextraktsync)
   CGroup: /user.slice/user-1020.slice/user@1020.service/plextraktsync.service
           └─9038 /home2/rolle/.local/pipx/venvs/plextraktsync/bin/python /home/rolle/.local/bin/plextraktsync watch

Feb 29 12:39:44 <hidden> systemd[2075]: Started PlexTraktSync watch daemon.
Feb 29 12:39:45 <hidden> plextraktsync[9038]: INFO     Listening for events!
Feb 29 12:39:45 <hidden> plextraktsync[9038]: INFO     Starting AlertListener:
Feb 29 12:39:45 <hidden> plextraktsync[9038]:          ws://<hidden>:/websockets/notifications?X-Plex-Token=<hidden
Feb 29 12:39:45 <hidden> plextraktsync[9038]:          >
Feb 29 12:39:45 <hidden> plextraktsync[9038]: INFO     Websocket connected

I hope this helps the future users. Thanks for all the help @glensc ❤️

seems PR for journalctl -u --user is needed

you can make unit file more universal by using %h

Random person here, I did want to clarify that the issues here (code 217 and 216) stem from you putting this in a user unit:

User=user
Group=user

You don't need these here and it limits the permissions of your user arbitrarily so it can't access everything you regularly can. If you specified these with the pipx solution it would likely have the same errors.

Additionally you will need loginctl enable-linger if you are running this on a server and you don't want this unit to be killed when your sessions end.