We are working on jruby on rails app. Want to set JRUBY_OPTS or JAVA_OPTS.
I can easily use the export to set them on my machine, but I'd like these options to persist with the application.
Our application runs on tomcat in production can set options there in the config file.
Putting export JAVA_OPTS in the initializer file didn't work, seems like the options are set after application starts
you can not "persist" such options within the app.
as you exported locally you might export JAVA_OPTS before Tomcat starts - its a JVM process that will read and set those opts for the VM, your app being deployed there has no control over most settings possible via JAVA_OPTS (memory, stack-size etc)
Related
I have a Spring Boot application, which runs in an Apache Tomcat server. In application.yaml I have, among others, following entries:
mail:
pop3Host: ${MAIL_HOSTNAME}
inboxFolder: ${MAIL_INBOX}
hostName: ${MAIL_HOSTNAME}
port: ${MAIL_PORT}
userName: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}
The application is deployed to Tomcat from within IntelliJ Idea so I can debug it.
I start Tomcat using the following command:
export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8090,server=y,suspend=n"
export JAVA_OPTS=" -DMAIL_HOSTNAME='smtp.provider.com' -DMAIL_INBOX='MAIL_INBOX' -DMAIL_PORT='587' -DMAIL_USERNAME='username' -DMAIL_PASSWORD='XXXXXXXX'"
export CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8090,server=y,suspend=n"
./catalina.sh jpda start
However, after I
start Tomcat using the above script,
deploy the Spring Boot application from IntelliJ Idea, and
make sure that the code where those values are used is executed,
I get the exception indicating that the placeholders have not been substituted.
How can I fix it, i. e. make sure that I can specify some information (like user name and password) in application.yaml via environment variables (so that I don't include the actual credentials in application.yaml)?
export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8090,server=y,suspend=n"
export JAVA_OPTS=" -DMAIL_HOSTNAME='smtp.provider.com' -DMAIL_INBOX='MAIL_INBOX' -DMAIL_PORT='587' -DMAIL_USERNAME='username' -DMAIL_PASSWORD='XXXXXXXX'"
export CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8090,server=y,suspend=n"
./catalina.sh jpda start
Add export MAIL_HOSTNAME= etc. to the above lines, or create a setenv.sh file with such lines (in the same directory as catalina.sh file).
Using setenv.sh is documented in RUNNING.txt file of Apache Tomcat.
It is not possible to pass JVM arguments to a process running in a remote machine from an IDE. The Spring Boot params will be loaded from the JVM params when the process is started in the remote machine. I am sorry to say that it won't work.
An alternate solution i suggest is, use spring config server to create a separate profile for remote debugging config ( like we will have for Dev, QA environments etc ). When you try to debug the application, please restart the remote application using jenkins job ( I am assuming you don't have remote acccess to the box where the app is running) by passing the profile name in the jenkins job so that the values you wanted will be picked up. Please let me know if you need more details.
I've been trying to automate the creation of our development environment by combining batch files and WLST, but I am struggling to change the memory WebLogic server will start with.
Currently we are manually changing the memory settings in the <DOMAIN_HOME>/bin/setDomainEnv.cmd script, but this is a workaround. It should be possible to to do it automatically without much effort.
Setting the Domain
The script that sets the Domain in pretty simple:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_45
set MW_HOME=C:\dev\wls1036_dev
set DOMAIN_HOME=C:\dev\domain
cd %MW_HOME%
call configure.cmd
mkdir %DOMAIN_HOME%
cd %DOMAIN_HOME%
%JAVA_HOME%\bin\java.exe -Xmx1024m -XX:MaxPermSize=256m -Dweblogic.management.username=weblogic -Dweblogic.management.password=welcome1 weblogic.Server
I've tried to use some variables in this script such as MEM_ARGS, JAVA_OPTIONS, but none of these are forwarded to the final configuration of the domain, later it always starts with 512 heap, and 128 perm, which are not enough.
WLST memory start args
We are using Eclipse, and it does call the startWebLogic.cmd as start script. It is the standard configuration.
I tried to use the following WLST script. It does set the server start arguments, but WebLogic is not using those properties and loads not enough memory.
edit()
startEdit()
cd('/Servers/myserver/ServerStart/myserver')
cmo.setArguments('-Xmx1024m -XX:MaxPermSize=256m')
activate()
Any ideas?
You can use the trick for getting ServerStart arguments:
Write simple offline WLST-script to get arguments from config.xml:
getArguments.py
import sys
readDomain(sys.argv[1])
cd('Server/%s/ServerStart/NO_NAME_0' % sys.argv[2])
argsFile = open('arguments.txt', 'w')
print >>argsFile, cmo.arguments
Add this script to startWeblogic.cmd like:
startWebLogic.cmd
...
set DOMAIN_HOME=%~dp0
path\to\wlst.cmd getArguments.py %DOMAIN_HOME% admin_server_name
set /p EXTRA_JAVA_PROPERTIES=<arguments.txt
call "%DOMAIN_HOME%\bin\startWebLogic.cmd" %*
There is no easy way of setting values when executing WebLogic from Eclipse. It'll call the batch script and, at least at current version, does not allow to send dynamic parameters.
We solved it making the setDomainEnv.cmd file part of our versioned configuration:
Copy the setDomainEnv.cmd file to your version control configuration.
Edit whatever you want (memory, etc)
Copy the file like copy custom\setDomainEnv.cmd %DOMAIN_HOME%\bin /y when running your development environment configuration script.
Now every time you configure your development environment memory values will be ready without manual intervention.
You have to reedit your stuff when updating WebLogic, so you don't end up with an outdated component.
Why can my application not access environment variables that I have set? I deployed a WAR to AWS and set environment variables via ssh, but am unable to read them in. This process works in my dev environment, so not sure why it won't work in production. Any ideas? I am on a windows box locally and a linux box in production, but I don't think that should matter.
The environment variables should be set so that the user your app's process is running as can see them.
You say you are deploying a WAR - so my guess is that it's on tomcat - you could add your environment variables to the setenv.sh script in the tomcat/bin directory.
Sample setenv.sh contents with a few options for tomcat and an environment variable:
export CATALINA_OPTS="-Xmx1024M -XX:PermSize=512M -Duser.timezone=UTC -DgeoIPFile='/some/path/to/GeoIP.dat' -DxafileDir='/tmp/xafile' -DuploadDir='/path/to/uploads/dir'"
export MYENVVAR="12345"
Back story:
I have 3 Grails applications I want to run on the same Tomcat7 server. I am able to run 2 at a time without a problem but it is when I try to deploy the third I get a Java crash. Alternatively the app fails to deploy or it deploys but Java crashes within the hour.
/etc/default/tomcat7 has the following to limit Java's maximum memory usage:
JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseConcMarkSweepGC"
In each app's BuildConfig.groovy I can specify a bunch of arguments.
eg: grails.tomcat.jvmArgs = ["-Xms96m", "-Xmx128m"]
Question:
Are the arguments passed via grails.tomcat.jvmArgs only for their respective app (each app can have different memory demands/limits) or does the first deployed set global arguments for all applications?
Is something else happening?
The setting grails.tomcat.jvmArgs is only used for the development time Tomcat instance started by grails run-app, not for when you deploy to an external Tomcat instance. In that case the settings can be customized using CATALINA_OPTS
export CATALINA_OPTS=”-Xms256m -Xmx512m”
These settings apply to all apps deployed to Tomcat, so if you have 3 Grails apps you need to set sufficient memory for the three.
I need to pass a couple of JVM arguments to the JVM which Tomcat is running in so that my application can pick them up.
I want to follow the process outlined in this article to pick up environment variables.
How would I go about doing this?
UPDATE
Sorry This is running under windows (7 on my Dev machine 2003 on client server)
Windows:
In your Tomcat /bin folder, you should have a tomcat5w.exe admin app (or in later versions tomcat6w.ex, tomcat8w.exe, etc). Go to the Java tab and add the args in the "Java Options:" box.
Note that when you add new args, you need to add them as NEW LINES in that box (above or below any others there), not as additional arguments IN FRONT or BACK of values on one of the existing lines.
Linux / UNIX:
In *nix, changes to the setenv.sh file should be picked up:
export JAVA_OPTS=-server -Xms2g -Xmx4g -XX:PermSize=64m -XX:MaxPermSize=256m $JAVA_OPTS
Don't touch catalina.sh or other files in bin
You need to edit the Windows service. There are three ways to do this:
Start Tomcat5w with //MS//ServiceName to get an icon in the system tray which gives you a quick access to the configuration of the service.
Open the service manager in the "Control Panel". There is an entry for Tomcat.
In the editor, there is a tab where you can add additional JVM parameters.
The third way (which I prefer) is to write a script which edits the config for you. This way, you can save the config somewhere for backup. See the docs how to do that (Hint: use tomcat5 //US//...)