PHP exec Java cmd failed with permission denied - java

I am currently writing some PHP scripts that need to invoke jar. I wrote a test script to test Java -version cmd.
echo exec('whoami');
echo '<hr/>';
exec('java -version', $out);
var_dump($out);
The page return as below:
apache
array(6) { [0]=> string(134) "OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007ff705000000, 2555904, 1) failed; error='Permission denied' (errno=13)" [1]=> string(1) "#" [2]=> string(76) "# There is insufficient memory for the Java Runtime Environment to continue." [3]=> string(100) "# Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory." [4]=> string(57) "# An error report file with more information is saved as:" [5]=> string(29) "# /tmp/jvm-26720/hs_error.log" }
I have test the cmd in the console and it is normal.
[root#localhost ~]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
Is there anyone who can help me with this?
Update: Here is the hs_error.log

I had a similar issue. I duplicated it on the RedHat 7 (installed on the Amazon EC2).
Only when selinux was switched to the permissive mode - the issue was fixed.
Sudo or login as root
To check the status: $ sestatus or $ getenforce.
To turn it off:
temporary: $ setenforce 0.
permanently: edit /etc/selinux/config file
After deeper research, it looks that it is better to enable "apache to use the memory" and not turn off the mode:
setsebool -P httpd_execmem 1
More info here.

Related

"Error: Unable to access jarfile" if try'd to start from .sh script

I have the following problem: I would like to have a .sh file that starts a jar file so I have created one with nano and added the following:
java -jar myjarfile.jar
But Java gives me the following error "Error: Unable to access jarfile myjarfile.jar" so I tried to start it directly from the console with the same command. This works without problems so I checked the rights:
chmod 775 myjarfile.jar
chmod 775 start.sh
But I have exactly the same result. So I tried it with the root account but that did not help either. So slowly I'm a little bit desperate because I can not think of it anymore...
System information:
Linux version 4.9.0-8-amd64 (debian-kernel#lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) ) #1 SMP Debian 4.9.110-3+deb9u6 (2018-10-08)
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
Thanks for any answer :)

Springboot app getting stuck at startup in Docker with Java 10

Solution
Error existed between chair and keyboard
The problem was that the SPRING_PROFILES_ACTIVE environment variable was pointing to a profile that didn't exists. Changing it to the correct name fixed the issue. I would have expected Spring to output an error about that, but oh well.
Original question:
I have a "hello world" Java App build running with Spring boot in Java10. It runs fine directly on my machine, but when trying to start it up with docker it gets stuck with the following output:
(The Srping ascii art)
:: Spring Boot :: (v2.0.1.RELEASE)
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (jar:file:/app.jar!/BOOT-INF/lib/groovy-2.4.15.jar!/) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
The process running:
java -Xmx800m -Djava.security.egd=file:/dev/./urandom -jar /app.jar
It runs fine directly on my laptop (Mac OS), and on my coworker's (Windows 7), but it fails in docker both locally and on Kubernetes (AWS)
I have tried configuring spring log level to DEBUG, but with no effect.
I also tried to edit $JAVA_HOME/conf/security/java.security to change directly the java securerandom.source property, which didn't work either.
Edit:
The dockerfile is a FROM using this:
FROM openjdk:10-jdk
RUN apt-get update && \
apt-get install -y openssl curl
ADD java.security /docker-java-home/conf/security/java.security
ONBUILD ARG BUILD_VERSION_NO="no-version"
ENV SPRING_PROFILES_ACTIVE=prod
#ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n"
ONBUILD COPY target/*.jar app.jar
ONBUILD RUN sh -c 'touch /app.jar'
ONBUILD RUN echo "$BUILD_VERSION_NO" > /version
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]
The java version in my laptop is
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Packaging the app with the equivalent openjdk doesn't solve the problem
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10)
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)
Answering my own question in case someone else bumps into this:
The SPRING_PROFILES_ACTIVE environment variable contained "prod" whereas the spring profile in the application was "pro". Changing the value in the Dockerfile fixed the issue.

Ant failed with error "Failed to locateorg.apache.tools.ant.Main" in centos5.11

Unable to execute ant. it was working fine. but suddenly started throwing an error. can someone please help. Checked the environment variables and everything seems to be fine.
[root#usbossbuild ~]# ant -version
Failed to locateorg.apache.tools.ant.Main
ant.home: /hidapp_build/u01/apache-ant-1.8.4
Classpath: /hidapp_build/u01/apache-ant-1.8.4/lib/ant-launcher.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/activation.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-antlr.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-bcel.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-bsf.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-log4j.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-oro.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-regexp.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-resolver.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-apache-xalan2.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-commons-logging.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-commons-net.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-contrib-1.0b3.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-jai.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-javamail.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-jdepend.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-jmf.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-jsch.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-junit.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-junit4.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-launcher.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-netrexx.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-swing.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ant-testutil.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/jsch-0.1.50.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/mail.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/ojdbc6.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/surround.jar:/hidapp_build/u01/apache-ant-1.8.4/lib/xmltask.jar:/hidapp_build/u01/jdk_home/lib/tools.jar
Launcher JAR: /hidapp_build/u01/apache-ant-1.8.4/lib/ant-launcher.jar
Launcher Directory: /hidapp_build/u01/apache-ant-1.8.4/lib
Below are environment variables which required for ANT
[root#usbossbuild ~]# echo $ANT_HOME
/hidapp_build/u01/apache-ant-1.8.4
[root#usbossbuild ~]# echo $JAVA_HOME
/hidapp_build/u01/jdk_home
[root#usbossbuild ~]# which java
/hidapp_build/u01/jdk_home/bin/java
[root#usbossbuild ~]# java -version
java version "1.6.0_38"
Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)
[root#usbossbuild ~]# ls -lrt /hidapp_build/u01/jdk_home/lib/tools.jar
-rwxrwxrwx 1 oracle build 12627443 May 3 2013 /hidapp_build/u01/jdk_home/lib/tools.jar
Below are output from jenkins. in this i see it is searching in different path /usr/lib/jvm. i dont know why.
[SIS_Dev_MA_2.3_Onboarding_scm_workaround] $ /hidapp_build/u01/apache-ant-1.8.4/bin/ant -file sis_onboard_scmworkaround.xml download
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.34.x86_64/lib/tools.jar
I ran into an issue like this because my /etc/profile.d/ant.sh file had Windows-style line endings instead of UNIX style. You can verify this if you try "cd $ANT_HOME" and it shows a messed up error message like ": No such file or directory1.9.4".

Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server

Trying to start Solr with sunspot but having an issue with the Java Runtime Environment by getting this error.
root#oktobTest:~# dokku run oktob bundle exec rake sunspot:solr:start
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:203:in `ensure_java_installed'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:27:in `initialize'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `new'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `server'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:10:in `block (3 levels) in <top (required)>'
Tasks: TOP => sunspot:solr:start
(See full trace by running task with --trace)
Solar is up and running on the remote server.
Java is installed
root#oktobTest:~# which java
/usr/bin/java
And this is the output of sudo update-alternatives --config java
root#oktobTest:~# sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1073 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1072 manual mode
3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1073 manual mode
I edited /etc/profile file to export the path inspired by discussions here and here and javaandme
JAVA_HOME=/usr/java/default
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
I'm not sure about the path above is it correct or not.
config/sunspot.xml file
production:
solr:
hostname: localhost
port: 8983
log_level: WARNING
path: /solr/production
# read_timeout: 2
# open_timeout: 0.5
development:
solr:
hostname: localhost
port: 8982
log_level: INFO
path: /solr/development
test:
solr:
hostname: localhost
port: 8981
log_level: WARNING
path: /solr/test
To me, reinstallation JDK(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) fixes the problem that happened during the first use of solr in El Capitan
I got the same error. When running the following command.
$ bundle exec rake sunspot:solr:start -t
** Invoke sunspot:solr:start (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:solr:start
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
By using this command
$ bundle exec rake --execute 'puts which java'
I am getting '/usr/bin/java'.
But by the following command
$ java --version -> 'No Java runtime present, requesting install.
I am using Mac OSX and it prompted a message and clicking on more info it goes to:
oracle.com/technetwork/java/javase/downloads/index.html
So I installed JDK 8 from the link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
for mac OSX
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-macosx-x64.dmg
$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
After that Solr server run successfully :) .
In your case you have to reinstall the JDK from the above link to make it work
You have openJDK runtime environment. Switch to Java(TM) SE Runtime Environment, to make Solr work. Read this (difference-between-oracle-jdk-and-open-jdk)
Run the Solr server background by
$ bundle exec rake sunspot:solr:start -t
Successfully started Solr ...
Stop Solr server:
$ bundle exec rake sunspot:solr:stop -t
Start solr server in the foreground:
$ bundle exec rake sunspot:solr:run -t
There are some topics about this problem. If you are sure that Java on the server is fine, please try to paste in configuration file (config/sunspot.yml) for the relevant environment this line "solr_home: solr" and start solr server by "RAILS_ENV=[your_env] bundle exec sunspot:solr:start"

Rails 4: Solr throwing JavaMissing error, but Java is installed

I restarted my Rails 4 VPS and Solr was obviously also shutdown. I am now trying to startup Solr but when I run the following RAILS_ENV=production bundle exec rake sunspot:solr:start I get the following error message:
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/server.rb:203:in `ensure_java_installed'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/server.rb:27:in `initialize'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:37:in `new'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:37:in `server'
/home/dani/.rvm/gems/ruby-2.1.2/gems/sunspot_solr-2.1.1/lib/sunspot/solr/tasks.rb:5:in `block (3 levels) in <top (required)>'
/home/dani/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/dani/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sunspot:solr:start
(See full trace by running task with --trace)
The weird thing is that Java is installed:
$ echo $JAVA_HOME
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
$ java -version
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
I'm not sure what might be causing this behavior. Any suggestions?
Try adding to PATH the folder where java is, like this:
export PATH=$PATH:/path/to/java/bin
so that java could be callable from everywhere without specifying the folder.
Launching this before calling rake solved the problem for me.

Categories

Resources