Cloud Foundry java buildpack - java: command not found - java

New to cloud foundry, using the java buildpack to push a zip distribution of a java app. It detects the start script correctly, but when the start script gets to the point where it needs to start up the jvm, I get this error:
bash: java: command not found
Apparently 'java' is not on the shell's path during execution of the script, and I'm not finding a JAVA_HOME definition anywhere.
What is the path to use for starting java apps?
Where is it documented?
FALSE ALARM
Many thanks to #DanielMikusa for pointing out that JAVA_HOME is indeed set, even in the pretty old version of the buildpack that was in use. Nothing to see here.
EDIT #1
I've been able to find out that when the start script launches there is a jre located in $PWD/.buildpack-java/oracle_jre. But, this can't be what I'm expected to use to specify for the path of JAVA_HOME, can it? It seems like this location is entirely dependent on the java buildpack's current implementation. It seems like either the jre's bin folder should be in the start script's process' path or that there should be an environment variable or other configuration established prior to running the launch script so I can use that value for finding the java executable.
EDIT #2
Below is the output during the cf push operation:
PS E:\dev\hoobajoob\myproject\build\distributions> cf push -p .\my-service-1.0.0.zip my-service
Using manifest file E:\dev\hoobajoob\myproject\build\distributions\manifest.yml
Creating app my-service in org DEV / space dev as chefhoobajoob#github.com...
OK
Creating route my-service.cflab.dctmlabs.com...
OK
Binding my-service.cflab.dctmlabs.com to my-service...
OK
Uploading my-service...
Uploading app files from: C:\Users\hoobajoob\AppData\Local\Temp\unzipped-app384867239
Uploading 9.7M, 9390 files
Done uploading
OK
Starting app my-service in org DEV / space dev as chefhoobajoob#github.com...
Downloading oracle_buildpack_151...
Downloading binary_buildpack...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading java-buildpack-offline-v3-19-2...
Downloaded java-buildpack-offline-v3-19-2
Downloading java-buildpack-offline-4-7...
...<more downloads>
Creating container
Successfully created container
Downloading app package...
Downloaded app package (53.1M)
Staging...
-----> Java Buildpack Version: v3.5.1 (offline) | https://github.com/cloudfoundry/java-buildpack.git#3abc3db
-----> Downloading Oracle JRE 1.8.0_112 from http://127.0.0.1/oracle-jre/trusty/x86_64/jre-8u112-linux-x64.tar.gz (found
in cache)
Expanding Oracle JRE to .java-buildpack/oracle_jre (2.3s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/
trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
Memory Settings: -Xms2304M -XX:MetaspaceSize=314572K -Xss1M -Xmx2304M -XX:MaxMetaspaceSize=314572K
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/
auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (108B)
Uploaded droplet (120.5M)
Uploading complete
Destroying container
Successfully destroyed container
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App my-service was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/oracle_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_HOME=$PWD/.java-buildpack/oracle_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/oracle_jre/bin/killjava.sh $CALCULATED_MEMORY" exec $PWD/my-service-1.0.0/bin/launch`

Writing up the comments above in case someone else comes across this question.
We reviewed the full output of staging and the start up command generated by the Java buildpack.
We could see from the start command generated by the Java buildpack that it is the start commands responsibility to set JAVA_HOME.
If you rely on the Java buildpack to create the start command for your dist-zip style applications, it will "do the right thing" and add the JAVA_HOME environment variable with the correct path to the start command.
If you need to create a custom start command, it is your responsibility to set JAVA_HOME correctly.
If you cf ssh into an application started by the Java buildpack, it is your responsibility to set JAVA_HOME.

Related

Unable to create directory path [/User/Desktop/db2/logs] for Neo4j store

I am trying to use a tool that, in two steps, analyzes code smells for android.
In the first step, the tool parses an apk and generates within a directory .db files that should then be converted to CSV files in the next step; however, whenever I try to run the second step, the console returns the following error:
java.io.IOException: Unable to create directory path [/User/Desktop/db2/logs] for Neo4j store.
I think it is a Neo4J configuration problem.
I am currently running the tool with the following Java configuration:
echo $JAVA_HOME
/home/User/openlogic-openjdk-11.0.15
update-alternatives --config java
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
To be safe, I also started Neo4J, which returned the following output
sudo systemctl status neo4j.service
neo4j.service - Neo4j Graph Database
Loaded: loaded (/lib/systemd/system/neo4j.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-07-06 20:11:04 CEST; 16min ago
Main PID: 1040 (java)
Tasks: 57 (limit: 18901)
Memory: 705.4M
CPU: 16.639s
CGroup: /system.slice/neo4j.service
└─1040 /usr/bin/java -cp "/var/lib/neo4j/plugins:/etc/neo4j:/usr/share/neo4j/lib/*:/var/lib/neo4j/plugins/*" -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExper>.
How can I solve this?
You posted this error:
java.io.IOException: Unable to create directory path [/User/Desktop/db2/logs] for Neo4j store.
From that error, it looks like:
Neo4j was installed at "/User/Desktop/db2"
The permissions for that directory do not have "write" permission
I tried to reproduce this locally using Neo4j Community 4.4.5, following the steps below.
I do see an IOException related to "logs", but it's slightly different from what you posted. Perhaps we're on different versions of Neo4j.
Open terminal into install directory: cd neo4j
Verify "neo4j" is stopped: ./bin/neo4j stop
Rename existing "logs" directory: mv logs logs.save
Remove write permission for the Neo4j install: chmod u-w .
Start neo4j in console mode: ./bin/neo4j console
Observe errors in console output
2022-07-08 03:28:38.081+0000 INFO Starting...
ERROR StatusLogger Unable to create file [****************************]/neo4j/logs/debug.log
java.io.IOException: Could not create directory [****************************]/neo4j/logs
...
To fix things, try:
Get a terminal into your Neo4j directory:
cd /User/Desktop/db2
Set write permissions for the entire directory tree:
chmod u+w -R .
Start neo4j in console mode:
./bin/neo4j console
If this works and you're able to run neo4j fine, it points to an issue with user permissions when running neo4j as a system service.
The best steps from there depend on the system, your access, how comfortable you are making changes, probably other things. An easy, brute-force hammer would be to manually create each directory you discover (such as "/User/Desktop/db2/logs") and grant premissions to all users (chmod ugo+w .), then try re-running the service, see what errors pop up. Repeat that until you're able to run the service without errors.

AWS ElasticBeanstalk Play Framework 2.8.8 deployment issue with CheckProcfileForJavaApplication

Trying to deploy a Play Framework based Application using an ELB container
Recently it seems that AWS made changes to the way ELB works as we've done this before without issue.
The error we currently get is:
2021/12/14 23:00:15.705423 [INFO] Executing instruction: CheckProcfileForJavaApplication
2021/12/14 23:00:15.705468 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle
2021/12/14 23:00:15.705474 [INFO] Executing cleanup logic
2021/12/14 23:00:15.705598 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1639522815,"severity":"ERROR"}]}]}
Now of course I wouldn't be here if this was the actual problem
# cd /var/app/staging/server-xxxxxxxxxxx/
# ls -l
total 16
-rw-r--r-- 1 webapp webapp 135 Dec 14 20:39 Procfile
drwxr-xr-x 2 webapp webapp 82 Dec 14 22:21 bin
drwxr-xr-x 2 webapp webapp 113 Dec 14 22:21 conf
drwxr-xr-x 2 webapp webapp 8192 Dec 14 22:21 lib
drwxr-xr-x 3 webapp webapp 17 Dec 14 22:21 share
So Procfile exists
Hmmm is it valid however?
Let's check that out:
# cat Procfile
web: bin/server -v -J-Xms512M -J-Xmx2048m -J-server -Dhttp.port=5000 -Dhttps.port=8443 -Dconfig.resource=application.conf
Looks normal enough -- but does it actually work?
Short answer is yes -- if I copy and paste that command (minus the "web:" prefix of course) system comes up without any issues (ELB still fails to realize that though...)
I've tried a few variants of the command thinking that it might be related to yaml formatting of perhaps a tighter regex ^[A-Za-z0-9_-]+:\s*[^\s].*$ (source: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html)
web: bin/server
web: ./bin/server
web: bin/server
web: ./bin/server
web:bin/server
web:./bin/server
No difference (both worked when manually started without or without the leading ./ btw)
Unsure how I move forward here?
How do we find what the real problem is so that we have fighting chance to fix it?
And yes -- the initial trace above is already the output of eb-engine.log
Using (in case this is relevant)
Coretto Java 11
Play 2.8.8
Scala 2.13.6
SBT 1.5.2
Will answer any relevant queries that help improve this question and any chance of resolving it. Most Google searches I've dug through are related to other environments and are simply a missing Procfile...
I have worked out the following work-around to be able to use a standard (well slightly modified) Play Framework dist directly in an AWS ELB Java container
We start with the typical sbt dist process to create a zip "distribution" file
That file won't work in the format it is currently in (I've been researching and I will be asking specific questions to see if making it work directly might be possible) however it only takes a few small tweaks to get it to work
First Step: Modify Procfile (a file that you manually create and place in the project's dist directory) as follows:
web: chmod 700 bin/server; bin/server -v -J-Xms512M -J-Xmx2048m -J-server -Dpidfile.path=/dev/null -Dhttp.port=5000 -Dconfig.resource=application.conf
Note the chmod 700 bin/server; that was the final secret sauce required to make this work! I was kinda shocked that it did work actually. I did not think that would get past the regex they use to parse the Procfile
As a zip file is permissions agnostic, once I finally got the elb install process to get past that first "missing jar" hurdle I noticed the permissions on bin/server were simply rw. The ec2 instance's /var/log/eb-engine.log did not quite spell that out too clearly, however I confirmed that whenever I manually modified those permissions (on the ec2 instance) and then ran the bin/server command (to verify it) the Play server would start right away (however the elb container still failed to see it as a legitimate process and continued to report it as Status of no data, nor did it allow the load balancer to send it traffic so this "fix" was a real shot in the dark!)
Second step: Unzip that zip file and cd into the directory it created/assigned
cd server-vxxxxxxxxxxxxxx
touch placeholder.jar
The second dab of secret sauce is that the placeholder.jar file is simply a means to satisfy the CheckProcfileForJavaApplication which simply looks for the existence of any file named *.jar in the root of the bundled directory. If that file does not exist then the elb install script stops dead in it's tracks.
Note: You could simply place this empty placeholder.jar file in the Play dist folder if you prefer
Third Step: Create a new zip file elb.zip
zip --exclude share/doc/api/\* -r elb.zip .
Now take elb.zip and upload it to an AWS ELB container and low and behold it (finally) springs to life!

Gradle Daemon stopped working in parallel due to file lock timeouts

Yesterday all of the sudden my projects on a Windows 10 machine stopped running in parallel due to file lock timeouts.
All my projects are using gradle-wrapper and provide a run task
When I start the 1st run-task, it work normally, but any following run-tasks break with the error like this:
> .\gradlew run
Starting a Gradle Daemon, 1 busy and 4 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
Gradle could not start your build.
> Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal().
> Timeout waiting to lock journal cache (C:\Users\injec\.gradle\caches\journal-1). It is currently in use by another Gradle instance.
Owner PID: 16440
Our PID: 12216
Owner Operation:
Our operation:
Lock file: C:\Users\injec\.gradle\caches\journal-1\journal-1.lock
the --status option shows:
> .\gradlew --status
PID STATUS INFO
12216 IDLE 6.9.1
16440 BUSY 6.9.1
14992 STOPPED (stop command received)
7856 STOPPED (other compatible daemons were started and after being idle for 0 minutes and not recently used)
26680 STOPPED (by user or operating system)
18556 STOPPED (by user or operating system)
I tried different tricks, like switching the Gradle verison 5.6.1 - 6.8.3 - 6.9.1 and using the --stop option, but the error remains.
Adding the --stacktrace to the run command reveals that not only journal-1 cache is involved, but also some others dirs like modules-2.
I didn't do any changes to my system, apart from regular Win10 updates.
How can the problem be fixed?
TIA
It's likely that gradle process was exited abnormally and left the lock file behind. Check in the task manager if process with id 16440 exists, and if not just remove the orphan lock file C:\Users\injec\.gradle\caches\journal-1\journal-1.lock
This may be the file-system permissions of C:\Users\injec\.gradle... while you may have overseen one detail: you're calling .\gradlew instead of ./gradlew or gradlew.bat ...which means that you are not running on CMD, but on PS or WSL. gradlew.bat run would run directly on CMD.
Check .gradle file system. Gradle not works well on non-native file system. https://github.com/gradle/gradle/issues/15881
File system watching supports the following file system types:
APFS
btrfs
ext3
ext4
XFS
HFS+
NTFS
Gradle also supports VirtualBox’s shared folders.
Network file systems like Samba and NFS are not supported.
Symlinks
File system watching is not compatible with symlinks. If your project files include symlinks, symlinked files do not benefit from file system watching optimizations.
or you can disable file system watch for the build https://docs.gradle.org/current/userguide/file_system_watching.html#disable
Gradle maintains a Virtual File System (VFS) to calculate what needs to be rebuilt on repeat builds of a project. By watching the file system, Gradle keeps the VFS current between builds.

Managed VM deploy failed because "env" setting is not supported

Trying to deploy a Java app to Google Appengine Managed VM. I'm using console gcloud and already prepared WAR file. Plus app.yaml.
Using following command:
gcloud preview app deploy ./build/libs/app.yaml
Right now it fails with:
Building and pushing image for module [default]
-------------------------------------------------------------------------------- DOCKER BUILD OUTPUT --------------------------------------------------------------------------------
Step 0 : FROM gcr.io/google_appengine/jetty9
---> 005014071b64
Step 1 : ADD webapp-webapp.war $JETTY_BASE/webapps/root.war
---> 3e9023930cc8
Removing intermediate container 342e8a2f5750
Successfully built 3e9023930cc8
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Beginning teardown of remote build environment (this may take a few seconds).
Updating module [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [400] "env" setting is not supported for this deployment.
I see similar error (there) for maven-gcloud-plugin that happens when project is not configured as WAR. But notice that:
i'm using plain command line tool gcloud, a latest version
and my project is packaged into WAR already
Also i'm using following app.yaml (which i've got from maven plugin sources):
runtime: java
env: 2
api_version: 1
handlers:
- url: .*
script: dynamic
So the question, where from this error is coming from (docker image is already prepared at this moment, right?). What it means? And how to fix this?
Update
I noticed that it uses FROM gcr.io/google_appengine/jetty9 for VM. But for Appengine it should be FROM gcr.io/google_appengine/jetty9-compat. I've tried to switch to exploded app instead of WAR, and it started using correct Docker base image. But still fails:
Building and pushing image for module [default]
-------------------------------------------------------------------------------- DOCKER BUILD OUTPUT --------------------------------------------------------------------------------
Step 0 : FROM gcr.io/google_appengine/jetty9-compat
---> 2ad8572ef3d8
Step 1 : ADD . /app/
---> b10f4bc6718e
Removing intermediate container 8b149f4baf9c
Successfully built b10f4bc6718e
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Beginning teardown of remote build environment (this may take a few seconds).
Updating module [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [400] "env" setting is not supported for this deployment.
The reason was this line in app.yaml:
env: 2
it was too simple and too obvious to try to deploy w/o this option. Also, every doc, official and unofficial, mentions that you need to have env: 2 option set to deploy your app as Appengine app. That's really strange.
Removing this line also changed base Docker image to gcr.io/google_appengine/java-compat. I guess it means that jetty images, including jetty9-compat, aren't compatible with Appengine apps

specify port for standalone mode in PlayFrameWork 2.2.1

I have two apps developed in PlayFrameWork 2.2.1 named:
1. helloWorld_88
2. helloWorld_99
For helloWorld_88:
I want to build this app run (standalone) on port 88.
For helloWorld_99:
I want to build this app run (standalone) on port 99.
As I know, using "dist" task will help me to build a standalone version of apps but I don't know how to specify the port.
Can anybody advice step by step.
Thanks
Rado
Hi Rado, Thanks for your quick reply.
I have already try this before I post the question, but the port always 9000.
See bellow output from the command line (Windows)
E:\Deploy\helloworld_88\bin>helloworld_88 -Dhttp.port=88
Play server process ID is 2216
[info] play - Application started (Prod)
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
Any other idea
Thanks
I assume that you have built both applications using "play dist" command and that you run them using generated "bin/helloWorld_88" and "bin/helloWorld_99" script files on Linux. (for Windows these files are named "bin/helloWorld_88.bat" and "bin/helloWorld_99.bat")
Go to the "bin" folder and run:
helloWorld_88 -Dhttp.port=88
and then for the second application do:
helloWorld_88 -Dhttp.port=99

Categories

Resources