Heroku + Java + WAR deployment + New Relic - java

Heroku don't allow to upload files, just git repository(we can't share sources) and WAR files. We using WAR.
So, how i can use(my own newrelic.yml and newrelic-agent.jar) new relic with war deployments on heroku?
update.
Ok, i add newrelic add-on to application, and now can set some environment variables:
heroku config:set NEW_RELIC_APP_NAME="name"
heroku config:set NEW_RELIC_LICENSE_KEY="key"
But it's very basic and not working :). How to pass own config file to add-on?
update.
Find similar question: Heroku : Using NewRelic with heroku deploy:war approach

The simplest way to get application monitoring working with New Relic is by using the add-on as described here: https://addons.heroku.com/newrelic
Something like this should work:
heroku addons:add newrelic:stark
Heroku has some documentation about how to monitor Java applications using New Relic here: https://devcenter.heroku.com/articles/newrelic#java-configuration
There are also some other similar Stack Overflow questions about Heroku, New Relic and Java. For example:
adding newrelic addon heroku java

You can upload a .war file to Heroku using either the Heroku toolbelt:
heroku plugins:install https://github.com/heroku/heroku-deploy
heroku deploy:war --war <path_to_war_file> --app <app_name>
Or directly using curl:
curl -X POST -F war=#mywebapp.war -i https://:<API_KEY>#direct-to.herokuapp.com/direct/mywebapp/war

Related

Unable to deploy EAR file to Azure App Service using JBOSS EAP 7

I am unable to deploy EAR file into Azure App Service with JBOSS EAP 7.3.6.
I tried following steps as described in the documentation found at this link.
Out of given 4 options, allowed to use either Azure CLI or Kudu API since EAR is not supported by Azure Powershell and Kudu UI not supporting any.
Using Azure CLI, tried executing following command.,
az webapp deploy --resource-group test-rg --name dmap --src-path C:\Users\HP\Desktop\DMAP.ear
Getting error as
CommandNotFoundError: 'deploy' is misspelled or not recognized by the system.
Did you mean 'deployment' ?
Still stuck? Run 'az webapp --help' to view all commands or go to
'https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest' to learn
more
Using Kudu API, tried executing following command.,
curl -X POST -u dmap --data-binary #"C:\Users\HP\Desktop\DMAP.ear" https://dmap.scm.azurewebsites.net/api/publish&type=ear
Getting response as
The system cannot find the file specified.
Searching for this response, I found this link where it comes for successful deployment too. Assuming it I tried to access my application using link https://dmap.azurewebsites.net/DMAPWeb. But it shows nothing found.
To verify the deployment, I checked folder /site/wwwroot using FTP but I don't see any files deployed.
Could you please guide me here and clarify where I am wrong.
We have tested this in our local environment it is working fine. Below statements are based on our analysis.
Using the Below Azure CLI cmdlet , we have tried deploying the .ear file from local machine to web app (deployed in azure ) operation got succeeded without any issues.
Here is the cmdlet we have used :
az webapp deploy --resource-group <rgName> --name <webAppName> --src-path c:\Users\Downloads\<fileName>.ear ##Path of .ear file
Here is the Sample output for reference:
Note:
If you are deploying from local machine run the az.cmd(AzureCLI) in admin mode. By default az.cmd will be under the path c:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin in your local machine.

Springboot standalone application deploy in production

I am trying to deploy my springboot standalone application in production in linux server.I am trying to use the out of the box tomcat server.
'java -jar jarname.jar'
This works fine , but if I close my putty session the application is unistalled.
Now I used
'nohup java -jar jarname.jar &'
this works good and my application is not shutdown even if my putty session is closed.But the logs will not roll correctly(I have configured log4j to create a new log file for each day) in this case. So was wondering if this is the right way to do this.
I have searched several documentation but was not able to find a correct solution for this problem.
Please help.
Thanks
Well I think it's better to use Linux services for running application, you can read here for example
And if you want to collect logs - better write them to the file.
Spring provides build-in me mechanics to do that
logging:
level:
root: INFO
file:
clean-history-on-start: false
max-history: 7
max-size: 10MB
name: some-name
path: /path/log/dir
total-size-cap: 0B
Why not package it into a Docker image and run that on the server?
Here are a few ideas:
https://medium.com/swlh/deploying-spring-boot-applications-15e14db25ff0
You can run your spring boot application as jar, but you need to create a service so you can execute your spring boot as daemon.
https://dzone.com/articles/run-your-java-application-as-a-service-on-ubuntu
With this, you can start or stop your application like
$ sudo service myspringbootapp stop
$ sudo service myspringbootapp start

How to deploy Spring Boot application in Google Cloud Compute Engine?

I am a new to Google Cloud platform. I want to deploy my Spring Boot project in Compute Engine because deploying in App Engine costs more than the Compute Engine. There are a lot of videos/articles are available in YouTube/Websites for deploying in App Engine but I did not find any tutorial on deploying Spring Boot app in Compute Engine.
Here is the very good blog written on How to deploy Spring Boot app in Google Cloud Compute Engine with embedded tomcat?. I am just briefing here.
If you want to use an embedded tomcat server then PM2 is the best tool for managing the deployment in Compute Engine. PM2 is a process manager for the JavaScript runtime Node.js. Actually without PM2 also you can deploy Spring Boot app directly by executing command mvn spring--boot:run but the problem is when you exit the terminal then your server will also go down. Here you can use excute the command in background by using setsid mvn spring-boot:run. This will execute your Spring Boot app in background but when you need to restart the server then you will the error like Web server failed to start. Port 8080 was already in use
Hence you need to kill the existing running app by finding what is the processId. This is somehow a headache. Hence I will also recommend you to use PM2. To install PM2 you can use these commands in ubuntu.
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
sudo npm install -g pm2
If you want test your Spring Boot application, you can clone or pull the project from your Github repository or you can clone the spring-boot-test project from here.
git clone https://github.com/altafjava/spring-boot-test.git
cd spring-boot-test/
You will have to create one .sh file which will be used by the PM2 to restart the server. In your .sh file you need to write the command which is used to execute the spring boot project that is nothing but mvn spring-boot:run
echo "mvn spring-boot:run">server.sh
chmod +x server.sh
Finally, restart the server by using the command pm2 restart server. You can even check the logs on runtime by using pm2 logs.

adding new relic addon to heroku play framework 2.2.1 java app

Here is what I want to do. --> Deploy a play framework (2.2.1) Java web application on Heroku and use newrelic as an add on.
**Issue /problem:**
These are the steps i did so far.
1) I am able to add addon using the heroku command of addon "heroku addons:add newrelic:stark" I see the add on in the heroku resources.
2) Adding the newrelic.yml file. added the newrelic.yml file as attached and saved in the conf folder of the play framework (were the application.conf file is present). The file I picked up is from https://gist.github.com/anfuerer/6169040 (just updated licence and app info)
3) As its play 2.2.1, changed the built.sbt file to add dependencies.
"com.newrelic.agent.java" % "newrelic-agent" % "3.4.0",
"com.newrelic.agent.java" % "newrelic-api" % "3.4.0"
4) My Procfile which is required for heroku has the JAVA_OPTS specified and the JAVA_OPTS is set by using the command
heroku config:set JAVA_OPTS=”-Xmx384m -Xss512k -XX:+UseCompressedOops -Dfile.encoding=UTF-8 -javaagent:target/staged/newrelic-agent-3.4.0.jar -Dnewrelic.bootstrap_classpath=true -Dnewrelic.config.file=./conf/newrelic.yml newrelic.config.log_level=finer newrelic.debug=true”
5) obviously all the changes are added to git and committed before pushing to heroku by command "git heroku push master".
6) some basic sanity test.. I see my config after heroku config command as -
JAVA_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops -Dfile.encoding=UTF-8 -javaagent:target/staged/newrelic-agent-3.4.0.jar -Dnewrelic.bootstrap_classpath=true -Dnewrelic.config.file=./conf/newrelic.yml newrelic.config.log_level=finer newrelic.debug=true
NEW_RELIC_APP_NAME: test_application
NEW_RELIC_LICENSE_KEY: 000000000000000000000000000000000 (changed offcourse)
NEW_RELIC_LOG: stdout
PATH: .jdk/bin:.sbt_home/bin:/usr/local/bin:/usr/bin:/bin
REPO: /app/.sbt_home/.ivy2/cache
SBT_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops
Also tried to check by "heroku run env | grep NEW_RELIC" which gives me output -
NEW_RELIC_LOG=stdout
NEW_RELIC_LICENSE_KEY=00000000000000000000000000000
NEW_RELIC_APP_NAME=test_application
Now I go to my Heroku app dashboard, click on my app to see the add ons and click on new relic and i come to a screen which asks me to setup my app-
I click on setup, but which takes me to download the Java agent and it want me to install the java agent on to the webserver.
#################EDIT
Trying to install java newrelic on Play app framework as per #Jeanie's comment
1) download the new relic java agent in downloads folder.
2) unzip to the play framework app folder(project folder) (does this need to be the play framework folder where play build files are??) using
unzip newrelic_agent3.4.0.zip -d /path/to/appserver/
3) change directory to /appfolder/newrelic/
4) install the jars using
java -jar newrelic.jar install
5) This is the message I am getting.
Jan 20, 2014 12:48:39 -0700 [6935 1] com.newrelic INFO: Agent is using Logback
***** ( ( o)) New Relic Java Agent Installer
***** Installing version 3.4.0 ...
Could not edit start script because:
.:. Could not locate a Tomcat, Jetty, JBoss, JBoss7 or Glassfish instance in /home/amit/Applications/play-2.2.1/appfolder/
Try re-running the install command with the -s <AppServerRootDirectory> option or from <AppServerRootDirectory>/newrelic.
If that doesn't work, locate and edit the start script manually.
No need to create New Relic configuration file because:
.:. A config file already exists: /home/amit/Applications/play-2.2.1/appfolder/newrelic/newrelic.yml
***** Install incomplete
***** Next steps:
For help completing the install, see https://newrelic.com/docs/java/new-relic-for-java
Am I missing something here? Please note this is a Play framework app and I want newrelic addon to work on heroku and not locally on my machine.
#
Questions:
1) How do I install the java agent on heroku?? Do I need to in the first place?
2) Shouldn't heroku and new relic add on pick up my app as I have already added the api and java agent as a add on as step 3 ??
Any help or direction appreciated.
Issue resolved. Here are the steps.
1) Get the add on on Heroku by
$ heroku addons:add newrelic:stark
2) Go to your app dashboard and click on resources. Then click on the new relic addon. This will take you to a page where it will ask you to do a set up.
3) Click on set up, select Java, click to see your licence number and download the jar files.
4) As mentioned on the set up page unzip the jars files to the root of your project. Don't run the installer as you need the new relic working on Heroku.
5) Edit the Heroku Procfile as below:
web: target/universal/stage/bin/myapp -Dhttp.port=${PORT} ${java_opts} -DapplyEvolutions.default=true -Ddb.default.driver=com.mysql.jdbc.Driver -Ddb.default.url=${CLEARDB_DATABASE_URL} -J-javaagent:newrelic/newrelic.jar -J-Dnewrelic.config.file=newrelic/newrelic.yml
(change the other settings as per your need, keep the new relic settings unchanged, dont forget to put your app name in place of myapp in "target/universal/stage/bin/myapp")
6) Add dependency to either build.sbt or Build.scala
"com.newrelic.agent.java" % "newrelic-agent" % "3.7.0"
7) Deploy the app to heroku using git push heroku master
8) New relic will be automatically detected and the setup page will show the relevant metrics.
If anyone face any issues, let me know.
Just to get it out of the way so that we're not asking you the same basic questions. Did you go off the instructions at https://devcenter.heroku.com/articles/newrelic and pay close attention to the Java configuration at https://devcenter.heroku.com/articles/newrelic#java-configuration? That should get you going in the right direction.
Let us know if this does the trick or if you need further help. There is a ticket associated with this that we can continue to troubleshoot further, if needed.

Deploy - java application using appcfg.py

I have created a google-app-engine Java project in Eclipse using Google's Eclipse plugin. I had tried to deploy my application using terminal as follows:
~$ appcfg.py update /home/crimson/Music/Testing5/InitialData/
But it shows the following error:
appcfg.py: command not found
How to solve this?
If you developed a Java application using Google App Engine, you shouldn't use appcfg.py, that is meant for Python projects. See the documentation of Google App Engine for more details on how to deploy a Java-based project. In a nutshell, you will need appcfg.sh if you are on Linux or Mac OS X, or appcfg.cmd if you are on Windows.
If you are using linux try this following step :
Go to your appengine-sdk/bin
type chmod u+x appcfg.sh
run this command --> sh appcfg.sh rollback [your app war path location]

Categories