Run a Spring boot application in the background jenkins slave --windows - java

I have a spring boot application with embedded tomcat in it. I need to run this application in Jenkins the problem is that the build goes into an infinite loop.
javaw -jar myjar.jar
does the same thing as mentioned above. It was mentioned somewhere in SO that if we append start with the above mentioned code it will work.
start javaw -jar myjar.jar
the issue with this is that Jenkins build are completed now, but the application doesnt run.
Is there any way i can solve this issue ?
Note:
Jenkins and salve is running on windows.

Related

Running application with java + maven + tomcat (embedded) the port is not found

I've got no previous experience with java. Trying to run project from github - https://github.com/ESPD/ESPD-Service. The Service uses Maven for building multi-module Maven project. I'm using mvn clean package in order to generate the project.war file. Then type java -Dspring.profiles.active=prod -Xms768m -Xmx768m -jar project.war and the app is running in a Tomcat container with port 8080 and it shows on the cmd console that the app is running perfectly but the problem comes when i try to access the localhost:8080. It says Not Found and I've been looking all over the internet to find a solution but without success. Will appreciate a lot if someone gives me a hand on that one.
Java version should be JDK 1.8,
Maven version must be no greater than 3.5.0
Then add 2 libraries to ESPD-Service\espd-web\target\espd-web\WEB-INF\lib folder: mail-1.4.7.jar and activation-1.1.1.jar cuz they are currently missing.
After that run mvn install in order to install all the jars files and then run the java -Dspring.profiles.active=prod -Xms768m -Xmx768m -jar espd-web.war as it's written on the docs. And also when the app is running on localhost:8080 make sure you add localhost:8080/espd

Adding Java jar as Ubuntu service

I am trying to add my java jar application to Ubuntu as service so that when the Ubuntu server is restarted I dont need to manually run the jar command to run my application. At present I have to run this cmd on the terminal
java -jar myapp.jar -conf conf.json.
I came accross this link which would have solved my problem but for some reason the service is not running when i run the service as described in that website.
http://www.jcgonzalez.com/ubuntu-16-java-service-wrapper-example
Can someone please help me!!
I think your bash script should have "nohup" like this:
nohup java -jar myapp.jar -conf conf.json &

Restore old Jenkins jobs in Windows after the update

We were running plug-in rich Jenkins 2.46.1 and one of my team member tried to update Jenkins but it just hangs on displaying Please wait while Jenkins is restarting message for about 2 hours so I somehow forced Jenkins to shutdown and then started it using java -jar Jenkins.war command.
When Jenkins restarted again all my jobs were not displayed in Jenkins GUI but they were present in jobs and workspace folders so I tried an option Reload configuration from disk but that also did not restore jobs.
Please someone advice how I can restore my Jenkins jobs as they were before.
I believe you are not pointing JENKINS_HOME correctly. You may need something like this as startup script/batch file
For Linux:
export JENKINS_HOME=<path/to/old/jenkins/home>
java -jar Jenkins.war
For Windows:
set JENKINS_HOME=<path/to/old/jenkins/home>
java -jar Jenkins.war
Basically running war directly points to default temp directly for Jenkins Home. It can be overwritten by above environment variable. You can also centrally define it so that each start you do not need specify again.

Spring boot App not working after ssh logout

So I'm deploying my Spring Boot application on an Ubuntu LTS Server. It is built with maven and running with embedded Tomcat.
I'm still new to the deployment process, what I did was:
Log into server via ssh
use scp to upload my_application.zip
unzip it in ssh
java -jar my_application.jar
Now all of that works perfectly fine and I've been using it like that for quiet some time. Now I have to make the Application to stay online and available after logging out of the shell.
I have read some documentation about running processes in background on Linux and I've tried it with nohup java -jar myApplication.jar &, with the screen command and with bg. All of them worked fine while I'm logged into the ssh.
Here comes my problem:
As soon as I end the ssh session the Web App is still available (so the process clearly didn't stop) but it just looks & behaves really weird.
CSS is not applied, JS does not work etc.
My guess would be that some paths or file system accesses are messed up, but I have no idea at all how that could origin from the ssh session.
(When I log back into ssh everything is working fine again)
Would be great if someone has a clue here
If your server has encrypted home directory, it will get re-encrypted once you log out and therefore your script will stop working. It does not have a lot of sense to have encrypted homes on servers so you can disable it.
Or just run the script from different directory and avoid working with files under home directory.
I think you should use systemd for this case.
Also You can add new system user for your app.
You can find more information here:
Spring Boot: 59.2.2 Installation as a systemd service
Ubuntu Wiki: Systemd For UpstartUsers
For example:
Create file myunit.service
[Unit]
Description=MySpringService
After=syslog.target
After=network.target
After=mysql.service
[Service]
Type=forking
PIDFile=/work/www/myunit/shared/tmp/pids/service.pid
WorkingDirectory=/work/www/myunit/current
User=myunit
Group=myunit
Environment=RACK_ENV=production
OOMScoreAdjust=-1000
ExecStart=/usr/local/bin/bundle exec service -C /work/www/myunit/shared/config/service.rb --daemon
ExecStop=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state stop
ExecReload=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state restart
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Copy file to /etc/systemd/system/
Run:
systemctl enable myunit
systemctl start myunit

How to properly start a script generated by gradle using upstart?

I'm trying to deploy an Java app onto VPS. I'm using Gradle build system with 'application' plugin. I want the app to start up with the server.
During deployment process I run ./gradlew install to prepare run scripts. When ran directly, they work properly.
I used http://www.whiteboardcoder.com/2014/02/ubuntu-upstart-job-with-java-jar.html as a base for upstart configuration:
description "the test server"
start on runlevel [2345]
stop on runlevel [!2345]
expect fork
script
cd /opt/testserver/
exec ./build/install/testserver/bin/testserver
end script
But the PID reported by upstart after running start testserver is different then the one found using ps. My guess is that the reason for that is the last line of generated script:
exec "$JAVACMD" "${JVM_OPTS[#]}" -classpath "$CLASSPATH" mypackage.TestServer"$#"
As a result Upstart is not able to stop the app. Is there a way to make upstart see the right PID?
Well it looks like there is no forking going on here, so you should try removing the expect fork bit.

Categories

Resources