Jump to content

emby server crashing and restart solution


mbu10

Recommended Posts

mbu10

well just a idea.

My emby stops working every day or so (web interface not working, non responsive) and have to go in and restart it again (which is a pain if i am away from home)

so just written (part of) this 

which checks your web page and says fine if everything good , if not stops all the emby services and restarts them, 

You just need to run as a scheduled job (running every couple of mins) in windows under the user your running emby.

This is beta but should work as it is, will tweak it when i get the actual failure again

just copy and paste  in to a file anythingyou want.PS1

 

 

#Initialising
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
 
 
#Variables to modify
$output = "" #Define output variable
$stringToCheckFor = "The service is unavailable" #String to check for. Note that this will be searched for with wildcards either side
$startTime = get-date
$output = $webClient.DownloadString("http://192.168.2.12:8096")#Modify this url to be the url you want to test
$endTime = get-date
 
#Main workload
#The below checks for the string "The service is unavailable" from your website and if found forcefully restarts the defined service
if ($output -And $output -notlike "*$stringToCheckFor*") {
    "Site Up`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds"
} else {
Stop-Process -Name "EmbyServer" -Force
Stop-Process -Name "Embytray" -Force
Stop-Process -Name "ffmpeg" -Force
    "Stop Service Command Sent"
    "C:\Users\Administrator\AppData\Roaming\Emby-Server\system\EmbyServer.exe"
"Start EmbyServer.exe Sent"
}

 

  • Like 1
Link to comment
Share on other sites

Sammy
#Initialising
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
 
 
#Variables to modify
$output = "" #Define output variable
$stringToCheckFor = "The service is unavailable" #String to check for. Note that this will be searched for with wildcards either side
$startTime = get-date
$output = $webClient.DownloadString("http://localhost:8096")#Modify this url to be the url you want to test
$endTime = get-date
 
#Main workload
#The below checks for the string "The service is unavailable" from your website and if found forcefully restarts the defined service
if ($output -And $output -notlike "*$stringToCheckFor*") {
    "Site Up`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds"
} else {
Stop-Process -Name "EmbyServer" -Force
Stop-Process -Name "Embytray" -Force
Stop-Process -Name "ffmpeg" -Force
    "Stop Service Command Sent"
    "C:\Users\User Name\AppData\Roaming\Emby-Server\system\EmbyServer.exe" #User Name is the user name of the user running the Emby Server
"Start EmbyServer.exe Sent"
}

Should this be put in a *.bat file?

 

Is stopping ffmpeg necessary? Other things on my HTPC use it and it may cause bad results if I stop the process.

 

@@Luke can this code be put into Emby natively?

Link to comment
Share on other sites

mbu10

well all it is doing is checking the web site and makes sure it gets a response 

then if it does not

it stops the following processes

Stop-Process -Name "EmbyServer" -Force
Stop-Process -Name "Embytray" -Force
Stop-Process -Name "ffmpeg" -Force

i did this as when i stopped emby by it self sometimes it looked like it did not come up cleanly

 

this is a powershell script , put it in a .PS1 file(text file with the extenstion renamed to anythinyouwant.PS1"

you can run directly by running in powershell, it should return (web service up the date and time and response time

if this does not respond  it should the quit the 3 apps running and restarts emby

 

this might need some adjustment  or tweaks , and when mine crashes again will do it 

thanks

martin

Link to comment
Share on other sites

#Initialising
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
 
 
#Variables to modify
$output = "" #Define output variable
$stringToCheckFor = "The service is unavailable" #String to check for. Note that this will be searched for with wildcards either side
$startTime = get-date
$output = $webClient.DownloadString("http://localhost:8096")#Modify this url to be the url you want to test
$endTime = get-date
 
#Main workload
#The below checks for the string "The service is unavailable" from your website and if found forcefully restarts the defined service
if ($output -And $output -notlike "*$stringToCheckFor*") {
    "Site Up`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds"
} else {
Stop-Process -Name "EmbyServer" -Force
Stop-Process -Name "Embytray" -Force
Stop-Process -Name "ffmpeg" -Force
    "Stop Service Command Sent"
    "C:\Users\User Name\AppData\Roaming\Emby-Server\system\EmbyServer.exe" #User Name is the user name of the user running the Emby Server
"Start EmbyServer.exe Sent"
}

Should this be put in a *.bat file?

 

Is stopping ffmpeg necessary? Other things on my HTPC use it and it may cause bad results if I stop the process.

 

@@Luke can this code be put into Emby natively?

 

 

No, because we want to look at the root problem, not work around it.

  • Like 2
Link to comment
Share on other sites

mbu10

well when i am away from the house and may not have remote access (i generally do ) but want it to run smoothly and not just go off with no warning at all , but will get the logs for this morning to see if you can see what is causing the problem

but you will ask me to uninstall all my extensions / plugins etc 

but if it crashes only once a day if i keep my extensions, which i want to use and then use the script so it keeps running ..

instead of losing the plugin and it not crashing ?

but i do not get the functionality i need or want?

But will get the logs for this morning for you

martin

  • Like 1
Link to comment
Share on other sites

Sammy

No, because we want to look at the root problem, not work around it.

 

Fair enough! TY

 

Hopefully the current Beta will become the Stable Release as I don't have (m)any crashes using it. It seems that this started on the Stable Branch with the most current release or possibly the security Hot Fix that rolled out a few months ago but I've only been experiencing the issue since about 4.1.0 I believe. I've posted logs a couple of times so I don't think there's a need for me to do so again but more data points from mbu10 should prove helpful I hope.

Edited by Sammy
Link to comment
Share on other sites

Sammy

well all it is doing is checking the web site and makes sure it gets a response 

then if it does not

it stops the following processes

Stop-Process -Name "EmbyServer" -Force

Stop-Process -Name "Embytray" -Force

Stop-Process -Name "ffmpeg" -Force

i did this as when i stopped emby by it self sometimes it looked like it did not come up cleanly

 

this is a powershell script , put it in a .PS1 file(text file with the extenstion renamed to anythinyouwant.PS1"

you can run directly by running in powershell, it should return (web service up the date and time and response time

if this does not respond  it should the quit the 3 apps running and restarts emby

 

this might need some adjustment  or tweaks , and when mine crashes again will do it 

thanks

martin

 

Ah.. Okay. I'll give it a whirl and report back.

Link to comment
Share on other sites

Sammy

well when i am away from the house and may not have remote access (i generally do ) but want it to run smoothly and not just go off with no warning at all , but will get the logs for this morning to see if you can see what is causing the problem

but you will ask me to uninstall all my extensions / plugins etc 

but if it crashes only once a day if i keep my extensions, which i want to use and then use the script so it keeps running ..

instead of losing the plugin and it not crashing ?

but i do not get the functionality i need or want?

But will get the logs for this morning for you

martin

 

I use Jump Desktop App which costs $10 but I grabbed for free one day many years ago when Amazon Appstore used to give away an app a day. I use it all the time. It is pretty good but running a PC on a 5" phone screen or even my 9" tablet screen is really not all that great..

Link to comment
Share on other sites

mbu10

i run a vpn directly into my network , then from there can do what i want.... but restarting a emby box on a small phone not that much fun, also i do not know when it has gone down, if i am away for a couple of weeks , only know when some one emails me to say the house not playing anything...

Link to comment
Share on other sites

  • 2 weeks later...
Sammy

Does Stop-Process work in Windows 7 PS?

 

 

no idea you will have to take the line and try it inside win7

 

 

Has this been tested yet?

Link to comment
Share on other sites

Sammy

No, because we want to look at the root problem, not work around it.

 

Just a comment on this. I have Blue Iris, a security camera software running on my PC. I also have a third party app called Blue Iris Tools that monitors the status of Blue Iris and reloads it if it goes down and does a few other things like overlays on the video. I find that this reloads Blue Iris occasionally and have no problem with that happening. This is why I'm asking if this can be built in to Emby, not as solution necessarily but as a back up / stop gap thing to keep things going if there's an error.

 

Thanks..

Edited by Sammy
Link to comment
Share on other sites

BAlGaInTl

No, because we want to look at the root problem, not work around it.

 

This.

 

An application shouldn't have to keep checking to see if it's still running.

 

This is also why I think it's better to run a dedicated server on a server OS.  I get that not everyone can do that, but it seems the problems become extremely complicated when systems are multi-purposed.  At the very least, it makes sense to contanerize (e.g., Docker) those components.  That's currently what I do.  I did recently move my VPN to a Pi though.  That way, "if" my server has an issue, I can still VPN in to my network to do work.

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
×
×
  • Create New...