Jump to content


Photo

Emby Service Updater


  • Please log in to reply
127 replies to this topic

#1 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 27 November 2015 - 08:06 AM

Updates Emby when running as a service.

.\EmbyServiceUpdater.ps1 -ApiKey "YOUR_API_KEY" -ServerUrl "http://YOUR_SERVER_URL:PORT" [-InstallTask] [-UninstallTask] [-UpdateScript]

Github:

https://github.com/h...viceUpdater.ps1

 

Note:

An Emby api key and url is required, The api key can be created using the dashboard advanced menu, security tab.


Edited by hatharry, 29 April 2019 - 08:58 PM.

  • Tonos, TonkaTuff, denethor and 8 others like this

#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 137604 posts
  • Local time: 06:46 AM

Posted 27 November 2015 - 12:06 PM

Great stuff here!



#3 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 07 December 2015 - 09:06 AM

[removed]


Edited by hatharry, 31 July 2018 - 12:55 AM.

  • FrostByte and denethor like this

#4 denethor OFFLINE  

denethor

    Advanced Member

  • Members
  • 338 posts
  • Local time: 01:46 PM
  • LocationIstanbul,TR

Posted 07 December 2015 - 01:30 PM

Wow now I get go back to Dev for "SystemUpdateLevel". It was a pain in the a** since it requires some manual operations while running as a service :)



#5 jordy OFFLINE  

jordy

    Advanced Member

  • Members
  • 1317 posts
  • Local time: 09:16 PM
  • LocationAdelaide, Australia

Posted 03 January 2016 - 11:50 PM

@hatharry, Now that Luke has moved the install files to Github, could you re-write this to point to the new location for downloads please. Also a version to update Dev branch would be great.

Many Thanks. :)



#6 mediacowboy OFFLINE  

mediacowboy

    Advanced Member

  • Alpha Testers
  • 1825 posts
  • Local time: 05:46 AM
  • LocationTexas, United States

Posted 04 January 2016 - 12:44 AM

I don't use this right now but I had an idea come to me. Why not get this merged into the server. Have the option during install to run a a service. Then any time the server gets notified of a server reboot it run the exercise @hatharry has created.
  • jordy likes this

#7 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 137604 posts
  • Local time: 06:46 AM

Posted 04 January 2016 - 12:56 AM

Why not put it on github? It's nice to see emby-related projects pop up there.



#8 jordy OFFLINE  

jordy

    Advanced Member

  • Members
  • 1317 posts
  • Local time: 09:16 PM
  • LocationAdelaide, Australia

Posted 04 January 2016 - 01:02 AM

@mediacowboy, I thought the same too. I pretty much thought that seeing as Luke liked or was appreciative of it before, he might be inclined to add it to the server anyway. It seems like a relatively simple piece of code to add afterall. But seeing that this was not the case...



#9 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 04 January 2016 - 01:04 AM

Now that it has been running stable for a while now i will add it to github. would be good to see it merged with server.


  • swhitmore and jordy like this

#10 jordy OFFLINE  

jordy

    Advanced Member

  • Members
  • 1317 posts
  • Local time: 09:16 PM
  • LocationAdelaide, Australia

Posted 04 January 2016 - 01:05 AM

Nice :)

Sent from my HUAWEI MT7-L09 using Tapatalk

#11 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 04 January 2016 - 04:21 AM

Git can be found here


  • FrostByte likes this

#12 FrostByte OFFLINE  

FrostByte

    Advanced Member

  • ForumMod
  • 4280 posts
  • Local time: 06:46 AM
  • LocationThe UP

Posted 25 January 2016 - 06:26 PM

Thanks hatharry, didn't realize this was moved.  Makes more sense here though.  Your version probably works much better, but posting updated PowerShell script files from server support forum in case anyone wanted

 

Script updated with new server locations

#Test for admin permissions
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{   
#"No Administrative rights, it will display a popup window asking user for Admin rights"

$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments

break
}

$ServiceDisplayName = 'Media Browser', 'Emby Server'
$ServiceName = 'MediaBrowser', 'Emby'
$ProcessName = 'MediaBrowser.ServerApplication'
# Installer download path
$downloadPath = "$env:USERPROFILE\Downloads"
$InstallFolder = 'MediaBrowser-Server', 'Emby-Server'

#Find install folder
foreach ($string in $InstallFolder)
    { if (Test-Path -Path $env:USERPROFILE\AppData\Roaming\$string ) 
        {$InstallFolder = $string}
    }

# Stop the emby service
"Stopping service"
foreach ($string in $ServiceDisplayName)
{
    Stop-Service -DisplayName $string -ErrorAction SilentlyContinue
}
Stop-Process -Name $ProcessName -ErrorAction SilentlyContinue -Force
Wait-Process -Name $ProcessName -ErrorAction SilentlyContinue

# Download installer
write-host "Downloading installer"
$filename = 'setup.exe'
$SUL = Select-String $env:USERPROFILE\AppData\Roaming\$InstallFolder\config\System.xml -pattern "SystemUpdateLevel"
if ($SUL -match "Release") {$level = "release"}
if ($SUL -match "Beta") {$level = "beta"}
if ($SUL -match "Dev") {$level = "dev"}
$source = "https://github.com/MediaBrowser/Emby.Releases/raw/master/Server/windows/$level/$filename"
$destination = "$downloadPath" + "\" + "$fileName"
Invoke-WebRequest $source -OutFile $destination

# Run installer
write-host "Running installer"
& $destination | Out-Null
"Waiting for emby"
$process = get-Process -Name $ProcessName -ErrorAction SilentlyContinue
while (!$process)
{
    $process = get-Process -Name $ProcessName -ErrorAction SilentlyContinue
}

# Kill the emby app that gets started.
write-host "Finding emby service"
foreach ($string in $ServiceDisplayName)
{
    if (Get-Service -DisplayName $string -ErrorAction SilentlyContinue)
    {
        $emby = Get-Service -DisplayName $string -ErrorAction SilentlyContinue
    }
}
while (!$emby)
{
    # Check the app is running. Wait until it starts
    foreach ($string in $ServiceDisplayName)
    {
        if (Get-Service -DisplayName $string -ErrorAction SilentlyContinue)
        {
            $emby = Get-Service -DisplayName $string -ErrorAction SilentlyContinue
        }
    }
}

#Close emby
write-host "Closing emby"
Stop-Process -Name $ProcessName -ErrorAction SilentlyContinue -Force
Wait-Process -Name $ProcessName -ErrorAction SilentlyContinue

# Delete downloaded installer
write-host "Deleting installer"
Remove-Item $destination

#Restart the emby service
write-host "Setting service to auto startup"
foreach ($string in $ServiceName)
{
    Set-Service -Name $string -StartupType Automatic -ErrorAction SilentlyContinue
}

#Start service
write-host "Starting service"
foreach ($string in $ServiceDisplayName)
{
    Start-Service -DisplayName $string -ErrorAction SilentlyContinue
}

#Complete
write-host "Completed emby update"

Batch file (needs to be named the same as script file to work)

@ECHO OFF
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"

Attached Files


Edited by FrostByte, 26 January 2016 - 09:51 AM.

  • freddyfinn and brandur like this

#13 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 03 February 2016 - 11:33 PM

Updated to download from github



#14 MSattler OFFLINE  

MSattler

    Advanced Member

  • Alpha Testers
  • 1449 posts
  • Local time: 06:46 AM

Posted 04 February 2016 - 12:16 AM

Works pretty sweet!



#15 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 04 February 2016 - 08:46 AM

Fixed Task Creation



#16 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 137604 posts
  • Local time: 06:46 AM

Posted 04 February 2016 - 12:51 PM

Well done :)



#17 hatharry OFFLINE  

hatharry

    Advanced Member

  • Members
  • 120 posts
  • Local time: 11:46 PM

Posted 17 February 2016 - 10:24 PM

Added check to see if emby is closed before continuing. Removed Mediabrowser from service list.

 

If your computer has both mediabrowser and emby service, running "sc delete mediabrowser" will remove the mediabrowser service



#18 hansolo77 OFFLINE  

hansolo77

    Advanced Member

  • Members
  • 225 posts
  • Local time: 06:46 AM
  • LocationColumbus, Ohio

Posted 20 May 2016 - 08:39 AM

I'm not familiar with github...  How do I download and install this?  Is the link in the first post the latest version?  Thanks for the work!



#19 Koleckai Silvestri OFFLINE  

Koleckai Silvestri

    Advanced Member

  • Alpha Testers
  • 3735 posts
  • Local time: 03:46 AM

Posted 20 May 2016 - 12:47 PM

I'm not familiar with github...  How do I download and install this?  Is the link in the first post the latest version?  Thanks for the work!

 

The post from Frostbyte is probably the newest version here. If you download from Github, click on the green "Clone or Download" button. Select Download ZIP. When you unzip it, the script will be on the sub-folder. Double-click it to run. You must have Windows Powershell installed beforehand, though.



#20 hansolo77 OFFLINE  

hansolo77

    Advanced Member

  • Members
  • 225 posts
  • Local time: 06:46 AM
  • LocationColumbus, Ohio

Posted 20 May 2016 - 06:59 PM

Thanks.  I thought FrostByte's was the latest too, but then there were replies after that with further updates.  I just wasn't sure if the link in the first post was the latest then (because it had been updated).  I think obviously the one on Github is going to be the latest anyway, so I'll see if I can figure that out.  Also, I'm pretty sure I have Powershell installed too, comes with Windows Server.  Thanks again!

 

EDIT - Didn't work.. I went with the zip file from the OneDrive instead.  The Github link doesn't provide an exe.  Like it needs compiled or something.  But the zip (also found in the OP) did contain the exe.  It ran fine, scheduled the task, and auto installed the update.

 

Does the scheduled task it creates only restart the server when an update is ready to install, or will it restart every time regardless?  I think "everytime" would require that -restart flag right?


Edited by hansolo77, 20 May 2016 - 07:27 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users