Play2.0ã®target/startã¨ãã®åæ¢æ¹æ³ã«ã¤ãã¦èª¿ã¹ããã¨
è©ä¾¡/æ¬çªç°å¢ã¸ãããã¤ããéç¨ã§èª¿ã¹ããã¨ã«ã¤ãã¦æ¸ãã¾ãã
- ããã¯ã°ã©ã¦ã³ãã§Playãèµ·åãã(target/start)
- èµ·åæã«DBè¨å®ãªã©ãæå®ãã
- target/startã§èµ·åãããµã¼ãã¼ãåæ¢ãã
ç°å¢
- Play2.0.4
- Scala2.9.2
ããã¯ã°ã©ã¦ã³ãã§Playãèµ·åãã(target/start)
Playãèµ·åããã«ã¯ããã¤ãã®ã³ãã³ããããã¾ãã
こちらãã説æãå¼ç¨ãã¾ãã
play run
run ã³ãã³ãã¯éçºã¢ã¼ãã®ããã ãã«ç¨æããããã®ãªã®ã§ãæ¬çªç°å¢ã§ã¯çµ¶å¯¾ã«å©ç¨ããªãã§ãã ãããéçºã¢ã¼ãã®å ´åããªã¯ã¨ã¹ãæ¯ã« sbt ãå ¨ã¦ã®ã½ã¼ã¹ãã¡ã¤ã«ã®æ´æ°ãã§ãã¯ãè¡ã£ã¦ãã¾ãã¾ãã
ãã®çç±ããããããã¤ã³ãã³ãã¨ãã¦runã¯ä¸é©åã§ãã
play start
詳細ã¯å ã®ãªã³ã¯ãè¦ã¦é ããã¨ã«ãã¦ãåé¡ã¨ãªãã®ã¯æ¬¡ã®é¨åã
ããã»ã¹ãåãé¢ãããã« Ctrl+D ãå¿ è¦ã ã¨ãããã¨
Ctrl+Dã§ããã»ã¹ãåãé¢ãã¦ããµã¼ãã¼ã¯çãç¶ãã¾ããã
æä½æ¥ãå¿
è¦ã«ãªãã®ã¯ããããããã¾ããã
ããã§ã次ã®target/startã使ããã¨ã«ãªãã¾ãã
target/start
ã¾ããplay clean compile stageããå®è¡ãã¾ãããsbt clean compile stageãã§ãæ§ãã¾ããã
ããããã¨ä»¥ä¸ã®ãã®ãä½ããã¾ãã
- target/stagedãã£ã¬ã¯ããªã¨ã³ã³ãã¤ã«ãããã¢ã¸ã¥ã¼ã«
- target/startã¨ããèµ·åã³ãã³ã
ãããããtarget/startãã§èµ·ååºæ¥ã¾ãã
ãããããã«ããã¯ã°ã©ã¦ã³ãã§èµ·åããã«ã¯æ¬¡ã®ããã«ãã¾ãã
$ ./target/start >/dev/null 2>&1 &
èµ·åæã«DBè¨å®ãªã©ãæå®ãã
./target/startãè¦ãã¨åããã¾ãããä¸èº«ã¯ãã ã®javaã³ãã³ãå¼ã³åºãã§ãã
ãã®ããã-Dãªãã·ã§ã³ãç¨ããã°ã·ã¹ãã ããããã£ãæå®ãããã¨ãã§ãã¾ãã
ä¾ãã°ä»¥ä¸ã®ãããªè¨å®ãã§ãã¾ãã
é ç® | ããããã£å | ä¾ |
---|---|---|
èµ·åæã®PIDãã¡ã¤ã«åºåå | pidfile.path | -Dpidfile.path=/tmp/play_pid |
HTTPãã¼ã | http.port | -Dhttp.port=8888 |
HTTPã¢ãã¬ã¹ | http.address | -Dhttp.address=192.x.x.x |
DBãã©ã¤ã | db.default.driver | -Ddb.default.driver=com.mysql.jdbc.Driver |
DBã®URL | db.default.url | -Ddb.default.url=jdbc:mysql://localhost/sample |
DBã¦ã¼ã¶ã¼ | db.default.user | -Ddb.default.user=hoge |
DBãã¹ã¯ã¼ã | db.default.password | -Ddb.default.password=passpass |
target/startã§èµ·åãããµã¼ãã¼ãåæ¢ãã
ããã¾ã§ã®è¨å®ã§èµ·åã¾ã§ã¯åºæ¥ã¾ããããåæ¢ã¯ã©ãããã°ããã§ããããã
2ã¤ã®ã¢ããã¼ããããã¾ãã
1. PIDæå®ãã¦kill
å ã»ã©ã®ãªã³ã¯ã«ã¯æ¬¡ã®ããã«æ¸ããã¦ãã¾ãã
ãµã¼ãã®èµ·åæã«ã¯ãµã¼ãã®ããã»ã¹ ID ã表示ãããã¨åæã«ã RUNNING_PID ã¨ãããã¡ã¤ã«ã«æ¸ãè¾¼ã¾ãã¾ããèµ·åä¸ã® Play ãµã¼ããåæ¢ãããããã«ã¯ãåã«ãã®ããã»ã¹ã« SIGTERM ã·ã°ãã«ãéä¿¡ãã¦ã¢ããªã±ã¼ã·ã§ã³ãçµäºããã°ããã§ãããã
説æã¯ãplay startãé
ã«æ¸ããã¦ãããã®ã§ãããRUNNING_PIDãçæãããã®ã¯ãtarget/startãã§ãåãã§ãã
(â»-Dpidfile.pathã§æå®ãã¦ããã°RUNNING_PIDã§ã¯ãªãã¦ãã®ãã¡ã¤ã«åã¨ãªã)
ã¨ããã¨ãRUNNING_PIDã«æ¸ããã¦ããPIDã使ã£ã¦killãããããªãã®ã§ããããã
å
¬å¼ã®Wikiã§ããæ¸ããã¦ããã®ã§ãéæ¨å¥¨ãªæ¹æ³ã¨ããããã§ã¯ãªãããã§ãã
2. play stop
ãplay stopãã¨ããã³ãã³ããããã¾ãããããå®è¡ãã¦ãä¸è¨1ã¨åãçµæã«ãªãã¾ãã
ãªãããplay stopãã¯é常ã®ã³ã³ã½ã¼ã«ããå®è¡ãã¾ãã
playã³ã³ã½ã¼ã«ã«ã¯stopã¨ããã³ãã³ãã¯ããã¾ããã
ã¨ããã§play stopã¯å
é¨çã«ä½ããã¦ããã®ã§ãããã
https://github.com/playframework/Play20/blob/2.0.4/playãè¦ãã¨ãçµå±ä¸è¨1ã¨åããã¨ã ã¨åããã¾ãã
RUNNING_PIDããPIDãåå¾ãã¦killãã¦ããã ãã§ãã
if test "$1" = "stop"; then if [ -f RUNNING_PID ]; then echo "[info] Stopping application (with PID `cat RUNNING_PID`)..." kill `cat RUNNING_PID` RESULT=$? if test "$RESULT" = 0; then echo "[info] Done!" exit 0 else echo "[\033[31merror\033[0m] Failed ($RESULT)" exit $RESULT fi else echo "[\033[31merror\033[0m] No RUNNING_PID file. Is this application running?" exit 1 fi fi
â»ã³ã¼ãããåããããã«ãã¡ã¤ã«ãã¹ããRUNNING_PIDãã¨ããã¹ãæ¸ãã®ããã-Dpidfile.pathã§å¥ãã¹æå®ã«ãã¦ããã¨æ£å¸¸ã«åãã¾ããã
ããã§ã¡ãã£ã¨ããçåãæµ®ãã³ã¾ãã
ãkillã§æ¥ã«è½ã¨ãããã·ã¹ãã ä¸æ´åã«ãªããããªããããã
ããã«é¢ãã¦ã¯ã2.0.3ãå¢ã«å°ãç°ãªãã¾ãã
play.core.server.NettyServerã®createServerã¡ã½ããã«ãã£ã¦ãµã¼ãã¼ãç«ã¡ä¸ããã¾ãã®ã§ã
ããã®ã³ã¼ããè¦ã¦ã¿ã¾ãã
ã¾ãã¯2.0.4ããã
try { val server = new NettyServer( new StaticApplication(applicationPath), Option(System.getProperty("http.port")).map(Integer.parseInt(_)).getOrElse(9000), Option(System.getProperty("http.address")).getOrElse("0.0.0.0")) Runtime.getRuntime.addShutdownHook(new Thread { override def run { server.stop() } }) Some(server) } catch { case e => { println("Oops, cannot start the server.") e.printStackTrace() None } }
Runtime.getRuntime.addShutdownHookã«å¦çãç»é²ããã¦ãã¾ãã
addShutdownHookã¯JVMçµäºæã«ããã¯ãããå¦çã追å ãããã®ã§ãã
åèï¼FIO14-J. プログラムの終了時には適切なクリーンアップを行う
åèï¼Runtime (Java Platform SE 6)
ããã§NettyServerã®stopãå¼ã°ãã¦ãã¾ãã
stopã¡ã½ããã§ã¯Playã®stopãå¼ãã ããã®ä»ã¯ãã¼ãºå¦çãè¡ãã¾ãã
ãªã®ã§ããaddShutdownHookãåãã¦ãããã°ã大ä¸å¤«ããããªã¨æãã¾ãã
ãã ãJavadocã«ããããã«ãä¿è¨¼ã¯ãããªããã®ãã¡ãã£ã¨å¿é
ã
ã¾ããªã±ã¼ã¹ã¨ãã¦ãä»®æ³ãã·ã³ããç°å¸¸çµäºããããã¨ãããã¾ã
(ç¥)
ãã¨ãã°ãUnix ã®å ´åã® SIGKILL ã·ã°ãã«ã¾ãã¯ãMicrosoft Windows ã®å ´åã® TerminateProcess ã®å¼ã³åºãããã®ä¾ã§ãã
(ç¥)
ä»®æ³ãã·ã³ãç°å¸¸çµäºããã¨ã·ã£ãããã¦ã³ããã¯ã®å®è¡ã¯ä¿è¨¼ã§ãã¾ããã
ç°¡åãªã³ã¼ãã§ç¢ºèªãã¦ã¿ã¾ãããã確ãã«ãkill {pid}ãã§æ®ºãã¦ãã¡ããã¨ããã¯ãåãã¦ã¾ããã
ãã ãkill -KILL {pid}ãã§ã¯ããã¯åãã¾ããã§ããã
ã¾ããplay stopãã¯ãã ã®ãkill {pid}ãã ãã大ä¸å¤«ã
ããã¦ãã®addShutdownHookã¯2.0.3ã§è¿½å ããããã®ã§ãã®ã§ã2.0.2以åã¯å¯¾å¿ãã¦ãã¾ããã
以ä¸ã¯2.0.2ã®createServerã®åãå¦çé¨åã§ãã
try { Some(new NettyServer( new StaticApplication(applicationPath), Option(System.getProperty("http.port")).map(Integer.parseInt(_)).getOrElse(9000), Option(System.getProperty("http.address")).getOrElse("0.0.0.0"))) } catch { case e => { println("Oops, cannot start the server.") e.printStackTrace() None } }
é¢é£ãã話é¡ãå¤æ´å±¥æ´ã¯ãã®è¾ºã§ãã
Google グループ
merge fix Global.onStop is not called when netty exists · 3525058 · playframework/Play20 · GitHub