Starting Java app with Jail

Status
Not open for further replies.

Lessbones

Dabbler
Joined
Oct 17, 2016
Messages
22
Hi all--

I've been attempting to get a java app running at startup in a jail with no luck. Basically i've created a script that can run the app, but it only works when run from within the folder containing the app-- if I call it from / or anywhere else it doesn't work. Even if I change the location of the app in the script to /path/to/java.jar it still seems to expect to be inside the folder in order to be able to find everything and run properly.

My hacked together solution to fix this was to "cd" as the first step of the script-- basically this is what I want it to do:

1. cd /folder/containing/app/
2. tmux new sessession
3. run java app
4. detach session

this is the commad I have right now:

cd /App_location && tmux new-session -s app_Start java -Djava.net.preferIPv4Stack=true -Dsun.stdout.encoding=UTF-8 -jar JavaApp.jar -XX:+UseConcMarkSweepGC -Xmx512m -Xms512m

this works, when called from anywhere, from within a script file. But it doesn't seem to work when placed in /usr/local/etc/rc.d or as a command issued in cron.

I realize this is probably an extremely inelegant way of doing this, but I couldn't wrap my head around what I was reading here: https://www.freebsd.org/doc/en/articles/rc-scripting/ in order to get something so seemingly simple to start...

The next thing I tried was to install pm2 to manage the app instead of relying on starting it manually and using tmux, but pm2 throws up syntax errors on trying to run to run it per the instructions of the app creators (who are running on linux)

if anyone can help me make an actual script for this, or point me in the direction of an alternative management tool i'd be much obliged-- thanks everyone
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
So the following does not work?
"tmux new-session -s app_Start /path/to/java -Djava.net.preferIPv4Stack=true -Dsun.stdout.encoding=UTF-8 -jar /path/to/JavaApp.jar -XX:+UseConcMarkSweepGC -Xmx512m -Xms512m"

You may also make a start.sh script with all of you startup commands and just call that from cron.
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Just did a quick search and found this its for minecraft and uses screen but could but adapted.
 

Lessbones

Dabbler
Joined
Oct 17, 2016
Messages
22
Thanks for that-- The minecraft script could very well be adapted. I ended up moving over to using pm2 on debian in a bhyve VM-- there were just too many things broken on freebsd with this particular app. (mostly trying to get dotnet installed ended terribly)

When I tried to call the command as you wrote it with "/path/to/java" it would complain of not finding all sorts of files because the shell wasn't currently inside the folder in question. (it would start the app, but then not be able to find other files) and for whatever reason trying to start the script with "cd" in cron or rc.d simply wouldn't do anything-- I'd log in and there would be no open tmux session...

thanks anyway though-
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Hmm sounds like the app is not finding its location and using paths relative to that. It sound like its assuming the PWD is the base path... Seems like a trivial thing for the developer to have overlooked. You also mentioned .net so if its a developer from the microsoft realm that might explain it. :D
 
Status
Not open for further replies.
Top