PlexServerAutoUpdater
PlexServerAutoUpdater copied to clipboard
SilentUpdate Only Checks Once
When using the -silent option, silentUpdate.Run() gets called and only calls CheckIfCanUpdate() once. If playCount is greater than 0, CheckIfCanUpdate() merely logs this and exits with success. There is a timer set (_timer), but it isn't allowed to run as the application exits. There is no loop to recheck playCount. _timer appears to be referenced in MainForm.cs, but is not used in SilentUpdate.cs.
https://github.com/TechieGuy12/PlexServerAutoUpdater/blob/651d6a431c20634decb3130471b1b631e232dd4d/MainForm.cs#L93
In windowed mode, you're running _timer which then calls OnTimedEvent which calls CheckIfCanUpdate(). This establishes the loop on WaitTime because CheckIfCanUpdate() will restart the timer if playCount is greater than 0.
In console mode, you have to keep the main thread busy doing something or the process will exit and all Timers will stop running.
My suggestion:
- Add a private boolean variable to MediaServer named
_updateCompleteand set to false - Add an
IsUpdateComplete()function to MediaServer to return_updateComplete - Set _updateComplete in the
finallyblock inMediaServer.Update()at the very end. - Add a do-while loop inside the
if (_server.IsUpdateAvailable())block ofSilentUpdate.Run()that checks!MediaServer.IsUpdateComplete()and sleepsWaitTimeas anelsetoif (CheckIfCanUpdate())
Log file:
2019-05-30 20:32:16 Getting windows user.
2019-05-30 20:32:17 Checking if user is an administrator.
2019-05-30 20:32:17 Initializing the silent update.
2019-05-30 20:32:20 Getting the service user.
2019-05-30 20:32:20 The Plex service is installed. Let's get the user associated with the service.
2019-05-30 20:32:20 The Plex service user: serviceaccount.
2019-05-30 20:32:20 Get the local data folder for Plex.
2019-05-30 20:32:20 Plex local data folder: C:\Users\serviceaccount\AppData\Local
2019-05-30 20:32:20 Verify the updates folder is specified.
2019-05-30 20:32:21 Getting ready to download the latest package.
2019-05-30 20:32:21 Checking for the latest version from Plex.
2019-05-30 20:32:21 The update channel is set for Plex Pass.
2019-05-30 20:32:22 Parsing the information from Plex.
2019-05-30 20:32:23 Creating folder: C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates\1.15.8.1163-005053bb5\packages.
2019-05-30 20:32:23 Downloading the latest installation package from Plex.
2019-05-30 20:32:28 Checking if the installation package is valid.
2019-05-30 20:32:28 The package is valid. The checksums match.
2019-05-30 20:32:28 Verify the updates folder, C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates exists.
2019-05-30 20:32:28 Checking to see if updates folder exists.
2019-05-30 20:32:28 Getting the latest update folder.
2019-05-30 20:32:28 Checking for the latest Plex packages folder.
2019-05-30 20:32:28 Get the latest packages file.
2019-05-30 20:32:28 Latest packages file: C:\Users\serviceaccount\AppData\Local\Plex Media Server\Updates\1.15.8.1163-005053bb5\packages\PlexMediaServer-1.15.8.1163-005053bb5-x86.exe
2019-05-30 20:32:29 Checking for server update.
2019-05-30 20:32:29 The server is in use. Waiting for all media to be stopped before performing the update.
Thanks. I will look at this soon and make the necessary changes.
Just wondering if you've had a chance to look at this
I have not yet looked at it as life got a little busy. I am hoping to look at it this weekend.
Just checking back in on this. :-) I really appreciate you writing this tool. It's been a life saver for my system!
Seeing same FYI :)