Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plex-core to support synology packages #247

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

myellen
Copy link

@myellen myellen commented Nov 28, 2018

Checks DISTRO variable in getPlexVersion and parseVersion to see if script is running on synology.

Fixes #245

@demonbane
Copy link
Collaborator

Is it even possible to install Plex from the command-line on a Synology NAS? I have one that I've got root SSH access on, but I don't know of any way to install the .spk packages from the command-line.

@abl
Copy link

abl commented Dec 23, 2018

@demonbane synopkg install <path to .spk file> as root looks like it does the trick.

@demonbane
Copy link
Collaborator

That's great! Ok, so this can be added because it is an officially supported platform from Plex, but there are a couple of issues that need to be addressed first. In addition to downloading the Synology package, this should also support:

  • Installing the package
  • Starting and stopping the package before/after installation if necessary (I'm not familiar with how synopkg works, so if it already does this automatically then it can be skipped)
  • Verify that the script is running in a bash 4+ environment. DSM was shipping a 3.x bash version until recently, so some users might still have an old version of bash which won't work.
  • Any additional logic specific to how Synology handles packages that I haven't listed here.

@myellen
Copy link
Author

myellen commented Feb 9, 2019

Do you mean installing the package for the first time? or using your plexupdate installer script? It does handle installing the package using manual setup (but the user does have to follow the instructions on this page first to trust plex packages). I haven't modified installer.sh to detect the synology distro, so installer.sh wont work.

synopkg automatically starts and stops the package for installation.

I don't have an older version of dsm to test with. However, the changes I made don't use any bash functions that weren't already present in the script, so I'd assume it works fine in bash 3.x.

@demonbane
Copy link
Collaborator

I did a bit of digging and it looks like most (all?) versions of DSM 6 already include bash 4 so I think that should be ok. The existing code is already pretty heavily dependent on bash 4 which is why I mentioned it.

For installation, it would be great if you update installer.sh to support initial setup as well, but the only requirement would be that plexupdate can auto-install the update after downloading it (presumably using the synopkg command provided above).

There should also be some logic added to try to determine if we're running on a synology automatically so that it doesn't have to be specified via an environment variable:

plexupdate/plexupdate.sh

Lines 298 to 315 in 293e6d5

if [ -z "${DISTRO_INSTALL}" ]; then
if [ -z "${DISTRO}" -a -z "${BUILD}" ]; then
# Detect if we're running on redhat instead of ubuntu
if [ -f /etc/redhat-release ]; then
REDHAT=yes
BUILD="linux-ubuntu-${ARCH}"
DISTRO="redhat"
if ! hash dnf 2>/dev/null; then
DISTRO_INSTALL="${REDHAT_INSTALL/dnf/yum}"
else
DISTRO_INSTALL="${REDHAT_INSTALL}"
fi
else
REDHAT=no
BUILD="linux-ubuntu-${ARCH}"
DISTRO="ubuntu"
DISTRO_INSTALL="${DEBIAN_INSTALL}"
fi

I'm excited to see this added, so I'll try to be as responsive as possible to any questions you have so we can get this merged soon. Thanks for working on this!

@myellen
Copy link
Author

myellen commented Feb 12, 2019

I patched plexupdate.sh to detect synology and to work with the new 5.json naming scheme.

I updated installer.sh too. Where does installer.sh set the BUILD variable? or is it not necessary? I define DISTRO and DISTRO_INSTALL inside of check_distro().

@bruvv
Copy link

bruvv commented Apr 16, 2019

any update on this? I am still receiving an issue: #259

@myellen
Copy link
Author

myellen commented Apr 16, 2019

@d1slact0r no. you can manually download plexupdate-core and plexupdate.sh from my pull request and replace the versions you have on your synology now

plexupdate.sh Outdated Show resolved Hide resolved
plexupdate.sh Outdated Show resolved Hide resolved
plexupdate.sh Outdated Show resolved Hide resolved
@BradleyMarie
Copy link

I believe you also need to update the AUTOSTART section to add handling for using synopkg to start the job after the update completes.

@demonbane
Copy link
Collaborator

This fork is from an older release which still has the old API endpoints and build designations. It should be rebased to the current HEAD from upstream.

checks DISTRO variable in getPlexVersion and parseVersion
change cut to return field 2 and 3 instead of just 2
update plexupdate.sh to automatically determine if we're running on a synology
add ability to detect if running on synology in installer.sh
add spaces before closing brackets
changed spaces to tabs
@myellen
Copy link
Author

myellen commented Jun 5, 2019

I believe you also need to update the AUTOSTART section to add handling for using synopkg to start the job after the update completes.

It's been working for me without that, but I'll double check

This fork is from an older release which still has the old API endpoints and build designations. It should be rebased to the current HEAD from upstream.

I just rebased it.

remove check for plexpass version as now public versions also use new build versions.
Copy link
Collaborator

@demonbane demonbane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me. Once the changes are done I'll try installing Plex on my Synology at home so I can test it locally and then we can get it merged upstream. Thanks very much for working on this!

@@ -228,13 +228,17 @@ isNewerVersion() {
parseVersion() {
if [ "${REDHAT}" = "yes" ]; then
cut -f2- -d- <<< "$1" | cut -f1-4 -d.
elif [ "${DISTRO}" = "synology" ]; then
cut -f2-3 -d- <<< "$1"
else
cut -f2 -d_ <<< "$1"
fi
}

getPlexVersion() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, functions like these should generally start with the "default" option (Ubuntu/Debian) and then go on to the other cases. It's just a bit confusingly written right now because of how the REDHAT variable is used. I'd suggest swapping the two first cases and adding a comment (which I really should have done when I wrote the function 🤦‍♂ ), about what the "${REDHAT}" != "yes" does.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way GitHub is rendering this is a bit confusing. The comment is about the getPlexVersion function, not isNewerVersion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if I just switch the cases like so

	if [ "${REDHAT}" != "yes" ]; then
		dpkg-query --showformat='${Version}' --show plexmediaserver 2>/dev/null
	elif [ "${DISTRO}" = "synology" ]; then
		synopkg version "Plex Media Server" 2>/dev/null

I don't think the switch ever reaches the synology case because "${REDHAT}" != "yes" is true for synology devices too.

I'm not sure how best to change it.

plexupdate.sh Outdated Show resolved Hide resolved
@demonbane
Copy link
Collaborator

Now that we're going to have 3 supported platforms, I think it's also time to retire the REDHAT variable altogether as well. If you'd like to take a stab at it I'd really appreciate it, but if not I can try to do it myself later.

BUILD="linux-${ARCH}" is already done at line 56

Co-Authored-By: Alex Malinovich <alexmalinovich@gmail.com>
@myellen
Copy link
Author

myellen commented Jun 6, 2019

Before you install it on your synology, you'll have to follow the instructions in How to add Plex’s package signing public key to Synology NAS Package Center. That link should be added to the readme or the wiki.

re: redhat, I don't have any linux boxes to test with, and I'm not very familiar with them anyways. So unfortunately, I'm not really comfortable making those changes.

Add link to "How to add Plex’s package signing public key to Synology NAS Package Center"
@myellen
Copy link
Author

myellen commented Jun 6, 2019

I added it to the README since you need to do that step whether you use automatic or manual setup.

@demonbane
Copy link
Collaborator

Can the package signing key stuff be done via the command line? That would be a great thing to add to installer.sh.

@demonbane
Copy link
Collaborator

We could skip that check altogether, but my synology does have an /etc/crontab and /etc/cron.d that should work.

The installer only knows how to put a file into /etc/cron.daily right now anyway (though I am planning support for systemd timers at some point), so I don't think mentioning cron would be useful here.

What I'd love would be if the installer can just create a Task Scheduler task from the command line, but I'm not having much luck in finding a way to do it. synoschedtask seems to only be able to operate on already defined tasks, not set up a new one, and synowebapi could almost certainly do it, but I can't find any public API documentation on the Task Scheduler interface.

That would still be my preferred solution, but if we can't find a way to do it then we can at least print a link to a (soon to be written) wiki article on how to set up a scheduled task on Synology. (just need to short-circuit the logic at the top of configure_cron)

@myellen
Copy link
Author

myellen commented Jun 13, 2019

The GUI task scheduler just adds the tasks to /etc/crontab using synoschedtask. In my crontab 0 6 * * * root /usr/syno/bin/synoschedtask --run id=16 is the line for plexupdate.

We should be able to add a line to /etc/crontab, link cronwrapper inside of /etc/cron.d, or create a /etc/cron.daily folder to use.

@demonbane
Copy link
Collaborator

Do you know if cron job output will still get sent to the admin? I have a couple of scheduled tasks on my NAS and when they run I get an HTML email from Synology showing the output which leads me to believe that notifications are handled by synoschedtask, not the usual cron mail configuration.

@demonbane
Copy link
Collaborator

Oh, and the system crontab has MAILTO="" right at the top, so I guess that answers that question. :)

Ok, so in that case we can still add the job, we just need to provide a warning that on Synology you won't get any output. Any thoughts on a good flow to use in the installer that'll also be portable to other Linux systems that may not use the cron.daily setup?

@myellen
Copy link
Author

myellen commented Jun 14, 2019

I think if there's no cron.daily, it should check for cron.d. If it finds cron.d, change CRONWRAPPER to /etc/cron.d/plexupdate, then create a crontab file named plexupdate in cron.d with one line that just calls the cronwrapper as a script like 0 6 * * * root /path/to/plexupdate/cronwrapper.

So add some logic around line 235 and around line 277 to check CRONWRAPPER and switch to something like echo "0 6 * * * root ${FULL_PATH}/extras/cronwrapper" > "$CRONWRAPPER"

extras/installer.sh Outdated Show resolved Hide resolved
@demonbane
Copy link
Collaborator

I agree with everything except:

I think if there's no cron.daily, it should check for cron.d.

At the time, using cron.daily was just the simplest way of implementing this, but if we're going to just use cron.d might as well use it by default and get rid of cron.daily altogether.

Since installer.sh is meant to be run multiple times without problems, there should be some code to migrate an old cron.daily setup to cron.d. (for bonus points, grab the cron.daily time in crontab and use that in the cron.d entry. And if cron.daily/plexupdate isn't a symlink just assume they've got a custom setup and exit the cron logic without any changes/questions)

Use new crontab file file in cron.d instead of cron.daily to support more devices
@myellen
Copy link
Author

myellen commented Jun 19, 2019

I changed the cron support to use cron.d instead of cron.daily. There's not anything to migrate since it still uses /etc/plexupdate.cron.conf for settings, and that file gets overwritten every time you run installer.sh anyways. But it does remove the old file in cron.daily if its a symlink.

I look for a cron.daily job in crontab for the time, otherwise I just picked 4 am. May be something we prompt the user for.

I'm having some weird trouble with it running though. The cron job runs at the right time, and it does run the cronwrapper, and that does run plexupdate.sh, but it doesn't actually update. However if I manually run cronwrapper, it works fine. Maybe something with permissions or something weird with cron. So I'm curious if it's just my machine it happens on.

@myellen
Copy link
Author

myellen commented Jun 19, 2019

On second look, it might be because I don't include PATH in the new cron file...

@myellen
Copy link
Author

myellen commented Jun 19, 2019

yeah, that fixed it. Should be all good now.

@deepfriedmind
Copy link

So, is this about to be merged, or..?

@demonbane
Copy link
Collaborator

Hopefully late next week. I’ve been traveling the last few weeks and haven’t had a chance to review the latest updates, but it’s on my list as soon as I get back.

@deepfriedmind
Copy link

I've checked out this pull request and it still seems that PMS isn't started again after an update.

@myellen
Copy link
Author

myellen commented Nov 25, 2019

@deepfriedmind Which Synology and DSM version are you using? It’s been working for me on a ds916+ and dsm 6.

@deepfriedmind
Copy link

deepfriedmind commented Nov 25, 2019

I'm using a DS916+ on DSM 6.2.2-24922 Update 4.

@myellen
Copy link
Author

myellen commented Nov 26, 2019

Here are my troubleshooting questions:

  • Is AUTOSTART=‘yes’ In your configuration file?

  • Are DISTRO and/or DISTRO_INSTALL already defined in your configuration file?

  • Does the file /etc/synoinfo.conf exist on your Synology?

  • What happens if you use ssh and run synopkg start “Plex Media Server”?

  • Does synopokg list --name show a name for plex different form “Plex Media Server”?

@gapple
Copy link

gapple commented Dec 2, 2020

I was able to install and configure this branch successfully on a DS418 with DSM 6.2.3-25426 Update 2

@gapple
Copy link

gapple commented Aug 6, 2021

This no longer appears to work on DSM 7; it looks like there is a new DISTRO: synology-dsm7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parseVersion does not recognize Synology package versions correctly
7 participants