Android Question jRDC2 not running (yet) on Linux on Raspberry4

Status
Not open for further replies.
Hi,

seem to have trouble getting jRDC2 running on Raspberry running Linux Ubuntu Server 20.04 with Apache and Mariadb, some things are really unclear:
- Installed Openjdk/jre 11 via putty on the Raspberry
- followed this tut https://www.b4x.com/android/forum/t...-rdc-remote-database-connector.61801/#content and the video
In configuration.properties I'm not sure if it should read localhost or LAN-IP where Rasp is on like 192.168.0.240
also not sure if the mariadb string is correct, could not find that on their website
in configuration.properties:
#DATABASE CONFIGURATION
DriverClass=com.mariadb.jdbc.Driver
JdbcUrl=jdbc:mariadb://localhost/test?characterEncoding=utf8
User=mewhoelse
Password=blablabla
#Java server port
ServerPort=17178

sql.select_info=SELECT id, this, that, who FROM table;
- copied the jRDC.jar to folder private, because it was stated to not put it in www folder in case of apache server, but also not where to put it in case of apache
-opened port 17178 on Raspberry (I'm using ISPconfig and opening a port in the Firewall is easy)
- followed this https://www.b4x.com/android/forum/threads/server-run-a-server-on-a-vps.60378/page-2 giving the nohup command via putty I get no confirmation if it has started or not, it looks like it is hanging
- Entering 192.168.0.240:17178/test or http://mylocalwebsitename.int:17178/test in FireFox browser does nothing, Firefox says can't make a connection
- Running jRDC server in B4J and entering localhost:17178/test in the browser it shows that it is running (but no db connection as I had Xampp not running on windows)
- Stopped B4J
- Started the app in B4A
This is in sub process_globals:
B4X:
Sub Process_Globals
Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Private const rdcLink As String = "http://192.168.0.240:17178/rdc"
    End Sub

this is like in the example sub :
B4X:
Sub InfoData
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_info", Null)
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        req.PrintTable(res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

and in Activity_Create sub this was added:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    InfoData
    'and of course the rest of it..'
    End Sub

When running in B4A and requesting data from Raspberry I get this error:
ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to /192.168.0.240 (port 17178) from /192.168.232.2 (port 35584) after 30000ms, Response:
ERROR: java.net.SocketTimeoutException: failed to connect to /192.168.0.240 (port 17178) from /192.168.232.2 (port 35584) after 30000ms

Now it seems thejRDC2 Server is just not running on the Raspberry. How do I get this running correctly?
And where is this strange ip and port coming from 192.168.232.2 (port 35584) ---is that B4A or the android emulator?

Thanks for any help
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Many mistakes here.

1. Apache has nothing to do with B4J servers.
2.
because it was stated to not put it in www folder in case of apache server
No, it wasn't stated. This is a security mistake. Never put it under the www folder.

You can and should check the logs with:
B4X:
tail -f nohup.out
3. My guess is that the relevant port (17178) is not open in your server firewall settings.
 
Upvote 0
Thank you for your reply.


I was referring to this:
I checked the open ports with UFW status command:


Looks open to me.

I now tried the cgi-bin folder and even the www folder just for test sake and run the command again:
B4X:
sudo nohup usr/bin/java -jar jRDC.jar > nohup.out &

Is this correct?

If I try to call the log with: sudo tail -f nohup.out
Then it just seems to hang, no output in Putty.

In B4A I get the same error message as in the 1st post.

FYI: I added this to the manifest as SSL is working on ISPconfig, but not yet on the created website:
B4X:
'In case of non-SSL due to ssl is not working on the page yet
CreateResourceFromFile(Macro, Core.NetworkClearText)
So I'm trying to fix SSL for the website on the raspberry (just local, not public yet)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should read the instructions more carefully.

I now tried the cgi-bin folder and even the www folder just for test sake and run the command again:
It has nothing to do with jRDC2.

Why are you using sudo?
SSL is also not related here.

Start with running it with:
usr/bin/java -jar jRDC.jar
 
Upvote 0
Hi,
thank you both for your replies.
I think I confuse it with user of Linux itself and user of a website. As I'm using ISPconfig this creates sites, as you can use it to act like host for multiple websites.
I'm trying to see this the same as an VPS.
So the private folder is /var/www/clients/client1/web1/private, and under web1 is also the folder: web = htdocs = www folder.
I tried what Aeric mentioned, so created the app folder in /home/myname/ then copied jRDC.jar into that app folder.
nohup usr/bin/java -jar jRDC.jar > nohup.out &
or usr/bin/java -jar jRDC.jar
I get: nohup: failed to run command 'usr/bin/java': No such file or directory

It's not root path, because then I had to do sudo su
Think I'm going to re-read the article again, there are not that many steps but. Will try some more and if I don't get it to run will fall back to php as middleware.
Thanks!
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Ah, you're using sudo! If using sudo for the first time, you will be asked for the password. With using nohup, that does not happen and your process does not start properly. Usually, what I do, before using sudo to start a application for testing via nohup is to run it with another command, such as sudo apt-get update. Once sudo asks for a password, the next several commands you use with sudo will work without typing in the password. BTW, a more proper way of doing this would probably be this: https://unix.stackexchange.com/a/91182
 
Upvote 0
HI,
I tried as you suggested I get errors like this: nohup: Unable to run the command "java": No such file or directory
I've uploaded as the Linux user (not the website user) to /home/jerry/app/
used whereis java to get the correct path
so 1st sudo ls
next I tried different nohup, even complete paths:
nohup /usr/lib/jvm/java-11-openjdk-arm64/bin -jar /home/jerry/app/jRDC.jar > nohup.out & ---i get persmission denied
nohup /usr/bin/java -jar /home/jerry/app/jRDC.jar > nohup.out & ---nohup: ignoring input and redirecting stderr to stdout, seems to hang but....weird how it works,
testing it in the browser it seems to be running

but no connection to the db(credentials are 100% correct),

is this part correct from the config? Driverclass= and jdbcUrl= ?
B4X:
#DATABASE CONFIGURATION
DriverClass=com.mariadb.jdbc.Driver
JdbcUrl=jdbc:mariadb://localhost/test?characterEncoding=utf8
User=handsome
Password=indeed
#Java server port
ServerPort=17178

@OliverA do have the jar file also under /Home/user/ ?

Thanks!
 
Upvote 0
hmm, it run one time. getting errors again, permission denied / no such file which is kind of weird as Java is running just fine, path to the jar is ok
I give it another chance tomorrow, maybe copying the java unpacked (for ARM64) also to the home folder. and use full path for java and the jar
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The issue here is that we are dealing with too many things and too many steps have been skipped in order to properly diagnose the issue (even though, in a chaotic manner I'm pretty sure all the pieces of the puzzle are in this thread). Part of the issue is that I assumed you had a working application that you were trying to launch via nohup. How wrong I was. Here is the steps that should have brought you here to the forum:

1) Install Java on Pi and make sure it works and that the version aligns with the version you have on your PC (it must be greater or equal to the version on your PC). So in your case, Java may be installed (looking at post #10). The way to try is to use the command
Bash:
/usr/bin/java -version
. If that produces nothing, then maybe it is not installed. There are several ways to install Java. On the Pi (Version 4) it can be as simple
Bash:
sudo apt update
sudo apt install default-jdk
This should install Java 11, which you can verify by running
Bash:
java -version
Note #1: This installs the full OpenJDK without JavaFX. If you are only going to run server applications on the Pi, then you can install a stripped down version of Java via
Bash:
sudo apt install default-jre-headless
Note #2: You may need to run
Bash:
sudo update-alternatives --config java
and pick the correct Java you want the system to use, if there are multiple versions installed
2) Once you have Java up and running, then you need to test your application without using nohup. This way all output is displayed on the console and any error messages are easily seen. The application can be terminated via Ctrl+C. This method would have given you more insight as to why your test URL is not working as expected (@aeric's post #12 could be the solution)
3) Once everything works (Java and the application), then you can tackle nohup. Once you have your app running via nohup, if you want to restart it, you'll have to learn a little bit about kill and maybe (if you did not note/write down the PID that nohup displays) ps and grep in order to stop your application from running. Otherwise you will get more error messages due to the fact that the port you are using is already taken (by the currently running application).
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
@OliverA do have the jar file also under /Home/user/ ?
When testing, yes (in a sub-folder). Once I'm ready for more permanent usage, I create a folder in /var/opt and move the application into it.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
nohup /usr/bin/java -jar /home/jerry/app/jRDC.jar > nohup.out & ---nohup: ignoring input and redirecting stderr to stdout, seems to hang but....weird how it works
It is normal, not hang. What I normally do is press the enter key and then use the following command to ensure it is running.
B4X:
ps -ef | grep java
 
Upvote 0
Hello Oliver & Aeric,
thanks for your great replies.

On Win10 I have installed: (OpenJDK)
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)

On Raspberry I have installed:
jerry@192:~$ /usr/bin/java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode)

So there is a tiny difference, so to make sure I uninstalled and reinstalled(cause it did not want to update):
now followed this: https://adoptopenjdk.net/installation.html?variant=openjdk11&jvmVariant=hotspot#aarch64_linux-jdk
instead of installing directly via cmd(Putty).

jerry@192:~$ tar xzf OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.12_7.tar.gz
jerry@192:~$ export PATH=$PWD/jdk-11.0.12+7/bin:$PATH
jerry@192:~$ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

In B4A I have an application with which I try to connect to the jRDC server on the Raspberry.
Followed the HowTo on how to embed the needed scripts into that program.

I made a new build of jRDC.jar with the change as Aeric mentioned.

If it's running I know how to KILL it with the PID nr.

Now used this to run it:
B4X:
/home/jerry/jdk-11.0.12+7/bin/java -jar /home/jerry/app/jRDC.jar
then a bunch of text and then tadaaaa:
2021-08-11 19:55:31.554:INFOejs.Server:main: Started @2312ms
jRDC is running (version = 2.22)

that looks promising, I nearly gave up....
still an fetching problem although the credentials are copied from source which I use in PHP to connect to the db.

and because fetching is not succeeding this is the error in B4A:
ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:
ERROR: java.net.SocketTimeoutException: timeout

So when I get the connection to the DB when can start with the nohup as you said.
Now I have to figure out why it is not connecting.

Thanks!
 
Upvote 0
Question: why is there no line in the configuration file which database it has to connect to like in PHP? I only see username and password.
This might be the issue of not connecting to the database.
Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…