Permissions problems caused by upstart script

##My Problem:
Sonarr was giving permission problems when trying to move downloaded shows into the destination folder ("Couldn’t import episode foo: Access to the path “/raid/media/Video/TV Series/bar” is denied.)

##Some background:
I am running sonarr on ubuntu server 12.04.5 LTS
sonarr is started by a standard upstart job (https://github.com/Sonarr/Sonarr/wiki/Autostart-on-Linux)

#Set username for the process. Should probably be what you use for logging in
setuid downloader

env DIR=/opt/NzbDrone
#This is the install directory. If you installed using a deb package or the Son$

setgid allusers
start on runlevel [2345]
stop on runlevel [016]

respawn

exec mono --debug $DIR/NzbDrone.exe

I run sonarr as user downloader - this user corresponds to user ID 1001
I run SABnzbget+, couchpotato, transmission, headphones etc as this user
I have an allusers group which I have added the user downloader to
My destination media folders are all 775, root:allusers
My destination media files are all 664, root:allusers
My destination filesystem is xfs

##Some investigation:
If I stop the service and run sonarr as user downloader interactively everything works fine
On running ps -eo pid,comm,euser,supgrp | grep 1001 I get this if interactive:

22399 mono            1001     debian-transmission downloader allusers

And this if started by upstart:

22823 mono            1001     -

UID and GID are set to downloader:allusers in the upstart script.
I spent a few hours trying to sort this out. I couldn’t get the group ID set corectly by upstart.

##My solution:
I eventually fixed this by changing the upstart script to:

#Set username for the process. Should probably be what you use for logging in
setuid downloader

env DIR=/opt/NzbDrone
#This is the install directory. If you installed using a deb package or the Son$

setgid allusers
start on runlevel [2345]
stop on runlevel [016]

respawn

exec start-stop-daemon --start -c downloader --exec /usr/bin/mono /opt/NzbDrone.exe

Now ps -eo pid,comm,euser,supgrp | grep 1001 shows

24690 mono            1001     debian-transmission downloader allusers

And everything seems to be working the way it should.

But I feel like this is a bit hacky and I wonder if there is a better way to fix it?

No idea, setgid works fine for me.

On a side note, you may want to include uname 002 as well.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.