Stop NzbDrone from command line via mono

Hi all,

I’ve been searching everywhere and cannot seem to find an answer to the simplest of questions. In the NzbDrone installation guide it notes that you can start the program (debian) with :

mono /opt/NzbDrone/NzbDrone.exe

I cannot seem to find out how to stop the process in a similar manor being very unfamiliar with mono. Can anyone help out?

Thanks.

Just press Ctrl+C to exit.

Or if you’re running it as a service I guess you could do a ps|grep nzbdrone and then kill [process number]?

Thanks for the replies.

What I’m trying to do is find a way to start and stop nzbdrone without using an init.d script as I do not want it to start at boot.

I’m trying to create 2 bash scripts - one that starts it and one that stops it. I just can’t seem to find a way to do this.

I’d like to use these scripts with cron.

How would I run it as a service?

I found one way to do this by just copying the syntax of the ‘autostart in linux’ portion of the installation guide - i.e.

/sbin/start-stop-daemon -q -d /var/lib/nzbdrone -c root:nzb --start --background --make-pidfile --pidfile /var/run/nzbdrone.pid --exec $(which mono) -- /opt/NzbDrone/NzbDrone.exe 

but I have a feeling that there is an easier/better way.

basically I’d like to start nzbdrone and specify the user/group it runs as and make it run in the background… if possible - and of course be able to stop it as well.

I don’t know if it’s nzbdrone or the command above (or the fact that I’m running it on a pi), but it takes about 3 minutes to start up.

There is an extremely simple way… You can simply edit the crontab for the user you wish to have NZBDrone run under, as any commands executed in there will be run with that user’s permissions. You probably don’t even need separate bash scripts unless you need some extra functionality. The start command can be something as simple as ‘/path/to/mono /path/to/NzbDrone.exe’ and the stop command can be something as simple as ‘pkill NzbDrone.exe’ You can tweak what user:group it runs using the sudo command. stdout and stderr can be redirected as needed like you would do with any normal cron job.

It sounds like you don’t actually need a service wrapper since you’re not wanting to start it at boot time and the program executable does not really support anything other than execute/terminate. Don’t make things more complicated than they need to be. If the only difference a service wrapper will make is typing ‘/etc/init.d/nzbdrone stop’ versus ‘pkill NzbDrone.exe’, don’t bother with it.

This is how the Synology package does it:

#!/bin/sh

# Package
PACKAGE="nzbdrone"
DNAME="NzbDrone"

# Others
INSTALL_DIR="/usr/local/${PACKAGE}"
NZBDRONE_LOG="${INSTALL_DIR}/var/.config/NzbDrone/logs/nzbdrone.txt"
PATH="${INSTALL_DIR}/bin:${PATH}"
USER="nzbdrone"
PID_FILE="${INSTALL_DIR}/var/.config/${DNAME}/${PACKAGE}.pid"
MONO_PATH="/usr/local/mono/bin"
MONO="${MONO_PATH}/mono"
NZBDRONE="${INSTALL_DIR}/share/NzbDrone/NzbDrone.exe"
COMMAND="env PATH=${MONO_PATH}:${PATH} LD_LIBRARY_PATH=${INSTALL_DIR}/lib ${MONO}"

start_daemon ()
{
    start-stop-daemon -S -q -b -N 10 -x ${COMMAND} -c ${USER} -- --debug ${NZBDRONE} > /dev/null
    sleep 2
}

stop_daemon ()
{
    start-stop-daemon -K -q -u ${USER} -p ${PID_FILE}
    wait_for_status 1 20 || start-stop-daemon -K -s 9 -q -p ${PID_FILE}
}

daemon_status ()
{
    start-stop-daemon -K -q -t -u ${USER} -p ${PID_FILE}
}

wait_for_status ()
{
    counter=$2
    while [ ${counter} -gt 0 ]; do
        daemon_status
        [ $? -eq $1 ] && return
        let counter=counter-1
        sleep 1
    done
    return 1
}

case $1 in
    start)
        if daemon_status; then
            echo ${DNAME} is already running
        else
            echo Starting ${DNAME} ...
            start_daemon
        fi
        ;;
    stop)
        if daemon_status; then
            echo Stopping ${DNAME} ...
            stop_daemon
        else
            echo ${DNAME} is not running
        fi
        ;;
    status)
        if daemon_status; then
            echo ${DNAME} is running
            exit 0
        else
            echo ${DNAME} is not running
            exit 1
        fi
        ;;
    log)
        echo "${NZBDRONE_LOG}"
        exit 0
        ;;
    *)
        exit 1
        ;;
esac

Should be easy enough to adjust to your needs I guess?