Can we use pm2 for java? If yes can you provide a working example?
I think it's specifically for node.js based applications.
it does say we can run any executable and its not restricted to nodejs. The docs says it supports ruby, python, bash etc
I am using a shell script to launch the java process, but it is not stopping the java process when i stop the shell script. Help!
Can you post a sample?
{
"apps" : [
{
"name" : "app-x",
"cwd" : "/sit3/apps/connectors/app-x",
"args" : "",
"script" : "run.sh",
"node_args" : [],
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"error_file" : "/sit3/app-x/log/app-x.stderr.log",
"out_file" : "/sit3/app-x/log/app-x.stdout.log",
"pid_file" : "/sit3/app-x/pids/app-x.pid",
"instances" : 1,
"watch" : false,
"merge_logs" : true,
"exec_interpreter" : "bash",
"exec_mode" : "fork"
}
That would be something I could use. We're already using pm2 for our node apps, it would be really nice to use it for .jars as well (uberjar generated from Clojure/leiningen in fact). Or is it something that should be done via bash scripts ? (and if so I'd happy to get pointers on how to do so).
Thanks !
I finally got this to work by making the interpreter as none and then composing the java command line by doing the following. I gave the cwd as the directory where java is running, and the script as java and then in the args all the class path options and arguments for the java class.
So now I am able to start a java process from pm2. I am able to stop it as well.
Issue now is that, when I run pm2 start javaagent after a pm2 stop java agent, it seems to be missing the env variables that was set. Can someone with knowledge of PM2 help?
thanks
@nha if the above description doesn't help, let me know, I can send you the process.json file that we created.
@zalym That would really help thank you.
Here you go
{
"apps": [{
"name": "JavaAgent",
"cwd": "/usr/bin",
"args": [
"-Xmx256m",
"-cp",
"/app/somedirectorywhereagentresides:/some/directory/where/your/classes/lives",
"your.main.class"
],
"env": {
"ANY_ENV_VARIABLE": "that you might need in your program"
},
"script": "java",
"node_args": [],
"log_date_format": "YYYY-MM-DD HH:mm Z",
"exec_interpreter": "none",
"exec_mode": "fork"
}
]
}
@zalym Thanks a lot !
_Edit_ : I can confirm it works.
@zalym Thanks!
@zalym I am looking for the way to us pm2 to start and stop java with springboot. Could you show me an example of JavaAgent in /app/somedirectorywhereagentresides? @nha As you confirm it worked, could you help me ?
JavaAgent as specified in the name is just the name pm2 looks for when you use the command line tools.
Taken from the docs:
application name (default to script filename without extension)
And use it like
pm2 start process.json --only JavaAgent
@ren28997 how do you start your spring boot application?
@zalym couldn't you do what pm2 does with Linux upstart? Running a java JAR as a daemon in Linux is fairly easy and upstart will ensure it is always running.
I am sure there are other tools out there which provides similar functionality. using pm2 for java is kind of laboured way of doing it. but for my use case, it worked well where I had a bunch of node js applications and few java processes. it helped to have one process manager to rule them all.
https://github.com/Unitech/PM2/issues/1507#issuecomment-140730679 by @zalym works for me, too. Thanks!
Close the issue?
Yea!
Thx n Regards
Saleem
On Fri, Sep 2, 2016 at 5:26 AM -0400, "Steven Wüthrich" [email protected] wrote:
Close the issue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
I think you should use nohup linux command ---- :D
check this:
anybody that can help me with a process.json file to work on pm2 please :(
Most helpful comment
Here you go