Jump to content

Windows Server Running as Service


Go to solution Solved by carpediem,

Recommended Posts

Posted

I have an issue that when my Win10 machine reboots for a Win10 patch my Emby Server does not restart so I decided to try running it as a service, I disabled the "Run at Startup" option inside of the server settings and got the service to run, but it would not access my NAS folders, using windows Explorer I could access them but not through Emby.  When I just run the server via the program and not by the service it works fine.  
 

Any ideas for either why the service can't access my folders on the NAS or why running the program with the "Run at Startup" does not work?

 

 

Where do I start?

  • Solution
Posted (edited)

Deuce, in order to run Emby as a service you will need to change the account that runs the Emby service to an account that has access to your network shares. If memory serves me well, Emby will work just fine as a service using the default System account if all your media is local. However, if you have network shares, the system account does not have the necessary permissions to access them. Check out this post for more details:

 

https://emby.media/community/index.php?/topic/804-unable-to-access-media-when-running-server-as-a-service/

 

I believe the advantage of running Emby directly vs as a service is that you get get auto-updates. However, I do run mine as a service since that survives reboots etc If there are additional advantages to running it directly, others please chime in.

Edited by carpediem
  • Like 2
Posted

I believe the advantage of running Emby directly vs as a service is that you get get auto-updates.

 

Auto-updates work with service now as well (mostly) if on the beta track.

  • Like 1
Posted

Thank you Carpediem for the response, that was the issue, setup another user account and that fixed the issue.

 

Once again thank you.

  • Like 1
Koleckai Silvestri
Posted

Auto-updates work with service now as well (mostly) if on the beta track.

Works on the Release track as well.

  • Like 1
Posted

Deuce911, glad that worked for you.

 

Koleckai and Moviefan, thanks for the info on running as a service. I'll definitely be checking that out.

Starlionblue
Posted

Auto-updates work with service now as well (mostly) if on the beta track.

 

"Mostly" is correct. I had to turn auto-updates off after the umpteenth time the service didn't restart. Wishlist:

  • Make the server restart more reliable.
  • An option to only restart within a certain time window, e.g. 0200-0400, and not only "when no one is around".
FrostByte
Posted

 

"Mostly" is correct. I had to turn auto-updates off after the umpteenth time the service didn't restart. Wishlist:

  • Make the server restart more reliable.
  • An option to only restart within a certain time window, e.g. 0200-0400, and not only "when no one is around".

 

 

Heh, ya I started a thread in the testing area on this awhile back.  Very unreliable at best in my experience.  I think it has actually gotten worse the last couple of updates.

  • Like 1
Starlionblue
Posted

Quite. It worked pretty well for a bit. Then my kids started hating me again...  :lol:

  • Like 1
Posted

Since i switched to a faster system, this has been working flawlessly for me once again.

 

I really think the issue is just that sometimes the commands are sent, but the service startup fails.

 

I've witnessed this personally on the older, slower system several times when doing a manual restart.  Just seems like it needs time to fully stop and be able to start again.

  • Like 1
Posted

Pushed to the dev branch a fix for the latest update and a timeout between stopping and starting

Posted

Since i switched to a faster system, this has been working flawlessly for me once again.

 

I need to find some slower systems to work with ;)

FrostByte
Posted

I wouldn't say I have a powerhouse system, but that shouldn't really affect starting and stopping a service a whole lot.  I never had any issues with my PS

Posted

I wouldn't say I have a powerhouse system, but that shouldn't really affect starting and stopping a service a whole lot.  I never had any issues with my PS

 

PS has a wait until the process has ended before starting. That's what was missing.

  • Like 1
FrostByte
Posted (edited)

PS has a wait until the process has ended before starting. That's what was missing.

 

Nice, get that thing into beta then :)

 

Edit: I was referring to my PowerShell script though ;)

Edited by FrostByte
Posted (edited)

FrostByte that's interesting y our powershell script never had any issues.

 

Can you post it here?

 

It actually just happened on my brand new system this morning and I was in the services.msc refreshing to watch it.  Emby went into "starting" mode.  Stayed there for a few seconds, and then just died.

 

Hopefully this time wait works, but another thing we might need to do is have the task possibly do a "net start Emby" more than once while checking to see if the service starts properly.  I believe the issue is entirely related to the Emby service failing to start, even though it tried, for one reason or another.

Edited by moviefan
Posted

Hopefully this time wait works, but another thing we might need to do is have the task possibly do a "net start Emby" more than once while checking to see if the service starts properly.  I believe the issue is entirely related to the Emby service failing to start, even though it tried, for one reason or another.

 

The latest version started the service twice but ended up locking files when updating. My testing with Powershell looks more promising than CMD.

  • Like 2
FrostByte
Posted

FrostByte that's interesting y our powershell script never had any issues.

 

 

I'm not a good coder, but here's part of what some of us were using.  The original script we came up was a little more involved because it would stop the service, download and install the appropriate Emby update, and then restart the service.   The code below will just stop the service/process and then start the service again.  It can obviously be cleaned up a lot

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

$ServiceName = 'Emby'
$ProcessName = 'MediaBrowser.ServerApplication'

# Stop the emby service
Write-Host "Stopping Emby"
Stop-Service -Name $ServiceName -ErrorAction SilentlyContinue -Force
Stop-Process -Name $ProcessName -ErrorAction SilentlyContinue -Force
Wait-Process -Name $ProcessName -ErrorAction SilentlyContinue
#Get-Service -Name $ServiceName
#Pause

# Make sure Emby service is set to auto start
#Write-Host "Setting service to auto start"
Set-Service -Name $ServiceName -StartupType Automatic -ErrorAction SilentlyContinue

# Start service
Write-Host "Starting Emby"
Start-Service -Name $ServiceName -ErrorAction SilentlyContinue

# Check Emby status
Get-Service -Name $ServiceName

#Complete
#Pause

I'm hoping harry's update works though because I would really like to make my server headless again, but put a monitor and kb back until this is sorted out.  Just don't want to run dev builds though :)

Posted

I've converted to Powershell, It now restarts the service then waits for the updater to finish then starts the service again. The updater is meant to start the service it's self but most of the comments are about it not starting correctly. so it'll still let the updater start the service but Powershell will start the service again to make sure.

  • Like 1
FrostByte
Posted

Sounds good.  If this works will it be able to do everything automated?  Would like the server if it's not busy then a release would auto update and the service would stop/restart on it's own with no intervention required.  I'm trying to get as close to a headless/dark room setup as possible

Posted

Correct, my main goal is to make everything as automated and headless as possible

  • Like 1
Posted

for now here's the code you can run manually in powershell with admin rights.

& {Restart-Service Emby; Wait-Process Mediabrowser.Updater; Start-Service Emby}
  • Like 2
Posted

I'm not a good coder, but here's part of what some of us were using.  The original script we came up was a little more involved because it would stop the service, download and install the appropriate Emby update, and then restart the service.   The code below will just stop the service/process and then start the service again.  It can obviously be cleaned up a lot

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

$ServiceName = 'Emby'
$ProcessName = 'MediaBrowser.ServerApplication'

# Stop the emby service
Write-Host "Stopping Emby"
Stop-Service -Name $ServiceName -ErrorAction SilentlyContinue -Force
Stop-Process -Name $ProcessName -ErrorAction SilentlyContinue -Force
Wait-Process -Name $ProcessName -ErrorAction SilentlyContinue
#Get-Service -Name $ServiceName
#Pause

# Make sure Emby service is set to auto start
#Write-Host "Setting service to auto start"
Set-Service -Name $ServiceName -StartupType Automatic -ErrorAction SilentlyContinue

# Start service
Write-Host "Starting Emby"
Start-Service -Name $ServiceName -ErrorAction SilentlyContinue

# Check Emby status
Get-Service -Name $ServiceName

#Complete
#Pause

I'm hoping harry's update works though because I would really like to make my server headless again, but put a monitor and kb back until this is sorted out.  Just don't want to run dev builds though :)

 

Doesn't sound like hatharry is using this exact code but I would prefer that it NOT perform the first check for administrator rights.  

 

I run Emby on my new system under a non-admin account to restrict what files it has access to elsewhere.  I've configured the permission on the Emby service so that the user Emby runs underneath has full control.  I think this initial check would fail on my system though.

FrostByte
Posted

 

for now here's the code you can run manually in powershell with admin rights.

& {Restart-Service Emby; Wait-Process Mediabrowser.Updater; Start-Service Emby}

 

Very clean and efficient, thanks hatharry

Posted

It looks like the update capability has been removed in the 3.1.194.  I no longer have the option showing.

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