Run play scala application with pm2

2019-04-11 09:34发布

We have been deploying Play/Scala application on our UNIX server by just running the executable, something like

java_opts="-Xms128M -Xmx512M" ./bin/myProject -Dconfig.file=/path/to/my/confFile.conf -Dhttp.port=9022 &

and it works fine. However, for my NodeJS applications I use pm2 and I really appreciate its ease of use as well as monitoring options and hence would like to use it for the other apps too.

This thread claims it is possible to run JARs. Any idea on how to adapt the conf (see below) for it to work with my Play/scala apps and if it is possible at all?

Running a Jar with pm2:

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

2条回答
神经病院院长
2楼-- · 2019-04-11 10:17

Try putting your command line args under "args".
Put your conf and lib directories on classpath.
The bootstrap class for Play is play.core.server.NettyServer.

查看更多
Deceive 欺骗
3楼-- · 2019-04-11 10:26

Here is a working example from my project. First you need to prepare your project with command "activator dist". It makes standalone version and compress it to .ZIP file.

  1. In project directory run "activator dist"
  2. If command finished success - look at path where will be located .zip file with your project.
  3. Extract files from .zip into directory (for example /var/www/yourproject).
  4. create yourapp.json file and put following code to this file:
{
    "apps": [{
            "name": "NameInPM2List",
            "cwd": "/path/to/your/project",
            "args": [
                "-Duser.dir=/path/to/your/project",
                "-Dhttp.address=127.0.0.1",
                "-Dhttp.port=9000",
                "-cp",
                "/path/to/your/project/lib/*",
                "play.core.server.ProdServerStart"
            ],
            "script": "/usr/bin/java",
            "node_args": [],
            "log_date_format": "YYYY-MM-DD HH:mm Z",
            "exec_interpreter": "none",
            "exec_mode": "fork"
        }
    ]
}
  1. run your project with command "pm2 start /path/to/json/file/yourapp.json"

That's all.

查看更多
登录 后发表回答