Autostart on Linux

Daniel Martínez edited this page Mar 16, 2018 · 37 revisions

Method 1: Upstart (Ubuntu based distros prior to 16.04)

Using Upstart allows for more advanced features, such as start/stop and automatic restart if it crashes.

Create the NzbDrone Upstart config file

sudo edit /etc/init/nzbdrone.conf

Paste in the following code, changing the username (right click if using terminal)

author "Simon Tallmyr - Nosscire"
description "Upstart Script to run Sonarr as a service on Ubuntu/Debian based systems, as well as others"

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

env DIR=/opt/NzbDrone
#This is the install directory. If you installed using a deb package or the Sonarr Repository you do not need to change this

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


exec mono --debug $DIR/NzbDrone.exe

Press Ctrl+X then y to save (assuming you're using nano).

Start Sonarr

sudo start nzbdrone

Method 2: LSB style init-script (Debian/Ubuntu)

  1. sudo edit /etc/init.d/nzbdrone

  2. Paste the following: (change the user/group to not be root. See the security note in the next section.)

    # Provides:          nzbdrone
    # Required-Start:    $local_fs $network $remote_fs
    # Required-Stop:     $local_fs $network $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: nzbdrone
    # Description:       Sonarr
    . /lib/lsb/init-functions
    #set -e
    MONO=$(which mono)

    if ! [ -r ${DAEMON} ]; then echo "Can't read: ${DAEMON}" 2>&1; exit 1; fi
    if ! [ -x ${MONO} ]; then echo "Not executable: ${MONO}" 2>&1; exit 1; fi
    if ! [ -d ${DATADIR} ]; then echo "No such directory: ${DATADIR}" 2>&1; exit 1; fi
    if [ ! -d ${PIDDIR} ]; then
            mkdir -p ${PIDDIR}; chown ${RUNASUSER}:root ${PIDDIR}; chmod 0750 ${PIDDIR};
    do_start() {
            if [ -e ${PIDFILE} ]; then
                    if ! kill -0 $(cat ${PIDFILE}) &> /dev/null; then
                            rm -f $PIDFILE
            log_daemon_msg "Starting ${DESC}" "${NAME}"
            if pgrep -f "^${MONO} ${DAEMON}" > /dev/null 2>&1; then
                    log_progress_msg "(already running?)"
                    start-stop-daemon -q -d ${DATADIR} -c $RUNAS --start --background --make-pidfile --pidfile $PIDFILE --exec $MONO -- $DAEMON $DAEMON_OPTS
            log_end_msg $RETVAL
    do_stop() {
            log_daemon_msg "Stopping ${DESC}" "${NAME}"
            if ! pgrep -f "^${MONO} ${DAEMON}" > /dev/null 2>&1; then
                    log_progress_msg "(not running?)"
                    start-stop-daemon -q --stop --pidfile $PIDFILE --retry 15
            log_end_msg $RETVAL
    case "$1" in
            status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
            echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
            exit 1
    exit 0
  1. Press Ctrl+X then y to save.

  2. sudo insserv -v nzbdrone

Note: May need to run sudo ln -s /usr/lib/insserv/insserv /sbin/insserv first if insserv is not found.

  1. sudo /etc/init.d/nzbdrone start

Note: The script by default runs as root. I suggest adding an nzbdrone user (useradd -m -d /var/lib/nzbdrone --gid nogroup nzbdrone) and adjusting the script so that RUNASUSER=nzbdrone & RUNASGROUP=nogroup.

Please see here for a security note.

Method 3: init.d script (Debian)###

Please see here.

Method 4: RC.Local

Please Note: This is not the most elegant solution but it works

This Method Provided by: protocol77

This Guide is to help those who would like to use linux to run Sonarr at time of writing this there is not "Install As Service" option like with the Windows Build so this needs to be done until a better alternative is found i have personally tested it so you should have no issues if you do please post in the Sonarr Forums ( and someone will try and help you.

**First ** make sure Sonarr is installed you can go here to find out how to do that

Next I created a .sh or batch file to automate the process of type "sudo mono /opt/NzbDrone/NzbDrone.exe" Here is a link to the batch file so it saves you all from having to do this even though it was easy if you open in a text editor you will see

Batch File: (Just Hit Download to grab it)

Next there are two ways of doing this

Method One:

is using rc.local you do this by opening a terminal windows and typing (without quotes) "sudo nano /etc/rc.local" (or if easier you can use a text editor like gedit, pluma, leafpad whatever you have just replace the nano part with what you want

Once this is open go to the bottom and just above where it says "exit 0" type the following for eg.

/bin/sh /home/server/Desktop/

mine was saved to my desktop on my linux machine you will need to edit this to wherever you put the file you downloaded above but remember to keep the /bin/sh first then a space then the rest

Method Two: (With Screenshots)

Go to your menu and find the application to set startup items this may be called many things mine was called Session And Startup

Once this is open i went to Application AutoStart there i clicked on the add button

Next i added the following which you will notice is the same as the one in Method One "/bin/sh /home/server/Desktop/"

after that i gave it a name and then pressed "Ok" and then "Close" i then did a reboot of the system

on reboot i did notice it took a couple more seconds to login this is because this is setting that command to run at login but once logged in i opened my browser and went to http://localhost:8989 and voila it started

I cannot guarantee this will work but it seems to be working for me i am Linux newbie and this took me a while to figure out so hopefully by posting here it will help someone else avoid the trouble i went through


Modern Linux systems have been updated to use the new systemd standard. The method is very simple and involves creating a service file then enabling it.

Create the service file

Be sure to modify the user, group, mono path and install directory.

Create the file sonarr.service with the content:

Description=Sonarr Daemon


ExecStart=/usr/bin/mono /opt/NzbDrone/NzbDrone.exe -nobrowser


Move the file to your system directory

Typically located in /etc/systemd/system/, verify before proceeding. Will differ based on distribution.

mv sonarr.service /etc/systemd/system/

Add Sonarr to startup

systemctl enable sonarr.service

Start Sonarr service

Start sonarr via systemd and verify status.

systemctl start sonarr.service
systemctl status sonarr.service


Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.