Jump to content

Emby no longer respecting defined user


Jorpd
Go to solution Solved by dcrdev,

Recommended Posts

Hi,

 

Since moving away from the installing/updating via repository, I installed the newer version of emby using dpkg -i emby-server-deb_3.2.70.0_amd64.deb

 

I've found that since then, emby can't access my media folders as it's not respecting the EMBY_USER=$user line in /etc/emby-server.conf 

 

I found there's also /etc/emby-server.conf.dpkg-dist which I've added EMBY_USER=$user to, but this hasn't resolved the issue.

 

Just to clarify, ps aux | grep emby-server shows that it's running as emby, which confirmed my suspicions when the library scan came back empty.

 

Can anybody point me towards the correct config file?

Link to comment
Share on other sites

dcrdev


systemctl disable emby-server --now
chown -R <user>:<user> /path/to/emby/data/folder #probably /var/lib/emby or /var/lib/emby-server
systemctl enable emby-server@<user> --now

 

Edited by dcrdev
Link to comment
Share on other sites

Or

sudo systemctl stop emby-server
sudo nano /usr/lib/systemd/system/emby-server.service

And change the line

user=emby

 to

user=YOURUSER
CTRL+X,Y
sudo systemctl daemon-reload
sudo systemctl start emby-server
Edited by Delphi
Link to comment
Share on other sites

I start the service using service emby-server start, so I believe the systemctl instructions don't apply here.

 

I've found/modified the emby-server.service file, but there may be another step I need to do as it's not running as that user still.

 

I probably need the equivalent command of systemctl daemon-reload

Link to comment
Share on other sites

dcrdev

I start the service using service emby-server start, so I believe the systemctl instructions don't apply here.

 

I've found/modified the emby-server.service file, but there may be another step I need to do as it's not running as that user still.

 

I probably need the equivalent command of systemctl daemon-reload

 

Firstly I don't get @@Delphi 's suggestion of modifying the service unit, when enabling the service template i.e. emby-server@<user> does exactly the same thing; the service template defines user= as '%i' where '%i' is the argument passed after '@'. Why go to the trouble of having to deal with potential merge conflicts in future, when the change is entirely unnecessary?

 

Irrespective of the above - modifying emby-server.service isn't going to do anything for you, since Ubuntu 14.04 uses upstart and not systemd, modifying the systemd service unit is pointless.

 

I never used upstart, I used sysvinit before systemd came along - but what you probably want to do is look under /etc/init/ and /etc/init.d for emby-server* and see if there are any provisions for switching user. Upstart doesn't naively allow running jobs as different users, as systemd does - it requires the script to directly set setuid/setgid.

 

Should you get this working, bare in mind that you need to do this:

chown -R <user>:<user> /path/to/emby/data/folder #probably /var/lib/emby or /var/lib/emby-server
Link to comment
Share on other sites

No luck so far.

 

root@[mybox]:~# ps aux | grep emby-server
emby      7810  164  0.6 2625832 111460 ?      RLsl 21:06   0:01 /opt/emby-server/system/EmbyServer -programdata /var/lib/emby -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
$useridefinedinlocationsdiscussed   c   7820  0.0  0.0  10484  2220 pts/1    S+   21:06   0:00 grep --color=auto emby-server
 
Chowning /var/lib/emby as $useridefinedinlocationsdiscussed makes emby not run at all, so that confirms that first line of the ps aux output that it's still running as emby.
 
It's surprising that this is so more tricky than specifying the user as before in /etc/emby-server.conf 
Link to comment
Share on other sites

dcrdev

 

No luck so far.

 

root@[mybox]:~# ps aux | grep emby-server
emby      7810  164  0.6 2625832 111460 ?      RLsl 21:06   0:01 /opt/emby-server/system/EmbyServer -programdata /var/lib/emby -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
$useridefinedinlocationsdiscussed   c   7820  0.0  0.0  10484  2220 pts/1    S+   21:06   0:00 grep --color=auto emby-server
 
Chowning /var/lib/emby as $useridefinedinlocationsdiscussed makes emby not run at all, so that confirms that first line of the ps aux output that it's still running as emby.
 
It's surprising that this is so more tricky than specifying the user as before in /etc/emby-server.conf 

 

 

I had a look at the deb package... I wrote a script to do this for you, run it with the following command:

curl -s https://gist.githubusercontent.com/dcrdev/8fbc9280045dad89b333d74a307fb131/raw/c6167be7192f6a39063011f62c05be1583c4e656/change_emby_user.sh | bash

It will prompt you for the user you want to run emby as going forward.

 

Here is the contents of that script:

#!/bin/bash
initScriptLocation="/etc/init/emby-server.conf"

function main() {
	
	service emby-server stop

	read -p 'Username: ' euser
	
	if [ -d "/var/lib/emby" ]; then
		chown -R  "$euser":"$euser" "/var/lib/emby";
	else
		chown -R  "$euser":"$euser" "/var/lib/emby-server";
	fi

	sed -i "s/setuid emby/setuid $euser/g" "$initScriptLocation"

        initctl reload-configuration
	
	service emby-server start

}

function elevate {

    echo "Attempting to Elevate..." 1>&2
    sudo "$0" "$@"
    exit $?

}

# Test for root.
if [ "$(id -u)" != "0" ]; then
	echo "This script must be run as root!"
	elevate
fi

main

Edited by dcrdev
Link to comment
Share on other sites

It stopped emby-server cleanly but then I got:

start: Unknown job: emby-server

 

service --status-all shows:
[ - ]  emby-server
 
So I've really broken it now after playing with the permissions. Weird one because I chowned it back to how I found it before.

 

 

Thanks for your efforts!

Link to comment
Share on other sites

cat /etc/init/emby-server.conf

description "Emby Server is a personal media server with apps on just about every device."

author "Emby LLC"

 

setuid

exec /opt/emby-server/bin/emby-server

 

start on started networking

stop on stopped networking

 

respawn

respawn limit 5 60
Link to comment
Share on other sites

  • Solution
dcrdev

cat /etc/init/emby-server.conf

description "Emby Server is a personal media server with apps on just about every device."

author "Emby LLC"

 

setuid

exec /opt/emby-server/bin/emby-server

 

start on started networking

stop on stopped networking

 

respawn

respawn limit 5 60

 

Hmm did you not type your username when prompted by the above script?

 

Do:

service emby-server stop
Edit the file (/etc/init/emby-server.conf):

 

Change:

setuid
To:

setuid <usernameGoesHere>
Then do:

chown -R <usernameGoesHere>:<usernameGoesHere> /var/lib/emby
initctl reload-configuration	
service emby-server start
Edited by dcrdev
  • Like 1
Link to comment
Share on other sites

Unfortunately the script didn't prompt, only shut emby down and failed to bring it back.

I'll get on the above when back at my machine tomorrow. Thanks again

Link to comment
Share on other sites

dcrdev

Weird - I tested it on my machine, albeit with dummy files.

 

I guess Ubuntu 14.04 maybe has an older version of bash or something.

 

Anyway keep us posted with the manual instructions!

Link to comment
Share on other sites

I've good and bad news. The manually instructions worked, emby is running as myuser as shown below:

~# ps aux | grep emby-server
myuser     10793  7.7  2.2 6861416 364020 ?      SLsl 13:36  18:46 /opt/emby-server/system/EmbyServer -programdata /var/lib/emby -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
myuser     22873  0.0  0.0  10484  2296 pts/6    S+   17:39   0:00 grep --color=auto emby-server

However, the reason I noticed this had happened in the first place is that emby rescanned my library after reinstallation and lost all of my media. I noticed that it obviously didn't have access as here's a look at the folder permissions:

drwxrwxrwx 21 myuser  myuser  4096 Oct 18 07:47 ./
drwxr-xr-x  4 myuser  myuser  4096 May  6  2017 ../
drwxr-xr-x  1 myuser  myuser     0 Apr  4  2017 .acd-sorted/
drwxrwxrwx  2 myuser  myuser  4096 May  6  2017 .acd-sorted2/
drwxrwxrwx  2 myuser  myuser  4096 May  6  2017 acd-sorted-foldersyncmovies/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-hqmovies/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies0/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies1/
drwxr-xr-x  1 myuser  myuser     0 Jul 12  2017 acd-sorted-movies10/
drwxr-xr-x  1 myuser  myuser     0 Oct 20 13:29 acd-sorted-movies11/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies2/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies3/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies4/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies5/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies6/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies7/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies8/
drwxr-xr-x  1 myuser  myuser     0 Jun  7  2017 acd-sorted-movies9/
drwxrwxrwx  7 differentuser differentuser 4096 Jan 28 00:10 embybackup/
drwxrwxrwx  2 differentuser differentuser 4096 May  9  2017 iptv/
drwxrwxrwx  2 differentuser differentuser 4096 May  6  2017 scripts/

Now that emby is shown to be running as the correct account, I can't figure out why library scans are still coming back as empty.

Link to comment
Share on other sites

dcrdev

That's strange...

 

Did you make sure to:

chown -R user:user /var/lib/emby

?

 

Those permission look fine - although could you look at your Emby server log for any access/permission denied errors and post them here?

Link to comment
Share on other sites

I re-installed emby out of frustration and thanks to your help it's running as the correct user and has my library back. Many thanks

Link to comment
Share on other sites

That's strange...

 

Did you make sure to:

chown -R user:user /var/lib/emby

?

 

Those permission look fine - although could you look at your Emby server log for any access/permission denied errors and post them here?

 

Yeah it had been chowned correctly. I wish I knew what went on here, but your help with running as the correct user was the bulk of it I'm sure.

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