Play 2.2 application crashes on Heroku

我与影子孤独终老i 提交于 2019-12-23 07:47:12

问题


After moving from Play 2.0.4 to Play 2.2.0 I get this error when deploying on Heroku:

Oct 15 13:23:12 heroku/web.1: Starting process with command `target/universal/stage/bin/demagog -Dhttp.port=${PORT} ${JAVA_OPTS} -Dconfig.resource=${DEMAGOG_ENVIRONMENT}.conf`
Oct 15 13:23:13 app/web.1: Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true -Djava.rmi.server.useCodebaseOnly=true
Oct 15 13:23:13 app/web.1: Bad application path: -Xmx384m
Oct 15 13:23:15 heroku/web.1: State changed from starting to crashed
Oct 15 13:23:15 heroku/web.1: Process exited with status 0
Oct 15 13:24:37 heroku/web.1: Starting process with command `target/universal/stage/bin/demagog -Dhttp.port=${PORT} -Dconfig.resource=${DEMAGOG_ENVIRONMENT}.conf`
Oct 15 13:24:37 app/web.1: Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true -Djava.rmi.server.useCodebaseOnly=true
Oct 15 13:24:37 app/web.1: Play server process ID is 2
Oct 15 13:24:37 app/web.1: Oops, cannot start the server.
Oct 15 13:24:37 app/web.1: java.lang.IllegalStateException: System property demagog.defaultUser must be set. 

I don't understand this message

Bad application path: -Xmx384m

The second problem I can see is that my Play application can't found system property 'demagog.defaultUser', but this property is set in JAVA_OPTS environment variable. So it should work. Maybe it's just a consequence of the above problem? Any hints?


UPDATED

I have removed ${JAVA_OPTS} from the Procfile as @jan suggested. The first error

Bad application path: -Xmx384m

is not here anymore, but the system property 'demagog.defaultUser' is still not set.

Oct 16 10:50:35 heroku/web.1: Starting process with command `target/universal/stage/bin/demagog -Dhttp.port=${PORT} -Dconfig.resource=${DEMAGOG_ENVIRONMENT}.conf`
Oct 16 10:50:35 app/web.1: Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true -Djava.rmi.server.useCodebaseOnly=true
Oct 16 10:50:35 app/web.1: Play server process ID is 2
Oct 16 10:50:35 app/web.1: Oops, cannot start the server.
Oct 16 10:50:35 app/web.1: java.lang.IllegalStateException: System property demagog.defaultUser must be set.
...
Oct 16 10:50:35 app/web.1: at play.api.Play$.start(Play.scala:87)
Oct 16 10:50:35 app/web.1: at play.core.StaticApplication.<init>(ApplicationProvider.scala:52)
Oct 16 10:50:35 app/web.1: at play.core.server.NettyServer$.createServer(NettyServer.scala:243)
Oct 16 10:50:35 app/web.1: at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:279)
Oct 16 10:50:35 app/web.1: at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:274)
Oct 16 10:50:35 app/web.1: at scala.Option.map(Option.scala:145)
Oct 16 10:50:35 app/web.1: at play.core.server.NettyServer$.main(NettyServer.scala:274)
Oct 16 10:50:35 app/web.1: at play.core.server.NettyServer.main(NettyServer.scala)
Oct 16 10:50:35 heroku/web.1: Process exited with status 255 

when I run heroku command

heroku config

I can see the system property is included in the JAVA_OPTS environment variable

JAVA_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops -Ddemagog.defaultUser=xxx ...

回答1:


You probably haven't removed ${JAVA_OPTS} from your Procfile. With Play 2.2 the JAVA_OPTS are included in the generated start script so you don't have to include them in the Procfile anymore.

What happens then is that the start script tries to interpret your JAVA_OPTS as app parameters.




回答2:


Ok, I finally found it. The problem with setting my system property using environment variable JAVA_OPTS is that:

Environment variables are case sensitive in Unix while case insensitive in Windows.

with combination that the script generated by the sbt-native-packager reads java_opts environment variable. So you have to set java_opts (lower case) environment variable within Heroku.




回答3:


answer to the update: i do not know exactly what the problem is now. i would suggest to set the default user via the application.config. that'll be more play like anyways.

in your application.conf it could for example look

demagog.defaultUser="SOME_STD_DEFAULT_USER"
demagog.defaultUser=${?DEMAGOG_DEFAULTUSER}

then you can set the system specific variable via something like

heroku config:add DEMAGOG_DEFAULTUSER="yourdefaultuser"


来源:https://stackoverflow.com/questions/19391014/play-2-2-application-crashes-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!