Is NzbDrone running under the root account or the nzbdrone user defined in the init.d script?

Sonarr Version2.0.0.4389
Mono Version4.6.2 (Stable 4.6.2.7/08fd525 Mon Nov 14 12:31:30 UTC 2016)
Debian Jessie

root 759 0.4 3.8 179980 119360 ? Sl 17:05 0:18 /usr/bin/mono /opt/NzbDrone/NzbDrone.exe

Hey Team,

I’ve recently setup Sonarr and I’m wanting to verify that it is running under another user and not root, as implied from the ps aux output. I did follow the instructions for creating another user and defining that account in the /etc/init.d/nzbdrone script.

Is what I’m seeing in ps aux as it should be? Is mono spinning up as root and then it is calling the NzbDrone.exe as the specified user?

I’m just wanting to understand how that works and if I’ve done it properly.

Thanks!!

mono will show as running under the user it was started as, looks like either the init script isn’t starting Sonarr or isn’t setting the user correctly.

Hey Markus,

Here is what I’ve got. The script appears to be working as I can use service commands to stop, start and restart nzbdrone and it does appear to be working upon system bootup.

Valid user:
nzbdrone:x:1001:1001:NzbDrone Sonarr Media:/opt/NzbDrone:/usr/sbin/nologin

init.d script copies from the github:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          NzbDrone
# Required-Start:    $local_fs $network $remote_fs
# Required-Stop:     $local_fs $network $remote_fs
# Should-Start:      $NetworkManager
# Should-Stop:       $NetworkManager
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of Sonarr
# Description:       starts instance of Sonarr using start-stop-daemon
### END INIT INFO

############### EDIT ME ##################
# path to app
APP_PATH=/opt/NzbDrone

# user
RUN_AS=nzbdrone

# path to mono bin
DAEMON=/usr/bin/mono

# options for mono
DAEMON_OPTS=""

# Path to store PID file
PID_PATH=/var/run/nzbdrone
############### END EDIT ME ##################
mkdir -p ${PID_PATH}
PID_FILE=${PID_PATH}/nzbdrone.pid
EXENAME=`basename ${APP_PATH}/NzbDrone.exe`
DESC=`basename ${APP_PATH}/NzbDrone.exe .exe`
NZBDRONE_PID=`ps auxf | grep $EXENAME | grep -v grep | awk '{print $2}'`

test -x $DAEMON || { echo "$DAEMON must be executable."; exit 1; }

set -e

echo $NZBDRONE_PID > $PID_FILE

case "$1" in
start)
    if [ -z "${NZBDRONE_PID}" ]; then
        echo "Starting $DESC"
        rm ${PID_FILE} || return 1
        install -d --mode=0755 -o $RUN_AS $PID_PATH || return 1
        start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS $EXENAME
    else
        echo "${DESC} already running."
    fi
    ;;
stop)
    echo "Stopping $DESC"
    echo $NZBDRONE_PID > $PID_FILE
    start-stop-daemon --stop --pidfile $PID_FILE --retry 15
    ;;

restart|force-reload)
    echo "Restarting $DESC"
    start-stop-daemon --stop --pidfile $PID_FILE --retry 15
    start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS $EXENAME
    ;;
*)
     echo "Usage: `basename $0` {start|stop|restart|force-reload}" >&2
     exit 1
    ;;

esac

exit 0

Any thoughts?

Thank you for the help!

It looks right to me, but I’m not familiar with start-stop-daemon.

Looks like -c or --chuid is fine, but they also list --user in the examples here and I’m not entirely sure what it does.

http://man.he.net/man8/start-stop-daemon

Hey Markus,

Alright thanks! This does confirm what I was thinking, that it was running as root and not nzbdrone, so I’ll investigate and see what I can find.

Thanks!

1 Like

Quick update, calling --user on top of -c didn’t make a difference, but thank you for providing that link. It does explain how your script is functioning.

I wonder if other Debian users have run into this if this script’s adoption rate is rather low.

This is a bummer… but I’m determined to figure it out, rather than moving back to SickRage too quickly.

Hey Mark,

Once again, thank you for the guidance. Per the other comments, did I manage to miss the information for how Sonarr would suggest adding this to a debian system’s startup or do we only have the script manufactured by another entity? I’m educating myself on the sysinitv vs systemd changes that happened in Debian 8.

Thanks!

There are lots of ways to do it on all the various OSes that Sonarr can run on so we’ve had users that run Sonarr on those systems provide scripts that they have used to get Sonarr running at startup. With so many different systems it’s impossible for us to give a recommendation on them all or generate our own startup scripts, though incorrect scripts are fixed/removed when possible (usually by other users).

Roger that.

Oddly enough, and contradictory to what I thought I had seen without the init.d script installed, NzbDrone.exe is autostarting, but I have confirmed removal of the init.d script. This leads me to believe something else is autostarting nzbdrone before the script ever started, which could be why I’m seeing it started as root rather than the user defined in the init.d script from the wiki.

Hmmm… nzbdrone doesn’t autostart just from installing it, correct? I had believed this to be the case.

No it doesn’t.

Yeah, sounds like something else is starting it, not sure how you could find out where that is coming from though.

Markus!

I’m owning up to my ignorance here.

The only other spot that could be lauching it would be /etc/rc.local and sure enough when I recalled this bit of information, I realized that I had used this for testing at some point and completely forgot about it like the Debian noob that I am.

Once I removed this, I used the script from the wiki and voila, we see the following.

ps aux | grep nzbdrone
nzbdrone 1846 0.2 3.2 160800 101912 ? Sl 17:31 0:04 /usr/bin/mono NzbDrone.exe

Amazing how things work correctly when you set them up correctly. :slight_smile:

This is all part of the learning experience though.

Once again, thank you for taking the time to help out. I’ll be making a donation to your project and I hope your team is able to continue crafting this fine piece of software.

Have a great holiday!

1 Like

Awesome, glad you got to the bottom of it and thanks for letting us know.

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