I am running an executable jar using the command prompt. But after command prompt closing the execution is stopped. I need to run this permanently. Because this is a microservice.
How can I achieve this goal
I am running using java -jar JARPATH
There are several options:
1) Creating a service as was mentioned in the first answer and comment.
2) Run a process in the background.
nohup java -jar my-service.jar &
Where nohup command enables a process to continue running in the background when a user exits a shell.
To terminate the service, you need to kill the process.
You can create a run-script writing PID to a variable (or a text file):
#!/bin/bash
my-service &
export SERVICE_PID=$!
And kill the PID in stop-script:
#!/bin/bash
kill -9 $SERVICE_PID
3) Run process in a container, e.g. Docker
Running process in container allows has some advantages and allows to manage many different options rather than just 'run-and-stop'.
Simply create a service to invoke jar file. Services can run indefinitely and can be triggered at startup or can be started or stopped manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With