gauravsuman007 / megabasterd-docker

Run the megabasterd app inside a debian container and access the app GUI through noVNC web UI on port 5800
15 stars 5 forks source link

[Bug] Think "/dev/null" as app's home may cause startup crashes when using MB v8.?? #5

Open gnatbandanna opened 9 months ago

gnatbandanna commented 9 months ago

Current Behavior

Default (uses MB 7x) pull of gauravsuman007/megabasterd-docker and subsequent docker compose up works flawlessly, however after upgrading ./config/Megabastered/jar/MegaBastered.jar with the jar from MegaBasterdLINUX_8.18_portable.zip, the following error occurs:

SEVERE: path to '/dev/null/.megabasterd8.18/megabasterd.db': '/dev/null/.megabasterd8.18' does not exist. 

This works fine when reverting back to v7.7x.

Expected Behavior

I expect what the docs say: To manually upüdate to the latest Megabasterd release, download the latest Linux version of their java package, unzip it and copy the MegaBasterd.jar from the jar folder to /config/MegaBasterd/jar/ (replacing the existing file). Restart the container and the new version should be loaded!

Steps To Reproduce

(error follows)

Environment

Container creation

docker compose up

version: '3'
name: megabasterd
services:
  megabasterd:
  image: gauravsuman007/megabasterd
   ports:
     - "5802:5800"
    volumes:
     - "/home/pi/docker/config:/config:rw"
     - "/Downloads:/output:rw"

Container log

...
megabasterd-megabasterd-1  | [cont-init   ] 89-info.sh: terminated successfully.
megabasterd-megabasterd-1  | [cont-init   ] all container initialization scripts executed.
megabasterd-megabasterd-1  | [init        ] giving control to process supervisor.
megabasterd-megabasterd-1  | [supervisor  ] loading services...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'default'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'logrotate'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'app'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'gui'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'openbox'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'xvnc'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'nginx'...
megabasterd-megabasterd-1  | [supervisor  ] loading service 'certsmonitor'...
megabasterd-megabasterd-1  | [supervisor  ] service 'certsmonitor' is disabled.
megabasterd-megabasterd-1  | [supervisor  ] loading service 'logmonitor'...
megabasterd-megabasterd-1  | [supervisor  ] service 'logmonitor' is disabled.
megabasterd-megabasterd-1  | [supervisor  ] all services loaded.
megabasterd-megabasterd-1  | [supervisor  ] starting services...
megabasterd-megabasterd-1  | [supervisor  ] starting service 'xvnc'...
megabasterd-megabasterd-1  | [xvnc        ] Xvnc TigerVNC 1.13.1 - built May 16 2023 17:43:39
megabasterd-megabasterd-1  | [xvnc        ] Copyright (C) 1999-2022 TigerVNC Team and many others (see README.rst)
megabasterd-megabasterd-1  | [xvnc        ] See https://www.tigervnc.org for information on TigerVNC.
megabasterd-megabasterd-1  | [xvnc        ] Underlying X server release 12014000
megabasterd-megabasterd-1  | [xvnc        ] Sun Dec 10 00:25:46 2023
megabasterd-megabasterd-1  | [xvnc        ]  vncext:      VNC extension running!
megabasterd-megabasterd-1  | [xvnc        ]  vncext:      Listening for VNC connections on /tmp/vnc.sock (mode 0660)
megabasterd-megabasterd-1  | [xvnc        ]  vncext:      Listening for VNC connections on all interface(s), port 5900
megabasterd-megabasterd-1  | [xvnc        ]  vncext:      created VNC server for screen 0
megabasterd-megabasterd-1  | [supervisor  ] starting service 'openbox'...
megabasterd-megabasterd-1  | [supervisor  ] starting service 'nginx'...
megabasterd-megabasterd-1  | [nginx       ] Listening for HTTP connections on port 5800.
megabasterd-megabasterd-1  | [supervisor  ] starting service 'app'...
megabasterd-megabasterd-1  | [supervisor  ] all services started.
megabasterd-megabasterd-1  | [app         ] Dec 10, 2023 12:25:49 AM com.tonikelope.megabasterd.SqliteSingleton getConn
megabasterd-megabasterd-1  | [app         ] SEVERE: path to '/dev/null/.megabasterd8.20/megabasterd.db': '/dev/null/.megabasterd8.20' does not exist
megabasterd-megabasterd-1  | [app         ] Exception in thread "main" java.lang.NullPointerException
megabasterd-megabasterd-1  | [app         ]     at com.tonikelope.megabasterd.DBTools.setupSqliteTables(DBTools.java:33)
megabasterd-megabasterd-1  | [app         ]     at com.tonikelope.megabasterd.MainPanel.main(MainPanel.java:111)
megabasterd-megabasterd-1  | [supervisor  ] service 'app' exited (with status 1).
megabasterd-megabasterd-1  | [supervisor  ] service 'app' exited, shutting down...
megabasterd-megabasterd-1  | [supervisor  ] stopping service 'nginx'...
megabasterd-megabasterd-1  | [supervisor  ] service 'nginx' exited (with status 0).
megabasterd-megabasterd-1  | [supervisor  ] stopping service 'openbox'...
megabasterd-megabasterd-1  | [supervisor  ] service 'openbox' exited (with status 0).
megabasterd-megabasterd-1  | [supervisor  ] stopping service 'xvnc'...
megabasterd-megabasterd-1  | [xvnc        ] Sun Dec 10 00:25:50 2023
megabasterd-megabasterd-1  | [xvnc        ]  ComparingUpdateTracker: 0 pixels in / 0 pixels out
megabasterd-megabasterd-1  | [xvnc        ]  ComparingUpdateTracker: (1:nan ratio)
megabasterd-megabasterd-1  | [supervisor  ] service 'xvnc' exited (with status 0).
megabasterd-megabasterd-1  | [finish      ] executing container finish scripts...
megabasterd-megabasterd-1  | [finish      ] all container finish scripts executed.

Container inspect

No response

Anything else?

I have followed the procedure linked with 7.xx and this DID NOT solve the problem for me with 8x. https://github.com/gauravsuman007/megabasterd-docker/issues/2

I also tried upgrading to jdk11 and that DID NOT fix the issue either.

Looking at how MB determines where to write its db, it does use the $HOME var, and is different between MB v8 and v7. I'm not proficient in java, so I'm not certain how these differences affect figuring out the home directory.

v8:

public static volatile String MEGABASTERD_HOME_DIR = System.getProperty("user.home");

conn = DriverManager.getConnection("jdbc:sqlite:" + MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SQLITE_FILE + "?journal_mode=WAL&synchronous=OFF&journal_size_limit=500");

v7

public static volatile String MEGABASTERD_HOME_DIR = System.getProperty("user.home");

File database_path = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION);

Further, this problem DOES NOT occur with root, which does have a home directory defined:

If I connect to a running container with

docker exec -u app -it megabasterd-megabasterd-1 /bin/sh

and use the command

/usr/lib/jvm/java-1.8-openjdk/jre/bin/java -jar ./jar/mb.jar

I get the error (note mb.jar is v8.20):

Dec 09, 2023 2:04:07 PM com.tonikelope.megabasterd.SqliteSingleton getConn SEVERE: path to '/dev/null/.megabasterd8.20/megabasterd.db': '/dev/null/.megabasterd8.20' does not exist

However, if I do the same as '-u root', it works fine (expected soft error):

Dec 09, 2023 2:05:16 PM com.tonikelope.megabasterd.SqliteSingleton getConn SEVERE: path to '/config/MegaBasterd/jar/.megabasterd8.20/megabasterd.db': '/config/MegaBasterd/jar/.megabasterd8.20' does not exist

and if I change 'root' home to /dev/null, as in the 'app' user, I get precisely the same error as 'app':

Dec 10, 2023 12:37:05 AM com.tonikelope.megabasterd.SqliteSingleton getConn SEVERE: path to '/dev/null/.megabasterd8.20/megabasterd.db': '/dev/null/.megabasterd8.20' does not exist

and if I change 'app' home to /config/MegaBasterd/jar/, it works as expected, no error:

java -jar ./MegaBasterd820.jar 

no error, yay! works:

LinuxOpenJDK 64-Bit Server VM 11.0.21 /usr/lib/jvm/java-11-openjdk

gnatbandanna commented 9 months ago

Until this is resolved, for anyone else having this issue now, and would like to build a working image with 8.x, try the below. Note I presume the passwd issue is coming from jlesage's image, and I didn't bother changing anything there since it would be annoying for anyone to maintain. I fudged it instead. Cinit was chosen because it's one of the only things that runs as root:

Add/Edit to Dockerfile:

ARG VERSION=8.20
...
COPY fix.cinit /fix.cinit
RUN /fix.cinit

and place fix.cinit where you're doing your docker build. The fix.cinit:

#!/bin/sh

echo "===> Fudging cinit <==="

cd /opt/base/sbin/
mv cinit cinit.bin

echo \
"cat <<EOF>/etc/passwd
root::0:0::/root:/sbin/nologin
app::1000:1000::/config/MegaBasterd/jar/:/sbin/nologin
EOF" > cinit

echo '/opt/base/sbin/cinit.bin "$@"' >> cinit
chmod +x cinit
gauravsuman007 commented 9 months ago

Thank you for the detailed investigation, around holiday season it's hard to find the time for debugging. I will set up the right home variable value for the user app and push out an updated build if it works.

I'll leave a comment here for you to test the new build to ensure it also works as expected on the raspberry platform.

gnatbandanna commented 9 months ago

Thank you for the detailed investigation, around holiday season it's hard to find the time for debugging. I will set up the right home variable value for the user app and push out an updated build if it works.

No problem! Note that I did try exporting HOME in /startapp.sh and that didn't seem to work, which led me to think that maybe Java uses the passwd file directly (maybe someone with Java knowledge can correct me), so I just fudged it -- and that worked. You'll probably have a more elegant solution!