(Tutorial) JDownloader in a Jail

brumnas

Dabbler
Joined
Oct 4, 2015
Messages
33
If the JDownloader is 'just another win app' for you as it was for me just a few hours ago, you can find this brief intro useful, as I didn't found anything concrete myself.

Good to know
- JD can be downloaded as a pure java.jar package and ran under java command line
- JD can be remotely controlled from MyJDownloader web portal (yes, free sign-in is needed.. similar to PlexTV login..)

Steps:
- register yourself free at https://my.jdownloader.org; the email/pwd will be needed in the java console config later
- create a new jail with a fixed IP to keep it simple
- pkg update, pkg upgrade
- pkg install wget openjdk8
- wget http://installer.jdownloader.org/JDownloader.jar
- java -jar JDownloader.jar -norestart
- execute the last command more times until console asks for MyJDownloader login email/pwd (the one you created at the start)
- sign in at https://my.jdownloader.org and control your NAS JD

I'm still fine-tuning and trying to understand the communication/logging, where/what/how happens, starting the java JD on startup etc. But basically it seems to work ;-).

Hope this helps somebody,
Andrej
 

Macbrody

Cadet
Joined
Jan 29, 2017
Messages
3
Hello,

I followed successfully your tuto, thanks a lot, that helped me to configure jdownloader in a jail.
Very valuable and simple if we use myjdownloader to manage the downloads.

I have 2 questions:
- did you succeed in requesting jdownloader updates + restart with myjdownloader interface ?
- did you know how to create files from jail with read/writes access ? I have to delete files either from myjdownloader or with jail shell.

Best Regards

Macbrody
 

ChriZ

Patron
Joined
Mar 9, 2015
Messages
271
I haven't used jdownoader in many years, but I remember it had its own web interface, without the need to create an account in an online service.
Has this changed? :confused:

P.S.: I was using the Windows version jar package
 

brumnas

Dabbler
Joined
Oct 4, 2015
Messages
33
Hi, to the issues:

1. JDownloader web interface
The remote login "through web" is needed for the backend JDownloader, e.g. when running as a UI-less server task from the .jar file.

2. Updates
I download/setup it once again; it's just 1 jar file with just a few questions to be answered from the CLI.

3. Downloaded files permissions
I ended up using "umask" (which gives new files a bit-mask 777 excluding those bits given by umask). I've put it into the script which starts jdownloader. This script is part of the "service script", which is the newer way of starting tasks automatically at startup under FreeBSD. I couldn't believe somehow that I need all that but no "classical" way worked for me, so I had to look into the docs at FreeBSD and read a few wiki pages.

This step was a bit uglier than I thought: I expected JD to have some config for this but I didn't find it. Then I expected some useful jail setting from FreeNAS for umask and starting tasks, but didn't find these. Then I expected the rc.d way of kicking in my startup script, which didn't work as well. So I ended up reading FreeBSD services and testing if umask will influence JD - which worked :smile:. Now when I re/start my jail, the JD runs and it uses the given umask.

I've created a new jail share (folder under the main movies library, like "_downloaded") and made a hard link pointing from the default JD download dir to that. So the preconfigured link points to the /mnt/XXX share, which writes to the /mnt/pool1/movies/_downloaded folder. Now when I open the main movies folder, the _downloaded pops out as the very first entry and I can move that files instead of copying as they are in the same dataset as the other movies.

Hope this helps,
Andrej
 

Macbrody

Cadet
Joined
Jan 29, 2017
Messages
3
Hi Andrej,

Could you give us some more details about the script you modify for starting JDownloader at jail startup, please ?

Best Regards

MacBrody
 

brumnas

Dabbler
Joined
Oct 4, 2015
Messages
33
I've put a script under the jail's /etc/rc.d -

Code:
#!/bin/sh

. /etc/rc.subr

name="spustit"
start_cmd="${name}_start"
stop_cmd=":"

spustit_start()
{
		umask 000
		/usr/local/bin/java -Djava.awt.headless=true -jar /usr/jdownloader/JDownloader.jar &
}

load_rc_config $name
run_rc_command "$1"



May be you want to use more restrictive umask as this sets 777 onto new files, which is ok on my box.

To understand how the service script architecture changed last years, check these docs:
https://www.freebsd.org/doc/en/articles/rc-scripting/rcng-confdummy.html

Hope this helps,
Andrej
 

Macbrody

Cadet
Joined
Jan 29, 2017
Messages
3
I reply after a long time but thanks a lot it works.

I have now JDownloader running in jail under Freenas, with autorun at Jail startup with total access to the files from my PC.

MacBrody
 
Joined
Dec 15, 2016
Messages
1
Hi Andrej,

thanks for your Tutorial...it works for me. Can you please tell me how can I realize the autostart script. I dont understand your last post..

Regards Chris
 

fkuehne

Cadet
Joined
Jul 30, 2017
Messages
8
Hy, this works fine on FreeBSD v11 for me, thanks.

I did'nt want to run jdownload as root though. Therefore I created a new shell script with this content, to start Jdownloader. (Maybe remove the & at the end)

Code:
#!/bin/sh
/usr/local/bin/java -Djava.awt.headless=true -jar /home/download/JDownloader.jar &


In the rc.d script I changed jdownloader_start() to execute the startscript as unpriviled user

Code:
umask 077
  su - unprivilegedUser -c /path/to/jdownloader-start-script.sh


And I added a _stop() function, for the case that I want to quit it properly

Code:
jdownloader_stop()
{
# I only have java running for jd, so the command kills java. So maybe use the "pidfile=" option if there are mot java instances
  pid=$(pgrep java)
  kill $pid
}
 
Last edited:

Psychoteur

Dabbler
Joined
Mar 19, 2017
Messages
34
Hello,
Did you setup unrar, 7zip or something else to get extract working ?
Jownloader downloads and reconnects to get a new ip but it didn't extract the archives.

And the stop function doesn't work. I've to kill "-15" java to stop jdownloader.
 

fkuehne

Cadet
Joined
Jul 30, 2017
Messages
8
I have 7zip and unrar running, but it didn't work until I installed the compat11x packet. Chose the one corresponding to your FreeNas version, so like 11 for 11 etc... After a restart of jdownloader it worked for me.

I read in the jdownloader forum that they just recently created compatibillity for unrar 5. So it should work with current unrar and with 7zip.

Is pgrep installed ? do you have privileges to run service jdownloader stop if it runs under a diffrent user?


But I have not been able to get PhantomJS running so far. In case anyone managed to do so.
 
Last edited:

Psychoteur

Dabbler
Joined
Mar 19, 2017
Messages
34
so I've setup 7zip and unrar.
Did you put the link inside tools/linux ?
Because now I can see archive setting inside download menu but it is greyed out.
I assume I should have a value at that line:Extraction: Last Working Lib ID
MyJdownloader is not easy to setup. The documentation is for jdownloader and not always sure what to input as value.

I'm reading that at the moment ->
https://board.jdownloader.org/showthread.php?t=57446

Pgrep is installed.

I just need two things: extract and automatic rename for movies :p
 

fkuehne

Cadet
Joined
Jul 30, 2017
Messages
8
If I remember corectly I maybe have disabled and restarted and enabled Archive Extractor.

Unter Extraxtion: Last Working Lib ID stands "FreeBSD-amd64" but I didn't input it.

Did you install the Compat library ? (I just took a look and have the compatx9 compatx10 and compatx11 installed) I think somehow it worked all alone somehow after installing something.

I just took a look and i have installed folowing packages because of the extraction matter
compat9x, compat10x and compat 11x
p7zip, p7zip-codec-rar, unzip, zip
unrar libunrar5 libarchive

some how it works,.. maybe take a look into the log for some error.. this was putting me onto the right path, what to look for..
 

Psychoteur

Dabbler
Joined
Mar 19, 2017
Messages
34
I did install compatx11 and 7zip but it's like jdownloader doesn't try to extract at all.
I've got nothing in logs. It was my starting point.

OK, you need to add compat9x :D It's working !!!

Now, I try to add jdownloader_enable="YES" in /etc/rc.conf to get jdownloader running at startup but it's not working.
 
Last edited:

mikale21

Cadet
Joined
Sep 8, 2017
Messages
1
I've put a script under the jail's /etc/rc.d -

Code:
#!/bin/sh

. /etc/rc.subr

name="spustit"
start_cmd="${name}_start"
stop_cmd=":"

spustit_start()
{
		umask 000
		/usr/local/bin/java -Djava.awt.headless=true -jar /usr/jdownloader/JDownloader.jar &
}

load_rc_config $name
run_rc_command "$1"



May be you want to use more restrictive umask as this sets 777 onto new files, which is ok on my box.

To understand how the service script architecture changed last years, check these docs:
https://www.freebsd.org/doc/en/articles/rc-scripting/rcng-confdummy.html

Hope this helps,
Andrej
Thank you very much for your tutorial. I have successfully installed jDownloader on FreeNas 9.1.The only thing where i need help is the start script and the permissions to the downloaded files. I don´t know how to write, how to name it and where to place the script. Can you help me please.
 
Last edited:

Psychoteur

Dabbler
Joined
Mar 19, 2017
Messages
34
Code:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures}

#!/bin/sh

# PROVIDE: jdownloader


. /etc/rc.subr


name="jdownloader"

rcvar="jdownloader_enable"


load_rc_config $name

: ${jdownloader_enable="NO"}

: ${jdownloader_msg:="JDownloader isn't started"}

: ${jdownloader_path="/usr/jdownloader/JDownloader.jar"}


pidfile=/usr/jdownloader/JDownloader.pid


start_cmd="${name}_start"

stop_cmd="${name}_stop"

status_cmd="${name}_status"


jdownloader_start()

{

		umask 000

		/usr/local/bin/java -Djava.awt.headless=true -jar $jdownloader_path

}


jdownloader_stop()

{

# I only have java running for jd, so the command kills java. So maybe use the "pidfile=" option if there are mot java instances

  pid=$(pgrep java)

  kill $pid

}


run_rc_command "$1"
/CODE]

That's my init script at the moment, the functions start and stop are working, I would like to have "status".

I'm missing something. I've read the documentation but I'm looking for a working sample. 
At the moment I'm reading how transmission and sickrage init scripts are written. 
I thought it was the role of rcvar to pass the argument to start the script when the jail starts. 

There is another problem when you update jdownloader via mydownloader, jdownloader doesn't restart.

As for the permissions, just do "chmod 666 jdownloader"
 

pseiko000

Cadet
Joined
Jan 22, 2018
Messages
3
First of all, thank you very much to the threadstarter for the short but directly instructions. I've made my on suggestions and want to add some extra notes for the "others", who had also some startup problems with the guide.

Second, i use the atm last stable FreeNAS build: FreeNAS-11.1-U1.iso (01/23/2018)

And third...if you see some strange smilies, which don't make any sense, the they are "translated" from this FreeNAS forum editor ;-)
Let's start

I'll copy the first and first script post (i hope you forgive me :) ) to add my special notes:
Steps:
- register yourself free at https://my.jdownloader.org; the email/pwd will be needed in the java console config later (1st)
- create a new jail with a fixed IP to keep it simple (2nd)
- pkg update, pkg upgrade (3rd a + b)
- pkg install wget openjdk8 (4th a)
- pkg install compat9x-amd64 (not from starting post) (4th b)
- wget http://installer.jdownloader.org/JDownloader.jar (5th)
- java -jar JDownloader.jar -norestart (6th)
- execute the last command more times until console asks for MyJDownloader login email/pwd (the one you created at the start) (7th)
- sign in at https://my.jdownloader.org and control your NAS JD (8th)

### 1st ###
Register yourself
I think it's that easy so i don't have to add something. Just one thing: use a mailadress you have permanently access to.

### 2nd ###
Create a new jail
Well, this wasn't that easy i thought, because i had a lot of to read to understand what a jail (german: Gefängnis) is. For short: a jail is something like a micro virtual machine (you don't need to download something, all you need comes with free nas by itself). Click "jail/add jail", name it and click on OK. FreeNAS will download some stuff and configure by it's own. You have the possibility to switch to the advanced mode. A jail has it own ip address, like a virtual machine. You will need it to connect with windows explorer or putty/ssh. The ip address is chosen by your default ip pool. If your network ip starts with 192.168.x.x, then the ip address will be 192.168.x.1 (for the second jail, if you want some, the ip will be 192.168.x.2 and so on). If you only want one jail, don't start to waste time with the jail template, click on advanced mode and set the ipv4 address (nothing else!!!) to that ip address you want to use. If you like to add 10 or even more jails, then you should set up your own (!) default template for jails by clicking on "jails/add jails template", type in your network configuration you like to use, save and THEN click on add jails. And yes, it's hardly recommened to use a fixed ip address until you have no or less knowledge about dns.

You should'nt mount the jail in the system harddisk where FreeNAS runs. It's even better to run a jail on a not-system-harddisk to guarantee, that the one and only FreeNAS runs on that harddisk. If you plan to take a big fat ssd for FreeNAS, don't be stupid and take the a 512gb ssd, a 32gb is more than enough! Each additional software you want to install, which don't comes with FreeNAS, you should only install in a jail, or vm!

I digress....

### 3rd a) ###
pkg update, pkg upgrade
This you already do IN THE JAIL!!! So now we have to know, how we can connect to the jail-machine. The imo easiest way is, to open up the console on your NAS (copy paste does'nt work until you're connected with something like putty > if you don't know what putty is, don't waste time to search in google, and if you know what it is, then use it with ssh > you have to modify the startup conf, so that sshd automatically start)

service sshd restart
to start it once

vi /etc/rc.conf
to modify the FreeBSD (jail is linux os > freebsd) startup script
if vim is available, use vim instead of vi

sshd_enable="NO"
change this to "YES", save and quit :)wq! + hit enter) to save the config

passwd
to set your root account a wise chosen password BUT not to complex, you will thank me later ;-)
It is hardly recommened to use another user for JDownloader which can also have root-rights but should not be root as itself, just for security reason. If you paranoid, you can also type in very hard an complex passwords and take care of all your permissions, but for noobs, skip this part even you don't know what you do.

restart your jail with the buttons on the buttom in your freenas jail configuration window

After reboot, you can use putty to connect to your jail.

### 3rd b) ###
Ok, you are root and you have your console from jail in front of you.
pkg update
Let it run through, if you have a weak broadband connection, let it be, it will finish in a few minutes.

pkg upgrade
Let it run through, if you have a weak performance, let it be, it will finish in a few minutes.[/code]

### 4th a) ###
pkg install wget openjdk8

Just type this command in, hit enter and let it be, it will finish in a few minutes. Just remember, if there comes a new jdk version, this command could vary e.g.

pkg install wget openjdk8a or pkg install wget openjdk8.1 or pkg install wget openjdk9 and so on.
If you get a promt with [y/N], always hit "y" and enter. This will install java in your jail in the given version.

### 4th b) ### (not from starting post)
cd /usr/ports/misc/compat9x/ && make install clean
pkg install compat9x-amd64


https://forums.freenas.org/index.php?threads/tutorial-jdownloader-in-a-jail.48374/#post-402618
https://forums.freenas.org/index.php?threads/tutorial-jdownloader-in-a-jail.48374/#post-402982

Thanks to fkuehne and Psychoteur because they answered the "why the f*ck won't JDownloader extract anything". While in the JDownloader FAQ you will find something like

For Linux, you jave to install “unrar-nonfree“.
The correct path to enter then is “/usr/bin/unrar“

it's much easier. Just write down both commands. I did this AFTER i installed JDownloader, and had to restart it, but if you install compat9x before the installation, i don't have to restart anything. One thing could happen: JDownloader is installed, you are already logged in and enable the archive extractor right now (after installation it is disabled), then it could be, you have to enable the archive extractor, restart JDownloader and only then, the archive extractor will work. Bug? Feature? Whatever...

### 5th ###
wget http://installer.jdownloader.org/JDownloader.jar

This will download (not install!) JDownloader in the given version (always the last version which is available on jdownloader.org)

### 6th ###
java -jar JDownloader.jar -norestart

This will install JDownloader. If you want to modify the installation path, normally it's the home directory of your logged on user. At this point i should say, if you have no no no linux knowledge and only want to run JDownloader on FreeNAS, then take a book and read it. If you have no knowledge about linux and want to understand how it works, take a linux beginner guide, read it, use it and if you are a pro, i don't to have to say anything.

### 7th ###
execute the last command more times until console asks for MyJDownloader login email/pwd (the one you created at the start)

No, you don't have to. Take a cup of coffee, do some work...do anything but wait about two three five ten minutes (depending how fast your NAS hardware is). I have a Samsung SSD 850 Pro 128GB built in, so i only wait about 2 minutes. After that, i hit the command again, and tadaaaa, you will be asked for your my.downloader.org credentials.
Type in your mailaddress, hit enter, type in your password you set with that my-jdownloader-account and hit enter.

Notice: You don't see the password you type in so type it slowly but correct.

### 8th ###
sign in at https://my.jdownloader.org and control your NAS JD

Yes, you do. But configuration isn't finished yet. This was the big first part of JDownloader installation. But if you want to close jdownloader (with the webui) or reboot your jail, jdownloader WILL NOT automatically start after reboot. So you have two options. Start it manually or make a startup script, so that jdownloader will start automatically when you restart your jail. Trust me, you would like it.

################################################################

Note: The original script from "brumnas" is a bit outdated, some paths have changed so, thank you brumnas for your script, i have to modify it.
orig. post: https://forums.freenas.org/index.php?threads/tutorial-jdownloader-in-a-jail.48374/#post-345343

Open your favorite editor in your jail (with root rights), paste the code below in (if you have putty or another terminal which support copy/paste, if you have only the console from FreeNAS, copy/paste will not work, so you have to type it char for char), save and quit and set the execute rights, otherwise the script won't work.

1.) vi /etc/rc.d/jdstart
(you could also type in "cd /etc/rc.d && touch jdstart && vi jdstart"
but i think this method is a way easier.
2.) paste the code in this file
3.) :wq! (save, quit)
4.) chmod 555 jdstart (to make jdstart for owner, groups and others executable)
5.) try your script: ./jdstart start
6.) wait a few seconds and then try to login with your my.downloader.org webUI
7.) if all works fine, close jdownloader with your webUI, restart your jail and wait....
if you have everything done right, you can login within a few seconds/minutes
in your webUI again, without starting JDownloader by your own[/code]

Code:
#!/bin/sh
###################################
# just a little bit advertisement :D
# JDownloader Startup Script by 'brumnas'
# modified by pseiko000
#
# --- placeholder ---
###################################
. /etc/rc.subr
#
name="spustit"
start_cmd="${name}_start"
stop_cmd=":"
#
spustit_start()
{
		umask 000
		/usr/local/bin/java -Djava.awt.headless=true -jar /usr/home/jduser/JDownloader.jar &
}
#
load_rc_config $name
run_rc_command "$1"

Edit: 2 recommendations i forgot.

Use the archiv extractor, otherwise you open your share on your windows/linux pc, extract it by your own what means that the data you'd like to extract were copied to your workstation, extracted and copied back to your nas.
If JDownloader extract the downloads automatically, you'll find the extracted data on your share without to do anything.
You should also choose the option "delete files after extracting", otherwise you have your data doubled (ziped and extracted).

I've read, the extractor works only after you disable it, reboot your jail, and enable it back again. Yes, it don't extract my files, after downloading. So i've done it this way, but i think you can also ONLY restart JDownloader, without restart your whole machine (jail).

Edit2: Split 4th in 4th a) and 4th b)
 
Last edited:

mrMuppet

Contributor
Joined
Mar 14, 2014
Messages
192
Found it:

After a while I found this entry in the log files (<jdownloader_dir>/logs/<log_dir>/ExtractionExtension.log.0):
Caused by: java.lang.UnsatisfiedLinkError: /root/tmp/7zip/SevenZipJBinding-QPcxx/lib7-Zip-JBinding.so: Shared object "libstdc++.so.6" not found, required by "lib7-Zip-JBinding.so"

This means that the C++ Compiler (gcc) is not installed on the system which it apparently it is not by default on FreeNAS. To install it run this command:
> pkg install lang/gcc

Now extraction really works!!!
 
Last edited:
Top