用pm2运行播放scala应用程序 [英] Run play scala application with pm2

查看:182
本文介绍了用pm2运行播放scala应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在我们的UNIX服务器上部署 Play / Scala 应用程序运行可执行文件,像

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

它工作正常。然而,对于我的NodeJS应用程序,我使用 pm2 ,我非常感谢它的易用性和监控选项,因此想要使用它的其他应用程序。



这个线程声称可以运行JAR。任何关于如何调整conf(见下文)的想法,以使其与Play / Scala应用程序一起使用,并且是否可以实现?



运行带有pm2的jar :

  {
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您可能需要在程序

script:java,
node_args:[],
log_date_format:YYYY-MM-DD HH:mm Z,
exec_interpreter:none,
exec_mode:fork
}
]
}


解决方案

这是我项目的一个工作示例。首先,您需要使用命令activation dist来准备项目。它使独立版本并压缩到.ZIP文件。


  1. 在项目目录中运行activ dist


  2. 将文件从.zip提取到目录中(例如/ var / WWW / yourproject)。

  3. 创建yourapp.json文件并将以下代码放入此文件中:




  {
apps:[{
name:NameInPM2List,
cwd:/ path / to /你的/项目,
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. 使用命令 pm2 start /path/to/json/file/yourapp.json

这就是全部。


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

解决方案

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.

这篇关于用pm2运行播放scala应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆