plexupdate icon indicating copy to clipboard operation
plexupdate copied to clipboard

Update plex-core to support synology packages

Open myellen opened this issue 5 years ago • 38 comments

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

Fixes #245

myellen avatar Nov 28 '18 17:11 myellen

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.

demonbane avatar Dec 20 '18 01:12 demonbane

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

abl avatar Dec 23 '18 19:12 abl

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.

demonbane avatar Dec 23 '18 23:12 demonbane

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.

myellen avatar Feb 09 '19 21:02 myellen

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:

https://github.com/mrworf/plexupdate/blob/293e6d5ecbe6f41536a054fe91445c5cdd0d0c10/plexupdate.sh#L298-L315

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!

demonbane avatar Feb 11 '19 01:02 demonbane

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().

myellen avatar Feb 12 '19 17:02 myellen

any update on this? I am still receiving an issue: https://github.com/mrworf/plexupdate/issues/259

bruvv avatar Apr 16 '19 17:04 bruvv

@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

myellen avatar Apr 16 '19 18:04 myellen

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

BradleyMarie avatar May 30 '19 07:05 BradleyMarie

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.

demonbane avatar May 31 '19 18:05 demonbane

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.

myellen avatar Jun 05 '19 18:06 myellen

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.

demonbane avatar Jun 05 '19 20:06 demonbane

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.

myellen avatar Jun 06 '19 03:06 myellen

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

myellen avatar Jun 06 '19 03:06 myellen

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

demonbane avatar Jun 06 '19 03:06 demonbane

There's definitely no documented way to install the certificate. It's possible there's a hack-y way to do it. None of the programs I've checked in /usr/syno/bin/ so far can do it.

myellen avatar Jun 06 '19 03:06 myellen

Ok, in that case we'll also need some code in both plexupdate and installer.sh that checks if synopkg threw an error related to the certificate and, if so, display a link to the Plex instructions for adding a key.

demonbane avatar Jun 06 '19 03:06 demonbane

Just tested this on my synology and it partially worked. The package was installed, but it didn't automatically get started. I saw that synopkg install has a --daemon-reload option but I'm not sure if that'll do what we want or not.

Also, since it looks like DSM doesn't have a standard cron setup, installer.sh should probably just skip the cron setup parts altogether if DISTRO==synology.

demonbane avatar Jun 06 '19 04:06 demonbane

Just tested this on my synology and it partially worked. The package was installed, but it didn't automatically get started. I saw that synopkg install has a --daemon-reload option but I'm not sure if that'll do what we want or not.

I believe this can be resolved by adding handing to the AUTOSTART section for Synology. I did this on my own box to resolve the same issue on my box.

BradleyMarie avatar Jun 10 '19 02:06 BradleyMarie

Just tested this and it looks like --daemon-reload is only good for throwing an error and doesn't appear to do anything. I did try a new install as well as an upgrade, and in both cases the service is stopped and disabled but not automatically started afterwards.

Adding synopkg start "Plex Media Server" to the AUTOSTART logic should take care of both use cases.

demonbane avatar Jun 10 '19 21:06 demonbane

added an error message with instructions to go to the website and updated the autostart. I also hid the plexpass password when you type it in.

Also, since it looks like DSM doesn't have a standard cron setup, installer.sh should probably just skip the cron setup parts altogether if DISTRO==synology.

When I run the installer, I just get the "It seems like you don't have a supported cron job setup, please see README.md for more details" message and the installation works fine. We could skip that check altogether, but my synology does have an /etc/crontab and /etc/cron.d that should work. However, I think the preferred method on synology should be to use the Task Scheduler in DSM. You'd only need a short page in the wiki to explain how to set it up.

myellen avatar Jun 13 '19 08:06 myellen

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)

demonbane avatar Jun 13 '19 21:06 demonbane

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.

myellen avatar Jun 13 '19 23:06 myellen

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 avatar Jun 14 '19 00:06 demonbane

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?

demonbane avatar Jun 14 '19 00:06 demonbane

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"

myellen avatar Jun 14 '19 16:06 myellen

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)

demonbane avatar Jun 14 '19 23:06 demonbane

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 avatar Jun 19 '19 18:06 myellen

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

myellen avatar Jun 19 '19 18:06 myellen

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

myellen avatar Jun 19 '19 19:06 myellen