问题
I'm trying to start graphhopper using pm2
... graphhopper
is a java application and the way I initiate it on the terminal is by going to its folder and entering the following command:
java -jar matching-web/target/graphhopper-map-matching-web-1.0-SNAPSHOT.jar server config.yml
This application works fine running from the command line, but I haven't succeeded on running it as a service with pm2
. The config file I'm using is this one (pm2 start config.json
):
{
"apps":[
{
"name":"graphhopper",
"cwd":".",
"script":"/usr/bin/java",
"args":[
"-jar",
"/home/myyser/graphhopper/map-matching/matching-web/target/graphhopper-map-matching-web-1.0-SNAPSHOT.jar",
"server",
"config.yml"
],
"log_date_format":"YYYY-MM-DD HH:mm Z",
"exec_interpreter":"",
"exec_mode":"fork"
}
]
}
I'm 100% sure that what I'm getting wrong here is the way I'm writing the "server", "config.yml"
parameters... Looking into pm2 logs graphhopper
I can see that those parameters are not being recognized at all... I've tried to tweak the way it's done as well but I didn't manage to figure out the right solution. I know how to start a java application using pm2
with no parameters. But how can I do it with a java application that has parameters as in the case of graphhopper
?
回答1:
As stated in the comments, this issue can be solved by creating a bash script and running it with pm2
instead of running directly the java application... The bash script used was the file graphhopper.sh
as the following:
#!/bin/bash
java -jar matching-web/target/graphhopper-map-matching-web-1.0-SNAPSHOT.jar server config.yml
And to start it as a service with pm2
:
pm2 start graphhopper.sh --name=graphhopper
回答2:
You can also run a fat jar directly in pm2 - use two dashes to separate the command args:
pm2 start java -- -jar matching-web/target/graphhopper-map-matching-web-1.0-SNAPSHOT.jar server config.yml
来源:https://stackoverflow.com/questions/63122472/how-can-i-start-a-java-application-with-parameters-using-a-pm2-config-file