# Need help autostart qBittorrent in FreeNAS jail please



## diedrichg (Jul 7, 2014)

I was successful in portsnap'ing; make install; qbittorrent-nox from freshports to a standard FreeNAS jail.

_(The reason is so that I can host my own private tracker - which qbittorrent supports and transmission does not)_

Anyways, qbittorrent runs great *but only* when I manually run the command 
	
	



```
$ qbittorrent-nox
```
 in the jail shell. I've done some reading and attempted to implement a few autostart batch files from the Internet but I have been unsuccessful as I simply do not have the knowledge to set the code correctly and other commands.

*My steps:*

```
$ nano /etc/rc.d/qbit
```
Paste the script listed here that a FreeNAS user suggested

```
#!/bin/sh
# File name 'qbit'
# Place this file into /etc/rc.d
# Edit /etc/rc.conf to include qbit_enable="YES"
     
. /etc/rc.subr
     
name="qbit"
rcvar=qbit_enable
    
PATH="$PATH:/usr/local/bin"
    
start_cmd="${name}_start"
stop_cmd=":"
     
load_rc_config $name
eval "${rcvar}=\${${rcvar}:-'NO'}"
     
qbit_start()
{
# And start up the service.
     
  service minidlna start
     
done
}
     
run_rc_command "$1"
```
I then set

```
$ chmod 775 /etc/rc.d/qbit

$ nano /etc/rc.conf

qbit_enable="YES"
```
To test I then run

```
$ /etc/rc.d/qbit
```
but it does not work - the software will not autostart after restarting the jail. I can manually run the script but as soon as I close the shell window the service stops.

What do I need to change? What am I missing? I simply don't have the knowledge to make this work, your input would be very much appreciated.


----------



## diedrichg (Jul 7, 2014)

As a second attempt coming from a different angle, here is something else I tried but with the same result - it will not autostart and running the script manually will not keep the service running once the shell window is closed.


```
$ pkg install screen
```


```
nano qbit.sh
```


```
#!/bin/bash
screen -S qbnox -d -m qbittorrent-nox
```


```
$ nano -w /etc/rc.d/rc.local
```


```
#!/bin/sh -e
sh '/path/to/your/script/qbit.sh'

exit 0
```


```
$ chown root /etc/rc.d/rc.local
$ chmod 755 /etc/rc.d/rc.local
$ chmod 755 qbit.sh
```


----------



## SirDice (Jul 7, 2014)

PC-BSD, FreeNAS, NAS4Free, and all other FreeBSD Derivatives


----------



## diedrichg (Jul 7, 2014)

http://forums.freenas.org/index.php?thr ... ost-126952

http://forums.freenas.org/index.php?thr ... ost-127003

edit: sorry - I linked the "quote and reply" link rather than the actual post #. Anybody should be able to read them now.


----------



## diedrichg (Jul 10, 2014)

Just curious if anyone will help me out with this as it's a FreeBSD coding question. Thanks.


----------



## ljboiler (Jul 11, 2014)

Go back and read the "EDIT" note of first reply in the FreeNAS forum, especially what is mentioned about line 23 of the provided script.   Then run `qbittorent-nox --help` (hint:  look for the word "background").   Put the two together and it should do exactly what you want.


----------



## diedrichg (Jul 11, 2014)

Thank you for the --help command! That got me in the right direction, at least now I can run `qbittorrent-nox -d` and be able to close the shell window.

Now I'm stuck at actually getting the right syntax in the script.

Would it be:

```
qbit_start()
{
# And start up the service.
 
  service qbittorrent-nox -d | --daemon start
 
done
}
```
or

```
service qbittorrent-nox -d start
```
or neither? To manually run qbittorrent as daemon I simply run `root@qbittorrent:/ # qbittorrent-nox -d`     Does the script need to have a / or ../ or something else that's missing?


----------



## ljboiler (Jul 12, 2014)

It's the neither choice; this script just needs to do what you type in manually, so drop the "service" at the front and the "start" at the end.  It might be a good idea to give /the/full/path/to/qbittorrent-nox (try `which qbittorrent-nox`) just in case the PATH is not set the same when interactively running as root versus the when the jail runs this script.


----------

