New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm2 for java - Shell script launching java process, stop doesn't stop the java process #1507

Closed
zalym opened this Issue Aug 7, 2015 · 20 comments

Comments

9 participants
@zalym

zalym commented Aug 7, 2015

Can we use pm2 for java? If yes can you provide a working example?

@pruhstal

This comment has been minimized.

pruhstal commented Aug 7, 2015

I think it's specifically for node.js based applications.

@zalym

This comment has been minimized.

zalym commented Aug 7, 2015

it does say we can run any executable and its not restricted to nodejs. The docs says it supports ruby, python, bash etc

@zalym

This comment has been minimized.

zalym commented Aug 7, 2015

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!

@pruhstal

This comment has been minimized.

pruhstal commented Aug 8, 2015

Can you post a sample?

@zalym

This comment has been minimized.

zalym commented Aug 8, 2015

{
"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"
}

@zalym zalym changed the title from pm2 for java to pm2 for java - Shell script launching java process, stop doesn't stop the java process Aug 23, 2015

@nha

This comment has been minimized.

nha commented Sep 3, 2015

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 !

@zalym

This comment has been minimized.

zalym commented Sep 14, 2015

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

@zalym

This comment has been minimized.

zalym commented Sep 14, 2015

@nha if the above description doesn't help, let me know, I can send you the process.json file that we created.

@nha

This comment has been minimized.

nha commented Sep 14, 2015

@zalym That would really help thank you.

@zalym

This comment has been minimized.

zalym commented Sep 16, 2015

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"
        }
    ]
}
@nha

This comment has been minimized.

nha commented Sep 16, 2015

@zalym Thanks a lot !
Edit : I can confirm it works.

@zalym zalym closed this Oct 24, 2015

@slavaGanzin

This comment has been minimized.

slavaGanzin commented Feb 18, 2016

@zalym Thanks!

@ren28997

This comment has been minimized.

ren28997 commented Feb 24, 2016

@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 ?

@abacaj

This comment has been minimized.

abacaj commented May 20, 2016

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

@zalym

This comment has been minimized.

zalym commented May 20, 2016

@ren28997 how do you start your spring boot application?

@abacaj

This comment has been minimized.

abacaj commented May 20, 2016

@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.

@zalym

This comment has been minimized.

zalym commented May 20, 2016

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.

@bacbos

This comment has been minimized.

bacbos commented Sep 2, 2016

#1507 (comment) by @zalym works for me, too. Thanks!

Close the issue?

@zalym

This comment has been minimized.

zalym commented Sep 3, 2016

Yea!

Thx n Regards
Saleem

On Fri, Sep 2, 2016 at 5:26 AM -0400, "Steven Wüthrich" notifications@github.com wrote:

#1507 (comment) by @zalym works for me, too. Thanks!

Close the issue?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@mitraxsou

This comment has been minimized.

mitraxsou commented Aug 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment