Jump to content

Emby Service Updater


hatharry
 Share

Recommended Posts

hatharry

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/hatharry/Emby.ServerUpdater/blob/master/EmbyServiceUpdater.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
  • Like 12
Link to comment
Share on other sites

  • 2 weeks later...
denethor

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 :)

Link to comment
Share on other sites

  • 4 weeks later...
jordy

@@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. :)

Link to comment
Share on other sites

mediacowboy

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.

  • Like 1
Link to comment
Share on other sites

jordy

@@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...

Link to comment
Share on other sites

hatharry

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.

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...
FrostByte

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}"

EmbyServerUpdate.zip

Edited by FrostByte
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
hatharry

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

Link to comment
Share on other sites

  • 3 months later...
hansolo77

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!

Link to comment
Share on other sites

Koleckai Silvestri

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.

Link to comment
Share on other sites

hansolo77

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
Link to comment
Share on other sites

hatharry

The exe is fully unattended, the powershell script is not.

 

I'll put the executables on github.

 

The server will only restart when it has an update.

Emby.ServerUpdater.exe -restart -download

will restart server every time and check for update.

 

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?

Link to comment
Share on other sites

  • 5 weeks later...
Doonga

Having some issues with this. I'm using the .exe version. After an update, it leaves Emby in a stopped state. If I restart it manually, I get an Emby log that shows that the update needs to apply, then when I restart the service again, it starts up normally.

 

Should I be running the scheduled task as my Emby user or as SYSTEM?

Edited by Doonga
Link to comment
Share on other sites

Doonga

Closer... Now it restarts and does the update, but then Emby exits again and ends up stopped. So I had to start it again. Seems like it needs 1 more start at the end and we're back in business.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...