How to deploy the jar/war file in unix box and it should not stop after closing putty.
Steps tried:
Created jar/war file from Springboot project
Login to Unix box with root user
Created a Project folder in /opt path
Copied the jar/war file in Project folder
Executed below command to run the application in putty:
Command: java -jar myapplication.jar
Application is running fine but issue comes when i close my putty. Application shutdowns.
Any suggestions...
you need to create your custom service in your machine
EX: In Linux we use sudo systemctl start MySQL like that you have to create,
Please refer to this documentation which will help you to create your own.
EX: sudo systemctl start my_java_spring_service
I hope it helps!
Related
I have Jenkins master on Ubuntu host in docker containers, connected to it is a windows slave that i run Jenkins on it using a PowerShell script that launch the agent:
java -jar agent.jar -jnlpUrl http://XX.XX.XX..../jenkins-agent.jnlp -secret XXX... -workDir "/jenkins"
we start the launch agent script using this script that creates the job:
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $trigger -FilePath start_agent.ps1 -Name MyJob
my issues is:
when i go to the master UI and go to the slave node - i press on "logs" but it doesn't show anything, it just loads forever with 3 dots loading
I tried to redirect logs using *>&1 > output.txt at the end of the java -jar command but it doesn't work. and I haven't found any java jar argument that works in redirecting the output have tried -XX file path , couldn't find the Log4j file
i have a directory in the windows jenkins path named "remoting" and it has logs but it only have restart logs and not live logs\error logs and i need it.
Thanks.
I want to deploy my java spring backend to AWS .
I figured the way to deploy jar file on aws. But the problem is as soon as I terminate the terminal deployment stops. I created a jar file on build and hosted on aws EC2 linux Instance by copying jar file there and running below command .
java -jar jarfile
I want this deployment to be persistent. Is there any tool similar to pm2 for nodeJs in JAVA so that I can run this jar file permanently. ?
Thanks for help.
You should use nohup to deploy jar file. It will run even though you close terminal
E.g:- nohup java -jar javaservice.jar > nohup.log &
I try to deploy the sprin boot jar file into a remote Linux server and run it throw java -jar command.
The command was much like below:
ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
The problem is that there was no any log dir been created while i running the command.
The sprin boot app was created by the spring.io site,it's a normal app then i put one single line "logging.file=./log/my.log" into application.properties.
But it works(the log dir can be created) when i just logged into the target server and type the command in the ssh console.
The sprin boot version is 2.05 and i've test version 1.5.16 still the same.
And i aslo test it in both Ubuntu and Centos servers,nothing haapens too.
Really appreciate if you can give a clue on this!
Thanks all you guys , it turns out my fault, the reason is that I am using a relative log path ,and I run that java -jar command out side the shell directory.
old command:ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
new command:ssh root#xxx.com:cd /tmp; /myjdk_path/bin/java -jar target.jar
the log dir was been created for the old command ,but it in the user home path(for this command is the ROOT user),but not in the /tmp path.
so my stupid check steps missing that point,and thought there is no log dir been created!
I developed a Java server (using Spring) and uploaded the final executable JAR to an EC2 instance using FileZilla. Now I want it to run.
I've connected via SSH and used java -jar server.jar to run my server, and it worked (I've tried accessing it). However once the SSH connection is closed the server obviously stops running as well.
How can I start my application in such a way so it keeps running?
Edit: Using the command screen explained here I was able to run it in background and so it keeps running.
The issue is not cloud dependent its the configuration you have to do to run your jar as a service in your system.
If you are using Elastic Bean Stalk change systemctl to initctl in below example.
Put the script commands you wish to run in /usr/bin/demoscript.sh
Remember to make the script executable with chmod +x.
Create the following file:
/usr/lib/systemd/system/demo.service
[Unit]
Description=Demo Script
[Service]
Type=forking
ExecStart=/usr/bin/demoscript.sh
Reload the systemd service files: systemctl daemon-reload
Check that it is working with systemctl start demo
You need to make it run as daemon process in linux.
There are many tutorial / templates available to create a daemon shell script. Quick google search shows github has many templates, so check them out.
You could try using systemd which is a Linux service manager. You can use it to run your service in the background.
To do that you need to first create a unit file that describes how systemd should manage your service (more info here).
sudo vim /etc/systemd/system/your-application.service
Your file might look something like this
[Unit]
Description=Java Application as a Service
[Service]
User=ec2-user
#change this directory into your workspace
#mkdir workspace
WorkingDirectory=/home/ec2-user/workspace
#path to the executable bash script which executes the jar file
ExecStart=/bin/bash /home/ec2-user/workspace/your-script.sh
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Then in your home directory /home/ec2-user/workspace you can create the bash script that will run your java application.
sudo nano your-script.sh
Your script might look like this
#!/bin/sh
java -jar your-application.jar
All you need to do then is start the service with the command
sudo systemctl enable your-application.service
sudo systemctl start your-application.service
I installed postgreSQL binaries in windows 7 32bit operating system; I can start the server from cmd but I cant run it as a windows service.
This is the error that I'm getting when I try to start the service manually:
"The postgreSQL service on local computer started and then stopped. some services stop automatically if they are not in use by other servces or programs"
All I need to do is; after booting to windows when I double clicked my java application I need to run my app smoothly without any database errors. I cannot do this because postgreSQL is not running as a windows service.
I found this in windows event viewer:
The description for Event ID 0 from source PostgreSQL cannot be found.
Either the component that raises this event is not installed on your local computer or the installation is corrupted.
You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory
I googled about it but I was not able to find an answer.
Problem was solved
path to the data directory was wrong in windows service file.
So I delete the service file from this method:
1)Run Regedit or Regedt32.
2)Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
3)Look for the postgreSQL service that you want delete and delete it.
4)reboot the computer.
After that open the cmd (Run as administrator) Go to the postgreSQL bin directory and run this command to create a new windows service:
pg_ctl.exe register -N "PostgreSQL" -U "NT AUTHORITY\NetworkService" -D "C:/Program Files/postgresql/pgsql/bin/pgsql/data" -w
This worked for me. Hope this will help.
This is a note for a normal user. If using an official installer it should has a build-in service,
Win+R and type services.msc
Search Postgres service based on the version installed,
e.g., "postgresql-x64-13 - PostgreSQL Server 13"
Click stop, start, or restart the service option
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or
directory
This looks like your working directory is C:\Windows\system32 and you are running postgres there and it looks for data/postgresql.conf.
Try changing the working directory or specifying -D C:\path\to\my\data.