2016年2月11日木曜日

Play! 2.4.4 + Scala 2.11.6 バイナリ、Jar、warファイルを生成する

  • このエントリーをはてなブックマークに追加


最近、Play 2.4.4 + Scala 2.11.6でプログラムを書いていて、アプリのデプロイ方法色々調べてたので、binary, jar, war ファイルの方法をご紹介します。

バイナリファイル

これは推奨されるやり方だそうです。javaさえインストールしていればそのまま実行できます。
構成ファイルbuild.sbtやplugin.sbtファイルに特別な設定入れなくても大丈夫です。
プロジェクトフォルダ(myApp)に入って、activator distを実行する
PS C:\myApp> .\activator dist
image_thumb3
これで. C:\myApp\target\universal\myapp-1.0-SNAPSHOT.zip ファイルが生成される。
zipファイルを解凍して、以下のようなフォルダ構造になります。
image_thumb5
bin フォルダの下に、2つの実行ファイルがあります。myappはLinux版、myapp.batはWindows版になります。
image_thumb7
ファイルを実行する
C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp 
デフォルトポート9000を他のポートに変更することもできます。
C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp “-Dhttp.port=8080”
※注意:ダブルクオーテーションが必要です。ない場合は、以下の様なエラーが表示される
PS C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp -Dhttp.port=80 Bad root server path: C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin\8080
image_thumb9

JARファイル

Jarを生成する場合は、sbt-assemblyプラグインが必要です。
build.sbtファイルに以下のコードを追記する。
//configuration for activator assembly : start
import AssemblyKeys._
assemblySettings
mainClass in assembly := Some("play.core.server.NettyServer")
fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value)
//skip test test in assembly := {}
jarName in assembly := "myApp.1.0-SNAPSHOT.jar"
mergeStrategy in assembly := {   case PathList("javax", "servlet", xs @ _*)         => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".properties" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".xml" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".types" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".class" => MergeStrategy.first   case "application.conf"                            => MergeStrategy.concat   case "unwanted.txt"                                => MergeStrategy.discard   case x =>     val oldStrategy = (mergeStrategy in assembly).value     oldStrategy(x) }
//configuration for activator assembly : end
......
project/plugins.sbtに以下を追記する
//configuration for activator assembly
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") 
バージョンを0.11.2にしてますが、sbtのバージョンに合わせる必要です。以下をご参照ください。
https://github.com/sbt/sbt-assembly/tree/0.11.2

activator assemblyを実行する
PS C:\myApp> .\activator assembly[info] Loading project definition from C:\myApp\project
[info] Set current project to myApp (in build file:/C:/myApp/)
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript asse
ts compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Including from cache: play-cache_2.11-2.4.6.jar
[info] Including from cache: xml-apis-1.4.01.jar
[info] Including from cache: ehcache-core.jar
[info] Including from cache: jta-1.1.jar
[info] Including from cache: play-ws_2.11-2.4.6.jar
[info] Including from cache: scala-library.jar
[info] Including from cache: guice.jar
[info] Including from cache: twirl-api_2.11.jar
[info] Including from cache: scala-reflect-2.11.6.jar
[info] Including from cache: jackson-core.jar
[info] Including from cache: commons-lang3.jar
[info] Including from cache: jackson-annotations.jar
[info] Including from cache: guava.jar
[info] Including from cache: javax.inject.jar
[info] Including from cache: aopalliance.jar
[info] Including from cache: jackson-databind.jar
[info] Including from cache: scala-xml_2.11-1.0.1.jar
[info] Including from cache: jackson-datatype-jdk8.jar
[info] Including from cache: play-server_2.11-2.4.6.jar
[info] Including from cache: async-http-client.jar
[info] Including from cache: signpost-core-1.2.1.2.jar
[info] Including from cache: guice-assistedinject.jar
[info] Including from cache: play_2.11-2.4.6.jar
[info] Including from cache: play-netty-server_2.11-2.4.6.jar
[info] Including from cache: netty.jar
[info] Including from cache: jackson-datatype-jsr310.jar
[info] Including from cache: build-link-2.4.6.jar
[info] Including from cache: play-exceptions-2.4.6.jar
[info] Including from cache: play-netty-utils-2.4.6.jar
[info] Including from cache: signpost-commonshttp4-1.2.1.2.jar
[info] Including from cache: slf4j-api.jar
[info] Including from cache: javassist.jar
[info] Including from cache: jul-to-slf4j.jar
[info] Including from cache: netty-http-pipelining.jar
[info] Including from cache: httpcore.jar
[info] Including from cache: play2-war-core-servlet30_2.11-1.4-beta1.jar
[info] Including from cache: play-iteratees_2.11-2.4.6.jar
[info] Including from cache: httpclient.jar
[info] Including from cache: play2-war-core-common_2.11-1.4-beta1.jar
[info] Including from cache: commons-logging-1.1.1.jar
[info] Including from cache: play-jdbc_2.11-2.4.6.jar
[info] Including from cache: scala-stm_2.11-0.7.jar
[info] Including from cache: play-jdbc-api_2.11-2.4.6.jar
[info] Including from cache: mariadb-java-client-1.3.4.jar
[info] Including from cache: jcl-over-slf4j.jar
[info] Including from cache: bonecp.jar
[info] Including from cache: config.jar
[info] Including from cache: HikariCP.jar
[info] Including from cache: scala-parser-combinators_2.11-1.0.1.jar
[info] Including from cache: anorm_2.11-2.4.0.jar
[info] Including from cache: play-json_2.11-2.4.6.jar
[info] Including from cache: anorm-tokenizer_2.11-2.4.0.jar
[info] Including from cache: h2.jar
[info] Including from cache: scala-arm_2.11-1.4.jar
[info] Including from cache: logback-core.jar
[info] Including from cache: tyrex.jar
[info] Including from cache: scala-continuations-library_2.11-1.0.1.jar
[info] Including from cache: play-functional_2.11-2.4.6.jar
[info] Including from cache: play-datacommons_2.11-2.4.6.jar
[info] Including from cache: logback-classic.jar
[info] Including from cache: bootstrap-3.3.1.jar
[info] Including from cache: joda-time.jar
[info] Including from cache: jquery-1.11.1.jar
[info] Including from cache: joda-convert.jar
[info] Including: myapp_2.11-1.0-SNAPSHOT-web-assets.jar
[info] Including from cache: akka-actor_2.11.jar
[info] Including from cache: akka-slf4j_2.11.jar
[info] Including from cache: commons-codec.jar
[info] Including from cache: xercesImpl-2.11.0.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF\services\com.fasterxml.jackson.databind.Module' with strategy 'filterDistinctLines'
[warn] Merging 'META-INF\services\java.sql.Driver' with strategy 'filterDistinctLines'
[warn] Merging 'org\apache\commons\logging\Log.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogConfigurationException.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogFactory.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\NoOpLog.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog$1.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog.class' with strategy 'first'
[warn] Merging 'reference.conf' with strategy 'concat'
[warn] Strategy 'concat' was applied to a file
[warn] Strategy 'discard' was applied to 2 files
[warn] Strategy 'filterDistinctLines' was applied to 2 files
[warn] Strategy 'first' was applied to 6 files
[info] SHA-1: ed00c338faad479d3f2a17dc26844c4de9945297
[info] Packaging C:\myApp\target\scala-2.11\myApp.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 164 s, completed 2016/02/11 16:17:24
packagingが終わったら、C:\myApp\target\scala-2.11\myApp.1.0-SNAPSHOT.jar というファイルが生成され、実行できます。
PS C:\myApp\target\scala-2.11> java -jar .\myApp.1.0-SNAPSHOT.jar

WARファイル

http://terrence.logdown.com/posts/262781-play-framework-project-to-build-war-files-to-tomcat-perform
WARの場合も、build.sbtとproject/plugins.sbtを編集する必要があります。
build.sbt
……
//configuration for activator war : start import com.github.play2war.plugin._
Play2WarPlugin.play2WarSettings
//3.1 for tomcat 8,Wildfly 8, Glassfish 4, Jetty 9 //3.0 for tomcat 7,JBoss 7, JBoss EAP 6, Glassfish 3, Jetty 8 Play2WarKeys.servletVersion := "3.0"
//configuration for activator war : end
……
libraryDependencies ++= Seq(   jdbc,   cache,   ws,   specs2 % Test,   "org.mariadb.jdbc" % "mariadb-java-client" % "1.3.4",   "com.typesafe.play" %% "anorm" % "2.4.0",   "org.webjars" % "bootstrap" % "3.3.1"  //configuration for activator war )
……
project/plugins.sbt
//configuration for activator war
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.4-beta1")
https://github.com/play2war/play2-war-plugin/wiki/Configuration
プラグインのバージョン設定は上記URLをご参照ください。
activator warを実行する
PS C:\myApp> .\activator war
[info] Loading project definition from C:\myApp\project
[info] Set current project to myApp (in build file:/C:/myApp/)
[info] Wrote C:\myApp\target\scala-2.11\myapp_2.11-1.0-SNAPSHOT.pom
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript asse
ts compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Build WAR package for servlet container: 3.0
[info] Packaging C:\myApp\target\myapp-1.0-SNAPSHOT.war ...
[info] Packaging done.
[success] Total time: 3 s, completed 2016/02/11 16:45:53
targetフォルダにwarファイルが生成されて、それをtomcatなどで配置すれば実行できるはずです。

2016年2月1日月曜日

php7 memcachedインストール失敗

  • このエントリーをはてなブックマークに追加


php7の環境にmemcachedを入れようとするとエラーが出ました。バグみたい。
●libmemcachedインストール
http://libmemcached.org/libMemcached.html  からダウンロードし解凍してインストール

./configure
make
make install  (g++が必要なので、・yum install gcc-c++)
●memcachedインストール
make の時に ,以下の様なエラーが表示される
In file included from /tmp/php-memcached/php_memcached.c:26:0: 
/tmp/php-memcached/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory
#include <ext/standard/php_smart_str.h>
php7でmemcachedがまだサポートされていないみたい。失敗する
参照リンク
https://bugs.php.net/bug.php?id=71139






2015年12月26日土曜日

Ubuntu14.04にdokkuインストールしてみました

  • このエントリーをはてなブックマークに追加



ubuntu14にdokkuをインストールしてみました。dokkuは今ubuntuしか対応しないようです。
手順はすごく簡単です。社内プロキシ環境の場合は、ファイルダウンロードなど制限されている可能性もあります。その時に正常にインストール出来ないこともあります。
●install shellダウンロード。現時点で最新バージョンは0.4.6になっています。必要に応じて最新バージョンを書き換えてください。
●install shell 実行。dockerも含めてインストールしてくれます。既にdockerインストール済みの場合は、シェルの中でスキップしてくれます。
root@ubuntu14:~# sudo DOKKU_TAG=v0.4.6 bash bootstrap.sh
Preparing to install v0.4.6 from https://github.com/dokku/dokku.git...
--> Initial apt-get update
herokuish (0.3.5) を設定しています ...
Importing herokuish into docker (around 5 minutes)
--> Installing docker
2015-12-19 00:45:41 URL:https://get.docker.com/ [12865/12865] -> "-" [1]
Warning: the "docker" command appears to already exist on this system.
If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.
If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.
You may press Ctrl+C now to abort this script.
+ sleep 20
apparmor is enabled in the kernel and apparmor utils were already installed
+ sh -c apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.fGRmeFnz8G --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
gpg: 鍵2C52609Dをhkpからサーバーp80.pool.sks-keyservers.netに要求
gpg: 鍵2C52609D:“Docker Release Tool (releasedocker) <docker@docker.com>”変更なし
gpg: 処理数の合計: 1
gpg: 変更なし: 1
+ sh -c mkdir -p /etc/apt/sources.list.d
+ sh -c echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list
+ sh -c sleep 3; apt-get update; apt-get install -y -q docker-engine
無視 http://jp.archive.ubuntu.com trusty InRelease
ヒット http://jp.archive.ubuntu.com trusty-updates InRelease
ヒット http://jp.archive.ubuntu.com trusty-backports InRelease
ヒット http://jp.archive.ubuntu.com trusty Release.gpg
ヒット http://jp.archive.ubuntu.com trusty-updates/main Sources
ヒット http://jp.archive.ubuntu.com trusty-updates/restricted Sources
ヒット http://jp.archive.ubuntu.com trusty-updates/universe Sources
ヒット http://jp.archive.ubuntu.com trusty-updates/multiverse Sources
ヒット http://jp.archive.ubuntu.com trusty-updates/main amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/restricted amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/universe amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/multiverse amd64 Packages
取得:1 https://apt.dockerproject.org ubuntu-trusty InRelease
無視 https://apt.dockerproject.org ubuntu-trusty InRelease
ヒット https://apt.dockerproject.org ubuntu-trusty Release.gpg
ヒット https://apt.dockerproject.org ubuntu-trusty Release
ヒット https://apt.dockerproject.org ubuntu-trusty/main amd64 Packages
ヒット http://security.ubuntu.com trusty-security InRelease
ヒット http://jp.archive.ubuntu.com trusty-updates/main i386 Packages
ヒット https://apt.dockerproject.org ubuntu-trusty/main i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/restricted i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/universe i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/multiverse i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-updates/main Translation-en
ヒット http://jp.archive.ubuntu.com trusty-updates/multiverse Translation-en
取得:2 https://apt.dockerproject.org ubuntu-trusty/main Translation-ja_JP
ヒット http://security.ubuntu.com trusty-security/main Sources
ヒット http://jp.archive.ubuntu.com trusty-updates/restricted Translation-en
ヒット http://jp.archive.ubuntu.com trusty-updates/universe Translation-en
ヒット http://jp.archive.ubuntu.com trusty Release
ヒット http://jp.archive.ubuntu.com trusty-backports/main Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/restricted Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/universe Sources
ヒット http://security.ubuntu.com trusty-security/restricted Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/multiverse Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/main amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/restricted amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/universe amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/multiverse amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/main i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/restricted i386 Packages
ヒット http://security.ubuntu.com trusty-security/universe Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/universe i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/multiverse i386 Packages
ヒット http://jp.archive.ubuntu.com trusty-backports/main Translation-en
ヒット http://jp.archive.ubuntu.com trusty-backports/multiverse Translation-en
ヒット http://jp.archive.ubuntu.com trusty-backports/restricted Translation-en
ヒット http://security.ubuntu.com trusty-security/multiverse Sources
ヒット http://jp.archive.ubuntu.com trusty-backports/universe Translation-en
ヒット http://jp.archive.ubuntu.com trusty/main Sources
ヒット http://jp.archive.ubuntu.com trusty/restricted Sources
ヒット http://jp.archive.ubuntu.com trusty/universe Sources
ヒット http://jp.archive.ubuntu.com trusty/multiverse Sources
ヒット http://jp.archive.ubuntu.com trusty/main amd64 Packages
ヒット http://security.ubuntu.com trusty-security/main amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/restricted amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/universe amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/multiverse amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/main i386 Packages
ヒット http://jp.archive.ubuntu.com trusty/restricted i386 Packages
ヒット http://jp.archive.ubuntu.com trusty/universe i386 Packages
ヒット http://jp.archive.ubuntu.com trusty/multiverse i386 Packages
ヒット http://security.ubuntu.com trusty-security/restricted amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/main Translation-ja
ヒット https://packagecloud.io trusty InRelease
ヒット http://jp.archive.ubuntu.com trusty/main Translation-en
ヒット http://jp.archive.ubuntu.com trusty/multiverse Translation-ja
ヒット http://security.ubuntu.com trusty-security/universe amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/multiverse Translation-en
ヒット http://jp.archive.ubuntu.com trusty/restricted Translation-ja
ヒット http://jp.archive.ubuntu.com trusty/restricted Translation-en
ヒット http://jp.archive.ubuntu.com trusty/universe Translation-ja
ヒット http://security.ubuntu.com trusty-security/multiverse amd64 Packages
ヒット http://jp.archive.ubuntu.com trusty/universe Translation-en
ヒット https://packagecloud.io trusty/main amd64 Packages
ヒット http://security.ubuntu.com trusty-security/main i386 Packages
ヒット http://security.ubuntu.com trusty-security/restricted i386 Packages
無視 http://jp.archive.ubuntu.com trusty/main Translation-ja_JP
無視 http://jp.archive.ubuntu.com trusty/multiverse Translation-ja_JP
無視 http://jp.archive.ubuntu.com trusty/restricted Translation-ja_JP
ヒット https://packagecloud.io trusty/main i386 Packages
無視 http://jp.archive.ubuntu.com trusty/universe Translation-ja_JP
ヒット http://security.ubuntu.com trusty-security/universe i386 Packages
取得:3 https://packagecloud.io trusty/main Translation-ja_JP
ヒット http://security.ubuntu.com trusty-security/multiverse i386 Packages
ヒット http://security.ubuntu.com trusty-security/main Translation-en
ヒット http://security.ubuntu.com trusty-security/multiverse Translation-en
ヒット http://security.ubuntu.com trusty-security/restricted Translation-en
無視 https://apt.dockerproject.org ubuntu-trusty/main Translation-ja_JP
ヒット http://security.ubuntu.com trusty-security/universe Translation-en
無視 https://apt.dockerproject.org ubuntu-trusty/main Translation-ja
無視 https://packagecloud.io trusty/main Translation-ja_JP
無視 https://packagecloud.io trusty/main Translation-ja
無視 https://apt.dockerproject.org ubuntu-trusty/main Translation-en
無視 https://packagecloud.io trusty/main Translation-en
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます...
依存関係ツリーを作成しています...
状態情報を読み取っています...
docker-engine は既に最新バージョンです。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 87 個。
+ sh -c docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:12:04 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:12:04 UTC 2015
OS/Arch: linux/amd64
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
--> Installing dokku
2015-12-19 00:46:13 URL:https://packagecloud.io/gpg.key [3889/3889] -> "-" [1]
OK
deb https://packagecloud.io/dokku/dokku/ubuntu/ trusty main
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
dokku は既に最新バージョンです。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 87 個。
(データベースを読み込んでいます ... 現在 63603 個のファイルとディレクトリがインストールされています。)
Preparing to unpack .../software-properties-common_0.92.37.6_all.deb ...
Unpacking software-properties-common (0.92.37.6) over (0.92.37.3) ...
Preparing to unpack .../python3-software-properties_0.92.37.6_all.deb ...
Unpacking python3-software-properties (0.92.37.6) over (0.92.37.3) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
python3-software-properties (0.92.37.6) を設定しています ...
software-properties-common (0.92.37.6) を設定しています ...
gpg: 鍵輪「/tmp/tmpwcgbpwbu/secring.gpg」ができました
gpg: 鍵輪「/tmp/tmpwcgbpwbu/pubring.gpg」ができました
gpg: 鍵C300EE8Cをhkpからサーバーkeyserver.ubuntu.comに要求
gpg: /tmp/tmpwcgbpwbu/trustdb.gpg: 信用データベースができました
gpg: 鍵C300EE8C: 公開鍵“Launchpad Stable”を読み込みました
gpg: 絶対的に信用する鍵が見つかりません
gpg: 処理数の合計: 1
gpg: 読込み: 1 (RSA: 1)
OK
(データベースを読み込んでいます ... 現在 63603 個のファイルとディレクトリがインストールされています。)
Preparing to unpack .../nginx_1.8.0-1+trusty1_all.deb ...
Unpacking nginx (1.8.0-1+trusty1) over (1.4.6-1ubuntu3.3) ...
(データベースを読み込んでいます ... 現在 63601 個のファイルとディレクトリがインストールされています。)
Removing nginx-core (1.4.6-1ubuntu3.3) ...
(データベースを読み込んでいます ... 現在 63595 個のファイルとディレクトリがインストールされています。)
Preparing to unpack .../nginx-common_1.8.0-1+trusty1_all.deb ...
Moving obsolete conffile /etc/nginx/naxsi.rules out of the way...
Moving obsolete conffile /etc/nginx/naxsi_core.rules out of the way...
Moving obsolete conffile /etc/nginx/naxsi-ui.conf.1.4.1 out of the way...
Unpacking nginx-common (1.8.0-1+trusty1) over (1.4.6-1ubuntu3.3) ...
以前に未選択のパッケージ nginx-full を選択しています。
Preparing to unpack .../nginx-full_1.8.0-1+trusty1_amd64.deb ...
Unpacking nginx-full (1.8.0-1+trusty1) ...
Preparing to unpack .../bind9-host_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking bind9-host (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../dnsutils_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking dnsutils (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../libisc95_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking libisc95 (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../libdns100_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking libdns100 (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../libisccfg90_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking libisccfg90 (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../liblwres90_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking liblwres90 (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Preparing to unpack .../libbind9-90_1%3a9.9.5.dfsg-3ubuntu0.6_amd64.deb ...
Unpacking libbind9-90 (1:9.9.5.dfsg-3ubuntu0.6) over (1:9.9.5.dfsg-3ubuntu0.4) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
nginx-common (1.8.0-1+trusty1) を設定しています ...
設定ファイル /etc/default/nginx を新規にインストールしています ...
設定ファイル /etc/logrotate.d/nginx を新規にインストールしています ...
設定ファイル /etc/init.d/nginx を新規にインストールしています ...
設定ファイル /etc/nginx/uwsgi_params を新規にインストールしています ...
設定ファイル /etc/nginx/scgi_params を新規にインストールしています ...
設定ファイル /etc/nginx/koi-utf を新規にインストールしています ...
設定ファイル /etc/nginx/koi-win を新規にインストールしています ...
設定ファイル /etc/nginx/mime.types を新規にインストールしています ...
設定ファイル /etc/nginx/nginx.conf を新規にインストールしています ...
設定ファイル /etc/nginx/sites-available/default を新規にインストールしています ...
設定ファイル /etc/nginx/fastcgi_params を新規にインストールしています ...
Removing obsolete conffile /etc/nginx/naxsi.rules ...
Removing obsolete conffile /etc/nginx/naxsi_core.rules ...
Removing obsolete conffile /etc/nginx/naxsi-ui.conf.1.4.1 ...
libisc95 (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
libdns100 (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
libisccfg90 (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
libbind9-90 (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
liblwres90 (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
bind9-host (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
dnsutils (1:9.9.5.dfsg-3ubuntu0.6) を設定しています ...
Processing triggers for ureadahead (0.100.0-16) ...
nginx-full (1.8.0-1+trusty1) を設定しています ...
nginx start/running, process 16840
nginx (1.8.0-1+trusty1) を設定しています ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...





































































































































































































































●インストール確認。docker imagesコマンドで確認し、2つのイメージが追加されていることが確認できます。
root@ubuntu14:~# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
gliderlabs/herokuish latest 998d64a151b5 About a minute ago 1.29 GB
heroku/cedar 14 56b31ddc05ad 3 weeks ago 1.267 GB


●公開鍵とホスト名設定。インストール完了したら、公開鍵とホスト名設定をします。ここのホスト名はOSのホスト名ではなく、dokkuで使う名前になります。IP, FQDNを指定できます。dokkuのコンテナにアクセスするときに、このホスト名を使います。例えば(http://<ip>: port   or http://a.b.com: port)。
設定は、コマンドやブラウザでできます。
・コマンドの場合
公開鍵生成
root@ubuntu14:~# ssh-keygen
公開鍵をdokkuというユーザーの.ssh/authorized_keysにコピー
root@ubuntu14:~# cat ~/.ssh/id_rsa.pub | sshcommand acl-add dokku
root@ubuntu14:/home/dokku/.ssh# cat authorized_keys
command="FINGERPRINT=b4:02:1a:ca:02:02:b5:4e:9f:6b:21:66:44:1e:8b:a9 NAME=admin `cat /home/dokku/.sshcommand` $SSH_ORIGINAL_COMMAND",no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAkZLloUYN6T***== rsa-key-20151201

ホスト名設定 vi /home/dokku/HOSTNAMEを編集する



・ブラウザの場合。public keyとhostnameを入れて「Finish Setup」をクリックするだけですみます。
image_thumb4[4]
これでインストールと設定が完了です。
●アプリデプロイ
dokkuを使ってアプリのデプロイを実施できます。今回はnode jsのアプリを例にしてみます。github上のnode-js-sampleというサンプルです。ご自分のgithubアカウントにForkして、使ってください。
https://github.com/heroku/node-js-sample

概ねのコマンドは以下の様な感じです。git cloneして、remote レポジトリ追加し、git push するだけです。ご自分のレポジトリを書き換えてください。
git clone git@github.com:c-ye/node-js-sample.git
cd node-js-sample/
git remote add dokku dokku@192.168.80.134:node-js-app
git push dokku master

git push 実行したら、出力の最後にアクセスURLが表示されます。
root@ubuntu14:~/node-js-sample# git push dokku master
Counting objects: 406, done.
Compressing objects: 100% (319/319), done.
Writing objects: 100% (406/406), 215.62 KiB | 0 bytes/s, done.
Total 406 (delta 57), reused 406 (delta 57)
-----> Cleaning up...
-----> Building node-js-app from herokuish...
-----> Setting config vars
CURL_CONNECT_TIMEOUT: 5
-----> Setting config vars
CURL_TIMEOUT: 30
-----> Adding BUILD_ENV to build environment...
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 4.0.0
engines.npm (package.json): unspecified (use default)
Downloading and installing node 4.0.0...
Using default npm version: 2.14.2
-----> Restoring cache
Skipping cache restore (new runtime signature)
-----> Building dependencies
Pruning any extraneous modules
Installing node modules (package.json)
express@4.13.3 node_modules/express
tqq escape-html@1.0.2
tqq merge-descriptors@1.0.0
tqq array-flatten@1.1.1
tqq cookie@0.1.3
tqq utils-merge@1.0.0
tqq cookie-signature@1.0.6
tqq methods@1.1.1
tqq fresh@0.3.0
tqq range-parser@1.0.3
tqq vary@1.0.1
tqq path-to-regexp@0.1.7
tqq content-type@1.0.1
tqq etag@1.7.0
tqq parseurl@1.3.0
tqq content-disposition@0.5.0
tqq serve-static@1.10.0
tqq depd@1.0.1
tqq qs@4.0.0
tqq finalhandler@0.4.0 (unpipe@1.0.0)
tqq on-finished@2.3.0 (ee-first@1.1.1)
tqq proxy-addr@1.0.10 (forwarded@0.1.0, ipaddr.js@1.0.5)
tqq debug@2.2.0 (ms@0.7.1)
tqq send@0.13.0 (destroy@1.0.3, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-errors@1.3.1)
tqq type-is@1.6.10 (media-typer@0.3.0, mime-types@2.1.8)
mqq accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.8)
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
-----> Build succeeded!
mqq express@4.13.3
-----> Discovering process types
Procfile declares types -> web
-----> Releasing node-js-app (dokku/node-js-app:latest)...
-----> Deploying node-js-app (dokku/node-js-app:latest)...
-----> DOKKU_SCALE file not found in app image. Generating one based on Procfile...
-----> New DOKKU_SCALE file generated
=====> web=1
-----> Running pre-flight checks
For more efficient zero downtime deployments, create a file CHECKS.
See http://progrium.viewdocs.io/dokku/checks-examples.md for examples
CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
-----> Default container check successful!
=====> node-js-app container output:
Node app is running at localhost:5000
=====> end node-js-app container output
-----> Running post-deploy
=====> unsupported vhost config found. disabling vhost support
-----> Setting config vars
NO_VHOST: 1
-----> Setting config vars
NO_VHOST: 1
-----> no nginx port set. setting to random open high port
-----> Setting config vars
DOKKU_NGINX_PORT: 2720
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
Reloading nginx
-----> Setting config vars
DOKKU_APP_RESTORE: 1
=====> Application deployed:
http://192.168.80.134:32768 (container)
http://192.168.80.134:2720 (nginx)
To dokku@192.168.80.134:node-js-app
* [new branch] master -> master






























































































でブラウザで結果確認。今回はnode jsのサンプルの結果です。正常に表示されます。
image
これで、ソースコードからdeployすることができました。

2015年10月12日月曜日

VMware VCenter serverで.dmpファイルがディスク容量食う

  • このエントリーをはてなブックマークに追加


VCenter serverである時点から”VMware vCenter Update Manager Check Notification”という通知がたくさん蓄積してきました。これが原因でVcenter server上でvmware-updatemgr-7837.dmpのような.dmpファイルが増えて、ディスク容量を消費しています。

一般的なシステムエラーが発生しました:Failed to write to C:\Documents and Settings\All Users\Application Data\VMware VirtualCenter\journal\<number>:
Error writing file.There is not enough space on the disk.

 

ログには以下のようなエラーが出力された。

image

http://www.natestiller.com/2011/02/vcs-vsphere-check-new-notifications-stuck-on-queued-vmware-vcenter-update-manager-check-notification/

で紹介された方法でできそうですが、自分の環境では、うまく行かず。

”net stop vmware-ufad-vci” 

“net start vmware-ufad-vci”

 

仕方なく代替手段として、タスクスケジューラーで定期的にファイルを削除するようにしました。

バッチファイルは下記です。

del "C:\Documents and Settings\All Users\Application Data\VMware\VMware Update Manager\Logs\vmware-updatemgr-*.dmp"

2015年10月11日日曜日

PHP4でsimplexml_load_file()と同等の機能を実装

  • このエントリーをはてなブックマークに追加


最近、仕事でXMLファイルを加工するPHPスクリプトを書いています。テスト環境で、PHP5でしたので、simplexml_load_file()を使って、ファイルをロードし、XML各要素の値を出しています。
こちらsimplexml_load_fileの紹介をご参照ください。
基本的な SimpleXML の使用法 ¶


しかし、本番環境に持って行ったら、なんとPHPのバージョンは4点台だった。参りましたね。スクリプトを書く前にきちんと本番環境を確認しないと、実感しました。

で、PHPのバージョンも上げるのかありだが、それはちょっと影響範囲が大きいため、諦めた。そして、simplexml_load_file()のような機能がPHP4であるかどうか調べたら、ありましたよ。助かりました。

Implementation of simplexml_load_file() in PHP4

miniXMLというライブラリを使えば実現できます。
miniXMLはこちらからダウンロードしてください。
http://sourceforge.net/projects/minixml/


自分で簡単にサンプルコードも作ってみました。
======================================================
<?php
/* xml sample file
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
*/

require_once(".\minixml-1.3.8\minixml.inc.php");
$xml = new MiniXMLDoc();
$xml->fromFile('.\movies.xml');
$rootElement = & $xml->getRoot();

$movie = $rootElement->getElementByPath('movie');
$title = $rootElement->getElementByPath('movie/title')->getValue();
echo "$title\n";

$characters = $movie->getElementByPath('characters');
$characters_all = $characters->getAllChildren('character');
foreach($characters_all as $c){
  $name = $c->getElementByPath('name')->getValue();
  $actor = $c->getElementByPath('actor')->getValue();
  echo "$name,$actor\n";
}

$plot = $movie->getElementByPath('plot')->getValue();
echo "$plot\n";

$greatlines = $movie->getElementByPath('great-lines');
$greatlines_all = $greatlines->getAllChildren('line');
foreach($greatlines_all as $l){
  $greatline = $l->getValue();
  echo "$greatline\n";
}

$ratings = $movie->getAllChildren('rating');
foreach ($ratings as $r){
  $type = $r->xattributes['type'];
  $rating = $r->getValue();
  echo "$type,$rating\n";
}
?>
======================================================


実行結果は下記の通りです。
c:\php>php parsexml.php
PHP: Behind the Parser
Ms. Coder,Onlivia Actora
Mr. Coder,El ActÓr
So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
PHP solves all my web problems
thumbs,7
stars,5

XMLの要素を全部出力できました。