Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scala implementation #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ $ sudo journalctl -f -u isu-node

などで見ることができます。

#### Scalaへの切り替え方

起動する実装をScala(Play 2.6)に切り替えるには、以下の操作を行います。

```
$ sudo systemctl stop isu-ruby
$ sudo systemctl start isu-scala
```

プログラムの詳しい起動方法は、 /etc/systemd/system/isu-scala.service を参照してください。

エラーなどの出力については、

```
$ sudo journalctl -f -u isu-scala
```

などで見ることができます。

### MySQL

3306番ポートでMySQLが起動しています。初期状態では以下のユーザが設定されています。
Expand Down
32 changes: 32 additions & 0 deletions provisioning/image/ansible/04_xbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,35 @@
copy: src=../files/etc/php/7.0/fpm/pool.d/www.conf dest=/etc/php/7.0/fpm/pool.d/www.conf owner=root mode=644
- name: stop php-fpm
service: name=php7.0-fpm state=stopped enabled=yes

# install java8 and sbt
- hosts: guests:extras
become: yes
gather_facts: no
tasks:
- name: Apt add bintray and jessie-backports
apt_repository: repo="{{item}}"
with_items:
- deb http://http.debian.net/debian jessie-backports main
- deb https://dl.bintray.com/sbt/debian /
tags: sbt
- name: Apt add key
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: 2EE0EA64E40A89B84B2DF73499E82A75642AC823
tags: sbt
- name: Install jre
apt:
update_cache: yes
default_release: jessie-backports
name: "{{item}}"
with_items:
- openjdk-8-jre-headless
- ca-certificates-java
tags: sbt
- name: Install jdk and sbt
apt: name="{{item}}"
with_items:
- openjdk-8-jdk
- sbt
tags: sbt
10 changes: 10 additions & 0 deletions provisioning/image/ansible/07_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
- name: npm install
shell: cd /home/isucon/private_isu/webapp/node; bash -lc "npm install"

- hosts: guests:extras
become: yes
become_user: isucon
gather_facts: no
tasks:
- name: build Play app
shell: cd /home/isucon/private_isu/webapp/scala; bash -lc "./setup.sh"

- hosts: guests:extras
become: yes
tasks:
Expand All @@ -44,5 +52,7 @@
copy: src=../files/etc/systemd/system/isu-go.service dest=/etc/systemd/system/isu-go.service owner=root mode=644
- name: node app (systemd)
copy: src=../files/etc/systemd/system/isu-node.service dest=/etc/systemd/system/isu-node.service owner=root mode=644
- name: scala app (systemd)
copy: src=../files/etc/systemd/system/isu-scala.service dest=/etc/systemd/system/isu-scala.service owner=root mode=644
- name: default application selection
service: name=isu-ruby state=running enabled=true
17 changes: 17 additions & 0 deletions provisioning/image/files/etc/systemd/system/isu-scala.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=isu-scala
After=syslog.target

[Service]
WorkingDirectory=/home/isucon/private_isu/webapp/scala
EnvironmentFile=/home/isucon/env.sh
SuccessExitStatus=143

User=isucon
Group=isucon
ExecStart=/home/isucon/private_isu/webapp/scala/target/universal/stage/bin/private-isu -J-server -J-Xmx512M -Dhttp.port=8080 -Duser.timezone=Asia/Tokyo
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s USR2 $MAINPID

[Install]
WantedBy=multi-user.target
8 changes: 8 additions & 0 deletions webapp/scala/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
logs
target
/.idea
/.idea_modules
/.classpath
/.project
/.settings
/RUNNING_PID
36 changes: 36 additions & 0 deletions webapp/scala/app/controllers/AssetsController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package controllers

import java.io._
import javax.inject.Inject

import play.api._
import play.api.http.FileMimeTypes
import play.api.mvc._

import scala.concurrent.{ ExecutionContext, Future }

/**
* Stolen from controllers.ExternalAssets
*/
class AssetsController @Inject() (environment: Environment)(implicit ec: ExecutionContext, fileMimeTypes: FileMimeTypes)
extends ControllerHelpers {

private val rootPath = sys.props.getOrElse("isu.public.dir", "/home/isucon/private_isu/webapp/public")

private val Action = new ActionBuilder.IgnoringBody()(_root_.controllers.Execution.trampoline)

def at(file: String): Action[AnyContent] = Action.async { request =>
Future {

val fileToServe = new File(rootPath, file)

if (fileToServe.exists) {
Ok.sendFile(fileToServe, inline = true).withHeaders(CACHE_CONTROL -> "max-age=3600")
} else {
NotFound
}

}
}

}
Loading