2014年5月29日木曜日

homebrewでmavenもインストール

普段はeclipseでm2eを使っているので、
maven入れないでも何とかなるので入れてなかったのですが、
用意してあるプログラムがmvnコマンド実行するタイプのものだったので、
homebrewでmaven入れてみました。

まずはhomebrew入れられるのか確認してみるといくつか出てくる。
$ brew search maven
maven      maven-shell  maven2       maven30     maven31
homebrew/versions/maven2     homebrew/versions/maven30   homebrew/versions/maven31

とりあえず上の5つをbrew infoで確認してみると、
「maven」のやつが最新版のようです。
$ brew info maven2
maven2: stable 2.2.1
http://maven.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/maven2.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.
 
$ brew info maven30
maven30: stable 3.0.5
http://maven.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/maven30.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.
 
$ brew info maven31
maven31: stable 3.1.1
http://maven.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/maven31.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.
 
$ brew info maven
maven: stable 3.2.1
http://maven.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/maven.rb
 
$ brew info maven-shell
maven-shell: stable 1.1.0
http://shell.sonatype.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/maven-shell.rb

versionsがつくやつはやはりtapしてないのでエラーになる。
$ brew info homebrew/versions/maven2
Error: No available formula for maven2 
Please tap it and then try again: brew tap homebrew/versions 

なのでtapしてみると、すごくWarning出た。
$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-versions'...
remote: Reusing existing pack: 2077, done.
remote: Counting objects: 2, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2079 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2079/2079), 664.37 KiB | 338.00 KiB/s, done.
Resolving deltas: 100% (1148/1148), done.
Checking connectivity... done.
Warning: Could not tap homebrew/homebrew-versions/allegro4 over 
Warning: Could not tap homebrew/homebrew-versions/allegro5 over 
Warning: Could not tap homebrew/homebrew-versions/ansible14 over 
Warning: Could not tap homebrew/homebrew-versions/antlr2 over 
Warning: Could not tap homebrew/homebrew-versions/appledoc20 over 
Warning: Could not tap homebrew/homebrew-versions/appledoc21 over 
Warning: Could not tap homebrew/homebrew-versions/appledoc22 over 
Warning: Could not tap homebrew/homebrew-versions/autoconf213 over 
Warning: Could not tap homebrew/homebrew-versions/autoconf264 over 
Warning: Could not tap homebrew/homebrew-versions/automake112 over 
Warning: Could not tap homebrew/homebrew-versions/bash-completion2 over 
Warning: Could not tap homebrew/homebrew-versions/bison27 over 
Warning: Could not tap homebrew/homebrew-versions/boost149 over 
Warning: Could not tap homebrew/homebrew-versions/cassandra-0.6 over 
Warning: Could not tap homebrew/homebrew-versions/cassandra10 over 
Warning: Could not tap homebrew/homebrew-versions/cassandra12 over 
Warning: Could not tap homebrew/homebrew-versions/clojure14 over 
Warning: Could not tap homebrew/homebrew-versions/cloog-ppl015 over 
Warning: Could not tap homebrew/homebrew-versions/cloog018 over 
Warning: Could not tap homebrew/homebrew-versions/coq83 over 
Warning: Could not tap homebrew/homebrew-versions/cvsps2 over 
Warning: Could not tap homebrew/homebrew-versions/doxygen1831 over 
Warning: Could not tap homebrew/homebrew-versions/drush4 over 
Warning: Could not tap homebrew/homebrew-versions/drush5 over 
Warning: Could not tap homebrew/homebrew-versions/eigen2 over 
Warning: Could not tap homebrew/homebrew-versions/elasticsearch-0.20 over 
Warning: Could not tap homebrew/homebrew-versions/elasticsearch090 over 
Warning: Could not tap homebrew/homebrew-versions/erlang-r13 over 
Warning: Could not tap homebrew/homebrew-versions/erlang-r14 over 
Warning: Could not tap homebrew/homebrew-versions/erlang-r15 over 
Warning: Could not tap homebrew/homebrew-versions/gawk3 over 
Warning: Could not tap homebrew/homebrew-versions/gcc43 over 
Warning: Could not tap homebrew/homebrew-versions/gcc44 over 
Warning: Could not tap homebrew/homebrew-versions/gcc45 over 
Warning: Could not tap homebrew/homebrew-versions/gcc46 over 
Warning: Could not tap homebrew/homebrew-versions/gcc47 over 
Warning: Could not tap homebrew/homebrew-versions/gcc48 over 
Warning: Could not tap homebrew/homebrew-versions/gcc49 over 
Warning: Could not tap homebrew/homebrew-versions/giflib5 over 
Warning: Could not tap homebrew/homebrew-versions/git-tf-2.0.2 over 
Warning: Could not tap homebrew/homebrew-versions/glfw2 over 
Warning: Could not tap homebrew/homebrew-versions/glfw3 over 
Warning: Could not tap homebrew/homebrew-versions/gmp4 over 
Warning: Could not tap homebrew/homebrew-versions/grails13 over 
Warning: Could not tap homebrew/homebrew-versions/grails20 over 
Warning: Could not tap homebrew/homebrew-versions/grails21 over 
Warning: Could not tap homebrew/homebrew-versions/grails22 over 
Warning: Could not tap homebrew/homebrew-versions/gsl114 over 
Warning: Could not tap homebrew/homebrew-versions/gst-ffmpeg010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-plugins-bad010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-plugins-base010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-plugins-good010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-plugins-ugly010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-python010 over 
Warning: Could not tap homebrew/homebrew-versions/gst-rtsp010 over 
Warning: Could not tap homebrew/homebrew-versions/gstreamer010 over 
Warning: Could not tap homebrew/homebrew-versions/guile18 over 
Warning: Could not tap homebrew/homebrew-versions/hadoop0202 over 
Warning: Could not tap homebrew/homebrew-versions/hadoop121 over 
Warning: Could not tap homebrew/homebrew-versions/hdf4 over 
Warning: Could not tap homebrew/homebrew-versions/imagemagick-ruby186 over 
Warning: Could not tap homebrew/homebrew-versions/isl011 over 
Warning: Could not tap homebrew/homebrew-versions/jboss-as5 over 
Warning: Could not tap homebrew/homebrew-versions/jboss-forge1 over 
Warning: Could not tap homebrew/homebrew-versions/jenkins-lts over 
Warning: Could not tap homebrew/homebrew-versions/jetty76 over 
Warning: Could not tap homebrew/homebrew-versions/jetty8 over 
Warning: Could not tap homebrew/homebrew-versions/jpeg6b over 
Warning: Could not tap homebrew/homebrew-versions/jpeg9 over 
Warning: Could not tap homebrew/homebrew-versions/json-c010 over 
Warning: Could not tap homebrew/homebrew-versions/leptonica169 over 
Warning: Could not tap homebrew/homebrew-versions/libcouchbase1 over 
Warning: Could not tap homebrew/homebrew-versions/libgee08 over 
Warning: Could not tap homebrew/homebrew-versions/libmpc08 over 
Warning: Could not tap homebrew/homebrew-versions/libotr4 over 
Warning: Could not tap homebrew/homebrew-versions/libpng12 over 
Warning: Could not tap homebrew/homebrew-versions/llvm-gcc28 over 
Warning: Could not tap homebrew/homebrew-versions/llvm31 over 
Warning: Could not tap homebrew/homebrew-versions/llvm32 over 
Warning: Could not tap homebrew/homebrew-versions/llvm33 over 
Warning: Could not tap homebrew/homebrew-versions/llvm34 over 
Warning: Could not tap homebrew/homebrew-versions/llvm35 over 
Warning: Could not tap homebrew/homebrew-versions/log4cplus10 over 
Warning: Could not tap homebrew/homebrew-versions/lua52 over 
Warning: Could not tap homebrew/homebrew-versions/mapnik071 over 
Warning: Could not tap homebrew/homebrew-versions/maven2 over 
Warning: Could not tap homebrew/homebrew-versions/maven30 over 
Warning: Could not tap homebrew/homebrew-versions/maven31 over 
Warning: Could not tap homebrew/homebrew-versions/mongodb24 over 
Warning: Could not tap homebrew/homebrew-versions/mpfr2 over 
Warning: Could not tap homebrew/homebrew-versions/mysql51 over 
Warning: Could not tap homebrew/homebrew-versions/mysql55 over 
Warning: Could not tap homebrew/homebrew-versions/node04 over 
Warning: Could not tap homebrew/homebrew-versions/node06 over 
Warning: Could not tap homebrew/homebrew-versions/node08 over 
Warning: Could not tap homebrew/homebrew-versions/nu0 over 
Warning: Could not tap homebrew/homebrew-versions/open-mpi16 over 
Warning: Could not tap homebrew/homebrew-versions/openjpeg20 over 
Warning: Could not tap homebrew/homebrew-versions/openssl098 over 
Warning: Could not tap homebrew/homebrew-versions/percona-server55 over 
Warning: Could not tap homebrew/homebrew-versions/perl514 over 
Warning: Could not tap homebrew/homebrew-versions/perl516 over 
Warning: Could not tap homebrew/homebrew-versions/perl518 over 
Warning: Could not tap homebrew/homebrew-versions/phantomjs17 over 
Warning: Could not tap homebrew/homebrew-versions/phantomjs182 over 
Warning: Could not tap homebrew/homebrew-versions/phantomjs192 over 
Warning: Could not tap homebrew/homebrew-versions/play12 over 
Warning: Could not tap homebrew/homebrew-versions/plowshare3 over 
Warning: Could not tap homebrew/homebrew-versions/postgis15 over 
Warning: Could not tap homebrew/homebrew-versions/postgis20 over 
Warning: Could not tap homebrew/homebrew-versions/postgresql8 over 
Warning: Could not tap homebrew/homebrew-versions/postgresql9 over 
Warning: Could not tap homebrew/homebrew-versions/postgresql91 over 
Warning: Could not tap homebrew/homebrew-versions/postgresql92 over 
Warning: Could not tap homebrew/homebrew-versions/povray36 over 
Warning: Could not tap homebrew/homebrew-versions/ppl011 over 
Warning: Could not tap homebrew/homebrew-versions/ppl10 over 
Warning: Could not tap homebrew/homebrew-versions/protobuf240a over 
Warning: Could not tap homebrew/homebrew-versions/protobuf241 over 
Warning: Could not tap homebrew/homebrew-versions/rabbitmq30 over 
Warning: Could not tap homebrew/homebrew-versions/raptor1 over 
Warning: Could not tap homebrew/homebrew-versions/redis1310 over 
Warning: Could not tap homebrew/homebrew-versions/redis24 over 
Warning: Could not tap homebrew/homebrew-versions/ruby182 over 
Warning: Could not tap homebrew/homebrew-versions/ruby186 over 
Warning: Could not tap homebrew/homebrew-versions/ruby192 over 
Warning: Could not tap homebrew/homebrew-versions/ruby193 over 
Warning: Could not tap homebrew/homebrew-versions/ruby20 over 
Warning: Could not tap homebrew/homebrew-versions/scala210 over 
Warning: Could not tap homebrew/homebrew-versions/scala29 over 
Warning: Could not tap homebrew/homebrew-versions/solr14 over 
Warning: Could not tap homebrew/homebrew-versions/solr36 over 
Warning: Could not tap homebrew/homebrew-versions/squid2 over 
Warning: Could not tap homebrew/homebrew-versions/subversion16 over 
Warning: Could not tap homebrew/homebrew-versions/subversion17 over 
Warning: Could not tap homebrew/homebrew-versions/tomcat6 over 
Warning: Could not tap homebrew/homebrew-versions/unison232 over 
Warning: Could not tap homebrew/homebrew-versions/valgrind36 over 
Warning: Could not tap homebrew/homebrew-versions/valgrind38 over 
Warning: Could not tap homebrew/homebrew-versions/varnish3 over 
Warning: Could not tap homebrew/homebrew-versions/vtk5 over 
Warning: Could not tap homebrew/homebrew-versions/zeromq22 over 
Warning: Could not tap homebrew/homebrew-versions/zeromq3 over 
Warning: Could not tap homebrew/homebrew-versions/zeromq32 over 
Tapped 144 formulae

tapした後はちゃんとinfoで引けるようになった。
ただ、versionsとついているだけあって、最新版のはないけど。
$ brew info homebrew/versions/maven2
maven2: stable 2.2.1
http://maven.apache.org/
Not installed
From: https://github.com/homebrew/homebrew-versions/commits/master/maven2.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.
 
$ brew info homebrew/versions/maven30
maven30: stable 3.0.5
http://maven.apache.org/
Not installed
From: https://github.com/homebrew/homebrew-versions/commits/master/maven30.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.
 
$ brew info homebrew/versions/maven31
maven31: stable 3.1.1
http://maven.apache.org/
Not installed
From: https://github.com/homebrew/homebrew-versions/commits/master/maven31.rb
==> Caveats
WARNING: This older version will conflict with Maven if installed at the
same time.

そして最新版をインストール。あっさりと終わる。
$ brew install maven
==> Downloading http://www.apache.org/dyn/closer.cgi?path=maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
==> Best Mirror http://ftp.riken.jp/net/apache/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/maven/3.2.1: 65 files, 7.8M, built in 3 seconds

ちゃんとmavenが入っていることが確認できた。
インストールされてるディレクトリもわかるので助かる。
$ mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T02:37:52+09:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: ja_JP, platform encoding: SJIS
OS name: "mac os x", version: "10.9.3", arch: "x86_64", family: "mac"

2014年5月25日日曜日

squidのcacheを減らす方法

ちょっとsquidの環境を作っていたらdiskが足りなかったので、cacheを減らしてみました。

まずは現在のcache容量を確認。diskは20Gしか積んでないのでかなりやばいです。
# cd /data/squid/cache/
# ls -al
合計 16649228
drwxr-xr-x 2 squid squid        4096  5月 12 09:49 2014 .
drwxr-xr-x 4 root  root         4096  5月  8 17:42 2014 ..
-rw------- 1 squid squid 17048797184  5月 21 10:13 2014 coss

減らす前のsquidの設定ファイルを確認。
# grep coss /etc/squid/squid.conf
cache_dir coss /data/squid/cache/coss 16250 block-size=1024 max-size=524288

cacheの量を変更。
# vim /etc/squid/squid.conf
 
# grep coss /etc/squid/squid.conf
cache_dir coss /data/squid/cache/coss 1625 block-size=1024 max-size=524288

現在のcacheファイルを削除。diskがかなり空きました。
サービス提供中とかだと実施できない手順ですが。。。
# rm coss 
rm: remove 通常ファイル `coss'? y

# ls -al
合計 8
drwxr-xr-x 2 squid squid 4096  5月 21 10:13 2014 .
drwxr-xr-x 4 root  root  4096  5月  8 17:42 2014 ..

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  2.8G   16G  15% /
tmpfs           499M     0  499M   0% /dev/shm

cacheを作り直します。
# squid -z
2014/05/21 10:13:59| Creating Swap Directories

squidを再起動すると、cacheの容量が設定変更後の量になりました。
# /etc/init.d/squid restart

# ls -al
合計 1664012
drwxr-xr-x 2 squid squid       4096  5月 21 10:13 2014 .
drwxr-xr-x 4 root  root        4096  5月  8 17:42 2014 ..
-rw------- 1 squid squid 1703936000  5月 21 10:14 2014 coss

参考URL
http://blog.x28.jp/archives/167

2014年5月15日木曜日

PlayのslickでのDBアクセス処理

PlayでSlickを使っていくつかブログ書いてたので、
http://syaka-syaka.blogspot.com/2014/04/play-frameworkslickevolution.html
http://syaka-syaka.blogspot.com/2014/05/play-frameworkslickevolution.html
DBアクセス処理についても載せてみます。
けっこういろんな書き方ができるのでいいところと難しいところあるなと感じました。
package models.h2
 
import play.api.db.slick.Config.driver.simple._
import models.dao.DAO
import java.sql.Timestamp
 
case class Twitter(
    id: Int, 
    word: String, 
    count:Int,
    disp_flg:Boolean,
    ng_flg : Boolean, 
    ins_date: Timestamp, 
    upd_date: Timestamp
)
  
class Twitters(tag: Tag) extends Table[Twitter](tag,"twitter"){
 
  def id = column[Int]("id",O.PrimaryKey,O.AutoInc)
  def word = column[String]("word",O.NotNull)
  def count = column[Int]("count",O.NotNull)
  def disp_flg = column[Boolean]("disp_flg",O.NotNull)
  def ng_flg = column[Boolean]("ng_flg",O.NotNull)
  def ins_date = column[Timestamp]("ins_date",O.NotNull)
  def upd_date = column[Timestamp]("upd_date",O.NotNull)
  def * = (id,word,count,disp_flg,ng_flg,ins_date,upd_date) <> (Twitter.tupled,Twitter.unapply)
}
 
object Twitters extends DAO{
  
  /**
   * 特定のカラムのみを引数指定でinsertする
   */
  def insert(word:String,ins_date:Timestamp,upd_date:Timestamp,count:Int,ng_flg:Boolean,disp_flg:Boolean)(implicit s: Session) = {
    Twitters map{
      r => (r.word,r.ins_date,r.upd_date,r.count,r.ng_flg,r.disp_flg)
    } +=(word,ins_date,upd_date,count,ng_flg,disp_flg)
    
  }
  
  /**
   *特定のカラムをkeyに該当するデータ(1カラム)をリストでselectする
   */ 
  def findByWord(word:String)(implicit s: Session):List[Int] = {
    Twitters filter {
      _.word === word
    } map {
     _.id
    } list
  }
 
  /**
   * 特定のカラムをkeyに該当するデータ(全カラム)を1件取得する
   */ 
  def findById(id:Int)(implicit s:Session):Twitter = {
    Twitters.where(_.id === id).first
  }
  
  /**
   * 特定のカラムをkeyに該当するデータ(全カラム)をリストでselectする
   */ 
  def findAllByWord(word:String)(implicit s: Session):List[Twitter] = {
   Twitters.where(_.word === word).list
  }
  
  /**
   * 全件select
   */ 
  def findAll()(implicit s:Session):List[Twitter] = {
    Twitters.list
  }
 
  /**
   * 全件select(idの降順)
   */ 
  def findAllOrderByIdDesc()(implicit s:Session):List[Twitter] = {
    Twitters.sortBy(_.id.desc).list
  }
 
  /**
   * select order byをしてlimitとoffsetつき
   */ 
  def findAllLimitOffsetOrderByIdDesc(limit:Int,offset:Int)(implicit s:Session):List[Twitter] = {
    val q = Twitters.sortBy(_.id.desc).drop(offset).take(limit)
//    println(q.selectStatement) //組み立てられたSQLを確認できる
    q.list
  }
  
  /**
   * select upd_date,idでorder byをしてlimitとoffsetつき
   */ 
  def findAllLimitOffsetOrderByUpdDateDescAndIdDesc(limit:Int,offset:Int)(implicit s:Session):List[Twitter] = {
    val q = Twitters.sortBy(_.id.desc).sortBy(_.upd_date.desc).drop(offset).take(limit) //order by upd_date desc,id descになる
//    println(q.selectStatement) //組み立てられたSQLを確認できる
    q.list
  }
  
  /**
   * 特定のカラムをkeyに該当するデータの1カラムをupdateする
   */ 
  def update(id:Int,updCount:Int)(implicit s:Session) = {
   Twitters.where(_.id === id).map(_.count).update(updCount)
  }
 
  /**
   * 特定のカラムをkeyに該当するデータの複数カラムをupdateする
   */ 
  def updateMultiColumn(id:Int,updCount:Int,updDate:Timestamp)(implicit s:Session) = {
   
   val q = (for 
  {twi <- Twitters if twi.id === id}
   yield
    (twi.count , twi.upd_date)
   )
   
//   println(q.updateStatement) //組み立てられたSQLを確認できる
   q.update(updCount,updDate)
  }
  
  /**
   * 件数をselectする
   */ 
  def count(implicit s:Session):Int = {
    Query(Twitters.length).first
  }
  
}


参考URL
https://github.com/freekh/play-slick
http://blog.lunatech.com/2013/09/25/play-slick-defining-queries
http://qiita.com/ryu1_okd/items/6871515ec42e88cd534f
http://zephiransas.github.io/blog/2013/04/24/slickwoshi-u/
http://tototoshi.hatenablog.com/entry/20121204/1354615421
http://krrrr.hatenablog.com/entry/20130213/1360687102

2014年5月12日月曜日

Macにbundlerでrailsを入れてみた

Macにbundlerでrails4.1.0を入れてみました。
Gemfileにrailsを追加。
$ vim Gemfile
$ cat Gemfile
source 'https://rubygems.org'
gem 'chef','~> 11.10.0'
gem 'berkshelf'
gem 'knife-solo'
gem 'rails'

bundleを実行。
$ bundle --path vendor/bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies....
Installing rake 10.3.1
Installing actionpack 1.4.0
Installing actionmailer 0.6.1
Installing activerecord 1.6.0
Using i18n 0.6.9
Using multi_json 1.9.2
Using activesupport 3.2.17
Using addressable 2.3.6
Using builder 3.2.2
Using gyoku 1.1.1
Using mini_portile 0.5.3
Using nokogiri 1.6.1
Using akami 1.2.1
Using buff-ruby_engine 0.1.0
Using buff-shell_out 0.1.1
Using hashie 2.1.1
Using chozo 0.6.1
Using multipart-post 1.2.0
Using faraday 0.8.9
Using minitar 0.5.4
Using rbzip2 0.2.0
Using retryable 1.3.5
Using buff-extensions 0.5.0
Using varia_model 0.3.2
Using buff-config 0.4.0
Using buff-ignore 1.1.1
Using hitimes 1.2.1
Using timers 2.0.0
Using celluloid 0.14.1
Using nio4r 1.0.0
Using celluloid-io 0.14.1
Using erubis 2.7.0
Using json 1.8.1
Using mixlib-log 1.6.0
Using mixlib-authentication 1.3.0
Using net-http-persistent 2.9.4
Using net-ssh 2.8.0
Using solve 0.8.2
Using ffi 1.9.3
Using gssapi 1.0.3
Using httpclient 2.3.4.1
Using little-plugger 1.1.3
Using logging 1.8.2
Using rubyntlm 0.1.1
Using rack 1.5.2
Using httpi 0.9.7
Using nori 1.1.5
Using wasabi 1.0.0
Using savon 0.9.5
Using uuidtools 2.1.4
Using winrm 1.1.3
Using ridley 1.5.3
Using thor 0.18.1
Using berkshelf 2.0.14
Using moneta 0.6.0
Using chef-zero 1.7.3
Using diff-lcs 1.2.5
Using highline 1.6.21
Using mime-types 1.25.1
Using mixlib-cli 1.4.0
Using mixlib-config 2.1.0
Using mixlib-shellout 1.4.0
Using net-ssh-gateway 1.2.0
Using net-ssh-multi 1.2.0
Using ipaddress 0.8.0
Using systemu 2.5.2
Using yajl-ruby 1.2.0
Using ohai 6.22.0
Using coderay 1.1.0
Using method_source 0.8.2
Using slop 3.5.0
Using pry 0.9.12.6
Using puma 1.6.3
Using rest-client 1.6.7
Using chef 11.10.4
Using knife-solo 0.4.1
Installing rails 0.9.5
Using bundler 1.6.1
Your bundle is complete!
It was installed into ./vendor/bundle

rails0.9.5が入ってしまった。
railsのバージョンを確認してみると、エラーになった。。。
$ bundle exec rails -v
(in /Users/xxxx/bundle/vendor/bundle/ruby/2.1.0/gems/rails-0.9.5)
rake aborted!
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
/Users/xxxx/bundle/vendor/bundle/ruby/2.1.0/gems/rails-0.9.5/Rakefile:3:in `require'
/Users/xxxx/bundle/vendor/bundle/ruby/2.1.0/gems/rails-0.9.5/Rakefile:3:in `'
(See full trace by running task with --trace)

Gemfileにrailsのバージョンを指定。
$ vim Gemfile
$ cat Gemfile
source 'https://rubygems.org'
gem 'chef','~> 11.10.0'
gem 'berkshelf'
gem 'knife-solo'
gem 'rails','4.1.0'

bundleを実行してみるとまたエラーが出た。
$ bundle --path vendor/bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    rails (= 4.1.0) ruby depends on
      activesupport (= 4.1.0) ruby
 
    berkshelf (>= 0) ruby depends on
      activesupport (3.2.17)

gem 'rails','4.1.0'を一度コメントアウトして、bundle updateを実行。
$ bundle update
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using addressable 2.3.6
Installing multipart-post 2.0.0 (was 1.2.0)
Installing faraday 0.9.0 (was 0.8.9)
Installing berkshelf-api-client 1.2.0
Using buff-extensions 0.5.0
Using hashie 2.1.1
Using varia_model 0.3.2
Using buff-config 0.4.0
Using buff-ruby_engine 0.1.0
Using buff-shell_out 0.1.1
Using hitimes 1.2.1
Using timers 2.0.0
Installing celluloid 0.16.0.pre (was 0.14.1)
Using nio4r 1.0.0
Installing celluloid-io 0.16.0.pre (was 0.14.1)
Using minitar 0.5.4
Installing sawyer 0.5.4
Installing octokit 3.1.0
Using retryable 1.3.5
Using buff-ignore 1.1.1
Using erubis 2.7.0
Using json 1.8.1
Using mixlib-log 1.6.0
Using mixlib-authentication 1.3.0
Using net-http-persistent 2.9.4
Installing semverse 1.1.0
Installing ridley 3.1.0 (was 1.5.3)
Installing dep-selector-libgecode 1.0.0
Using ffi 1.9.3
Installing dep_selector 1.0.3
Installing solve 1.2.0 (was 0.8.2)
Installing thor 0.19.1 (was 0.18.1)
Installing berkshelf 3.1.2 (was 2.0.14)
Using moneta 0.6.0
Using rack 1.5.2
Using chef-zero 1.7.3
Using diff-lcs 1.2.5
Using highline 1.6.21
Using mime-types 1.25.1
Installing mixlib-cli 1.5.0 (was 1.4.0)
Using mixlib-config 2.1.0
Using mixlib-shellout 1.4.0
Installing net-ssh 2.9.0 (was 2.8.0)
Using net-ssh-gateway 1.2.0
Using net-ssh-multi 1.2.0
Using ipaddress 0.8.0
Using systemu 2.5.2
Using yajl-ruby 1.2.0
Using ohai 6.22.0
Using coderay 1.1.0
Using method_source 0.8.2
Using slop 3.5.0
Using pry 0.9.12.6
Using puma 1.6.3
Using rest-client 1.6.7
Using chef 11.10.4
Using knife-solo 0.4.1
Using bundler 1.6.1
Your bundle is updated!

Gemfileのrailsのコメントアウトを外して、再度bundleを実行。
$ bundle --path vendor/bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.3.1
Using i18n 0.6.9
Using json 1.8.1
Installing minitest 5.3.3
Installing thread_safe 0.3.3
Installing tzinfo 1.1.0
Installing activesupport 4.1.0
Using builder 3.2.2
Using erubis 2.7.0
Installing actionview 4.1.0
Using rack 1.5.2
Installing rack-test 0.6.2
Installing actionpack 4.1.0
Using mime-types 1.25.1
Installing polyglot 0.3.4
Installing treetop 1.4.15
Installing mail 2.5.4
Installing actionmailer 4.1.0
Installing activemodel 4.1.0
Installing arel 5.0.1.20140414130214
Installing activerecord 4.1.0
Using addressable 2.3.6
Using multipart-post 2.0.0
Using faraday 0.9.0
Using berkshelf-api-client 1.2.0
Using buff-extensions 0.5.0
Using hashie 2.1.1
Using varia_model 0.3.2
Using buff-config 0.4.0
Using buff-ruby_engine 0.1.0
Using buff-shell_out 0.1.1
Using hitimes 1.2.1
Using timers 2.0.0
Using celluloid 0.16.0.pre
Using nio4r 1.0.0
Using celluloid-io 0.16.0.pre
Using minitar 0.5.4
Using sawyer 0.5.4
Using octokit 3.1.0
Using retryable 1.3.5
Using buff-ignore 1.1.1
Using mixlib-log 1.6.0
Using mixlib-authentication 1.3.0
Using net-http-persistent 2.9.4
Using semverse 1.1.0
Using ridley 3.1.0
Using dep-selector-libgecode 1.0.0
Using ffi 1.9.3
Using dep_selector 1.0.3
Using solve 1.2.0
Using thor 0.19.1
Using berkshelf 3.1.2
Using bundler 1.6.1
Using moneta 0.6.0
Using chef-zero 1.7.3
Using diff-lcs 1.2.5
Using highline 1.6.21
Using mixlib-cli 1.5.0
Using mixlib-config 2.1.0
Using mixlib-shellout 1.4.0
Using net-ssh 2.9.0
Using net-ssh-gateway 1.2.0
Using net-ssh-multi 1.2.0
Using ipaddress 0.8.0
Using systemu 2.5.2
Using yajl-ruby 1.2.0
Using ohai 6.22.0
Using coderay 1.1.0
Using method_source 0.8.2
Using slop 3.5.0
Using pry 0.9.12.6
Using puma 1.6.3
Using rest-client 1.6.7
Using chef 11.10.4
Installing hike 1.2.3
Using knife-solo 0.4.1
Installing multi_json 1.10.0
Installing railties 4.1.0
Installing tilt 1.4.1
Installing sprockets 2.12.1
Installing sprockets-rails 2.1.3
Installing rails 4.1.0
Your bundle is complete!
It was installed into ./vendor/bundle

正常にrails4.1.0が入ったようなので、バージョンを確認。
$ bundle exec rails -v
Rails 4.1.0


参考URL
http://qiita.com/znz/items/5471e5826fde29fa9a80
http://qiita.com/hirokishirai/items/e38b29a7075459ff6032
http://www.rubylife.jp/rails/ini/index2.html

2014年5月11日日曜日

ruby bundlerでchefを入れてみた

rbenvでrubyを入れられるようにしたので、次はchefを入れてみました。
今回はbundlerで入れるので、まずはGemfileを作成。
$ vim Gemfile
$ cat Gemfile
source 'https://rubygems.org'
gem 'chef'
gem 'berkshelf'

早速インストールを実行。
--pathでインストール先を指定する。
$ bundle --path vendor/bundle
Fetching source index from https://rubygems.org/
Resolving dependencies........................................................
Installing i18n 0.6.9
Installing multi_json 1.9.2
Installing activesupport 3.2.17
Installing addressable 2.3.6
Installing builder 3.2.2
Installing gyoku 1.1.1
Installing mini_portile 0.5.3
Installing nokogiri 1.6.1
Installing akami 1.2.1
Installing buff-ruby_engine 0.1.0
Installing buff-shell_out 0.1.1
Installing hashie 2.1.0
Installing chozo 0.6.1
Installing multipart-post 1.2.0
Installing faraday 0.8.9
Installing minitar 0.5.4
Installing rbzip2 0.2.0
Installing retryable 1.3.5
Installing buff-extensions 0.5.0
Installing varia_model 0.3.2
Installing buff-config 0.4.0
Installing buff-ignore 1.1.1
Installing hitimes 1.2.1
Installing timers 2.0.0
Installing celluloid 0.14.1
Installing nio4r 1.0.0
Installing celluloid-io 0.14.1
Installing erubis 2.7.0
Using json 1.8.1
Installing mixlib-log 1.6.0
Installing mixlib-authentication 1.3.0
Installing net-http-persistent 2.9.4
Installing net-ssh 2.8.0
Installing solve 0.8.2
Installing ffi 1.9.3
Installing gssapi 1.0.3
Installing httpclient 2.3.4.1
Installing little-plugger 1.1.3
Installing logging 1.8.2
Installing rubyntlm 0.1.1
Installing rack 1.5.2
Installing httpi 0.9.7
Installing nori 1.1.5
Installing wasabi 1.0.0
Installing savon 0.9.5
Installing uuidtools 2.1.4
Installing winrm 1.1.3
Installing ridley 1.5.3
Installing thor 0.18.1
Installing berkshelf 2.0.14
Installing chef-zero 2.0.2
Installing diff-lcs 1.2.5
Installing highline 1.6.21
Installing mime-types 1.25.1
Installing mixlib-cli 1.4.0
Installing mixlib-config 2.1.0
Installing mixlib-shellout 1.4.0
Installing net-ssh-gateway 1.2.0
Installing net-ssh-multi 1.2.0
Installing ipaddress 0.8.0
Installing systemu 2.5.2
Installing yajl-ruby 1.2.0
Installing ohai 7.0.2
Installing coderay 1.1.0
Installing method_source 0.8.2
Installing slop 3.5.0
Installing pry 0.9.12.6
Installing rest-client 1.6.7
Installing chef 11.12.2
Using bundler 1.6.1
Your bundle is complete!
It was installed into ./vendor/bundle

次にknife-soloを追加。
$ vim Gemfile
$ cat Gemfile
source 'https://rubygems.org'
gem 'chef'
gem 'berkshelf'
gem 'knife-solo'

インストールを実行。
「install」はつけてもつけなくてもよいみたい。
$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using i18n 0.6.9
Using multi_json 1.9.2
Using activesupport 3.2.17
Using addressable 2.3.6
Using builder 3.2.2
Using gyoku 1.1.1
Using mini_portile 0.5.3
Using nokogiri 1.6.1
Using akami 1.2.1
Using buff-ruby_engine 0.1.0
Using buff-shell_out 0.1.1
Using hashie 2.1.0
Using chozo 0.6.1
Using multipart-post 1.2.0
Using faraday 0.8.9
Using minitar 0.5.4
Using rbzip2 0.2.0
Using retryable 1.3.5
Using buff-extensions 0.5.0
Using varia_model 0.3.2
Using buff-config 0.4.0
Using buff-ignore 1.1.1
Using hitimes 1.2.1
Using timers 2.0.0
Using celluloid 0.14.1
Using nio4r 1.0.0
Using celluloid-io 0.14.1
Using erubis 2.7.0
Using json 1.8.1
Using mixlib-log 1.6.0
Using mixlib-authentication 1.3.0
Using net-http-persistent 2.9.4
Using net-ssh 2.8.0
Using solve 0.8.2
Using ffi 1.9.3
Using gssapi 1.0.3
Using httpclient 2.3.4.1
Using little-plugger 1.1.3
Using logging 1.8.2
Using rubyntlm 0.1.1
Using rack 1.5.2
Using httpi 0.9.7
Using nori 1.1.5
Using wasabi 1.0.0
Using savon 0.9.5
Using uuidtools 2.1.4
Using winrm 1.1.3
Using ridley 1.5.3
Using thor 0.18.1
Using berkshelf 2.0.14
Using chef-zero 2.0.2
Using diff-lcs 1.2.5
Using highline 1.6.21
Using mime-types 1.25.1
Using mixlib-cli 1.4.0
Using mixlib-config 2.1.0
Using mixlib-shellout 1.4.0
Using net-ssh-gateway 1.2.0
Using net-ssh-multi 1.2.0
Using ipaddress 0.8.0
Using systemu 2.5.2
Using yajl-ruby 1.2.0
Using ohai 7.0.2
Using coderay 1.1.0
Using method_source 0.8.2
Using slop 3.5.0
Using pry 0.9.12.6
Using rest-client 1.6.7
Using chef 11.12.2
Installing knife-solo 0.4.1
Using bundler 1.6.1
Your bundle is complete!
It was installed into ./vendor/bundle
Post-install message from knife-solo:
Thanks for installing knife-solo!
 
If you run into any issues please let us know at:
  https://github.com/matschaffer/knife-solo/issues
 
If you are upgrading knife-solo please uninstall any old versions by
running `gem clean knife-solo` to avoid any errors.
 
See http://bit.ly/CHEF-3255 for more information on the knife bug
that causes this.

chefのバージョンを確認する。
$ bundle exec chef-solo -v
Chef: 11.12.2

早速いろいろ試してみると、これにはまる
http://qiita.com/sakatuba@github/items/1548818b02735b2047ad
とりあえずchefのバージョンを下げてみます。
Gemfile修正
gem 'chef','~> 11.10.0'

今回はinstallとやろうとするとエラーになってupdateを薦められる
$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
You have requested:
  chef ~> 11.10.0
 
The bundle currently has chef locked at 11.12.2.
Try running `bundle update chef`

薦められたようにupdateを実行
$ bundle update chef
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using i18n 0.6.9
Using multi_json 1.9.2
Using activesupport 3.2.17
Using addressable 2.3.6
Using builder 3.2.2
Using gyoku 1.1.1
Using mini_portile 0.5.3
Using nokogiri 1.6.1
Using akami 1.2.1
Using buff-ruby_engine 0.1.0
Using buff-shell_out 0.1.1
Installing hashie 2.1.1 (was 2.1.0)
Using chozo 0.6.1
Using multipart-post 1.2.0
Using faraday 0.8.9
Using minitar 0.5.4
Using rbzip2 0.2.0
Using retryable 1.3.5
Using buff-extensions 0.5.0
Using varia_model 0.3.2
Using buff-config 0.4.0
Using buff-ignore 1.1.1
Using hitimes 1.2.1
Using timers 2.0.0
Using celluloid 0.14.1
Using nio4r 1.0.0
Using celluloid-io 0.14.1
Using erubis 2.7.0
Using json 1.8.1
Using mixlib-log 1.6.0
Using mixlib-authentication 1.3.0
Using net-http-persistent 2.9.4
Using net-ssh 2.8.0
Using solve 0.8.2
Using ffi 1.9.3
Using gssapi 1.0.3
Using httpclient 2.3.4.1
Using little-plugger 1.1.3
Using logging 1.8.2
Using rubyntlm 0.1.1
Using rack 1.5.2
Using httpi 0.9.7
Using nori 1.1.5
Using wasabi 1.0.0
Using savon 0.9.5
Using uuidtools 2.1.4
Using winrm 1.1.3
Using ridley 1.5.3
Using thor 0.18.1
Using berkshelf 2.0.14
Installing moneta 0.6.0
Installing chef-zero 1.7.3 (was 2.0.2)
Using diff-lcs 1.2.5
Using highline 1.6.21
Using mime-types 1.25.1
Using mixlib-cli 1.4.0
Using mixlib-config 2.1.0
Using mixlib-shellout 1.4.0
Using net-ssh-gateway 1.2.0
Using net-ssh-multi 1.2.0
Using ipaddress 0.8.0
Using systemu 2.5.2
Using yajl-ruby 1.2.0
Installing ohai 6.22.0 (was 7.0.2)
Using coderay 1.1.0
Using method_source 0.8.2
Using slop 3.5.0
Using pry 0.9.12.6
Installing puma 1.6.3
Using rest-client 1.6.7
Installing chef 11.10.4 (was 11.12.2)
Using knife-solo 0.4.1
Using bundler 1.6.1
Your bundle is updated!

chefのバージョンが変わっているのを確認。
$ bundle exec chef-solo -v
Chef: 11.10.4

2014年5月8日木曜日

rbenv-default-gemsでruby install時に必要なgemが最初から入ってるようにする

Macにrbenvでrubyを入れたので、次はrbenv-default-gemsを使って、
rubyのバージョンを指定してinstallした時に、必要なgemも一緒に入るようにしてみました。

まずはbrewでrbenv-default-gemsをインストール
$ brew install rbenv-default-gems
==> Downloading https://github.com/sstephenson/rbenv-default-gems/archive/v1.0.0.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-default-gems/1.0.0: 4 files, 16K, built in 2 seconds

gem listで今入ってるのを表示
$ gem list
 
*** LOCAL GEMS ***
 
bigdecimal (1.2.4)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.3)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.1.0)

default-gemsファイルを生成してbundlerと記述。
$ ls -al ~/.rbenv/default-gems
ls: /Users/xxxx/.rbenv/default-gems: No such file or directory
 
$ echo "bundler" >  ~/.rbenv/default-gems
 
$ ls -al ~/.rbenv/default-gems
-rw-r--r--  1 xxxx  xxxx  8  4 11 15:49 /Users/xxxx/.rbenv/default-gems

rbenvでバージョン2.1.1をインストール
$ rbenv install 2.1.1
rbenv: /Users/xxxx/.rbenv/versions/2.1.1 already exists
continue with installation? (y/N) y
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/xxxx/.rbenv/versions/2.1.1
 
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /Users/xxxx/.rbenv/versions/2.1.1
 
Fetching: bundler-1.6.1.gem (100%)
Successfully installed bundler-1.6.1
Parsing documentation for bundler-1.6.1
Installing ri documentation for bundler-1.6.1
Done installing documentation for bundler after 2 seconds
1 gem installed

gem listを表示すると、bundlerが追加されている。
$ gem list
 
*** LOCAL GEMS ***
 
bigdecimal (1.2.4)
bundler (1.6.1)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.3)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.1.0)

2014年5月3日土曜日

Macのrubyバージョンをrbenvであげる

Macには初めからrubyがインストールされていますが、最新のバージョンを入れたいのと、
複数のバージョンを入れたいのでrbenvを入れたいと思います。

rbenbはhomebrewで入れられます。
$ brew install rbenv
==> Downloading https://github.com/sstephenson/rbenv/archive/v0.4.0.tar.gz
######################################################################## 100.0%
==> Caveats
To use Homebrew's directories rather than ~/.rbenv add to your profile:
  export RBENV_ROOT=/usr/local/var/rbenv
 
To enable shims and autocompletion add to your profile:
  if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
==> Summary
🍺  /usr/local/Cellar/rbenv/0.4.0: 31 files, 152K, built in 3 seconds

以下のコマンドを実行する。
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

次にruby-buildを入れます。これもhomebrewで入ります。
$ brew install ruby-build
==> Installing dependencies for ruby-build: autoconf, pkg-config, openssl
==> Installing ruby-build dependency: autoconf
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/autoconf-2.69.mavericks.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M
==> Installing ruby-build dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.28: 10 files, 604K
==> Installing ruby-build dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1g.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.1g.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.
 
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
 
The OpenSSL provided by OS X is too old for some software.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
 
==> Summary
🍺  /usr/local/Cellar/openssl/1.0.1g: 429 files, 15M
==> Installing ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20140408.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20140408: 114 files, 488K, built in 2 seconds

次に関連するrbenv-gemset、rbenv-gem-rehash、readline、apple-gcc42をhomebrewで入れます。
$ brew install rbenv-gemset
==> Downloading https://github.com/jf/rbenv-gemset/archive/v0.5.6.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-gemset/0.5.6: 12 files, 52K, built in 3 seconds

$ brew install rbenv-gem-rehash
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/archive/v1.0.0.tar.gz
######################################################################## 100.0%
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/commit/0756890cfd9c7bbbdde38560fe81626a0c5769bd.patch
######################################################################## 100.0%
==> Patching
patching file README.md
Hunk #1 succeeded at 23 (offset -2 lines).
patching file etc/rbenv.d/exec/~gem-rehash.bash
patching file gems/rbenv-gem-rehash-1.0.0/lib/rubygems_plugin.rb
patching file rubygems_plugin.rb
patching file specifications/rbenv-gem-rehash-1.0.0.gemspec
==> Caveats
If the GEM_PATH environment variable is undefined, rbenv-gem-rehash must
first execute the gem env gempath command to retrieve RubyGems' default path
so that it can can append to the path rather than override it. This can take
a while--from a few hundred milliseconds on MRI to several seconds on
JRuby--so the default path for the current Ruby version is cached to the
filesystem the first time it is retrieved.
==> Summary
🍺  /usr/local/Cellar/rbenv-gem-rehash/1.0.0: 7 files, 24K, built in 3 seconds

$ brew install readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.2.4.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.2.4.mavericks.bottle.2.tar.gz
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.
 
OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include
 
==> Summary
🍺  /usr/local/Cellar/readline/6.2.4: 31 files, 1.6M

$ brew install apple-gcc42
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
==> Caveats
NOTE:
This formula provides components that were removed from XCode in the 4.2
release. There is no reason to install this formula if you are using a
version of XCode prior to 4.2.
 
This formula contains compilers built from Apple's GCC sources, build
5666.3, available from:
 
  http://opensource.apple.com/tarballs/gcc
 
All compilers have a `-4.2` suffix. A GFortran compiler is also included.
==> Summary
🍺  /usr/local/Cellar/apple-gcc42/4.2.1-5666.3: 104 files, 75M

homebrewのインストールが終わった状態はこんな感じです。
$ brew list
apple-gcc42  mysql   pcre   rbenv-gem-rehash ruby-build
autoconf  nginx   pkg-config  rbenv-gemset  tomcat
brew-cask  openssl   rbenv   readline

ではrubyのバージョンをあげたいと思います。
まずは今のバージョンがこちら。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

rbenbで入れられるバージョンが以下のものです。
$ rbenv install -l
Available versions:
  1.8.6-p383
  1.8.6-p420
  1.8.7-p249
  1.8.7-p302
  1.8.7-p334
  1.8.7-p352
  1.8.7-p357
  1.8.7-p358
  1.8.7-p370
  1.8.7-p371
  1.8.7-p374
  1.8.7-p375
  1.9.1-p378
  1.9.1-p430
  1.9.2-p0
  1.9.2-p180
  1.9.2-p290
  1.9.2-p318
  1.9.2-p320
  1.9.2-p326
  1.9.3-dev
  1.9.3-p0
  1.9.3-p125
  1.9.3-p194
  1.9.3-p286
  1.9.3-p327
  1.9.3-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-preview1
  1.9.3-rc1
  2.0.0-dev
  2.0.0-p0
  2.0.0-p195
  2.0.0-p247
  2.0.0-p353
  2.0.0-p451
  2.0.0-preview1
  2.0.0-preview2
  2.0.0-rc1
  2.0.0-rc2
  2.1.0
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.1
  2.2.0-dev
  jruby-1.5.6
  jruby-1.6.3
  jruby-1.6.4
  jruby-1.6.5
  jruby-1.6.5.1
  jruby-1.6.6
  jruby-1.6.7
  jruby-1.6.7.2
  jruby-1.6.8
  jruby-1.7.0
  jruby-1.7.0-preview1
  jruby-1.7.0-preview2
  jruby-1.7.0-rc1
  jruby-1.7.0-rc2
  jruby-1.7.1
  jruby-1.7.10
  jruby-1.7.11
  jruby-1.7.2
  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  jruby-9000+graal-dev
  jruby-9000-dev
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-1.0.0
  mruby-dev
  rbx-1.2.4
  rbx-2.0.0
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  rbx-2.2.2
  rbx-2.2.3
  rbx-2.2.4
  rbx-2.2.5
  rbx-2.2.6
  ree-1.8.6-2009.06
  ree-1.8.7-2009.09
  ree-1.8.7-2009.10
  ree-1.8.7-2010.01
  ree-1.8.7-2010.02
  ree-1.8.7-2011.03
  ree-1.8.7-2011.12
  ree-1.8.7-2012.01
  ree-1.8.7-2012.02
  topaz-dev

バージョン2.1.1を入れてみます。
$ rbenv install 2.1.1
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/xxxx/.rbenv/versions/2.1.1
 
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /Users/xxxx/.rbenv/versions/2.1.1

まだこの段階ではバージョンは変わっていません。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

選べるrubyのバージョンを確認すると、まだ初期から入っているrubyが使われています。
$ rbenv versions
* system (set by /Users/xxxx/.rbenv/version)
  2.1.1

デフォルトで使うバージョンを変更します。
$ rbenv global 2.1.1

$ rbenv versions
  system
* 2.1.1 (set by /Users/xxxx/.rbenv/version)

あれ、変わりません。。。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

ログアウトしてコンソール立ち上げ直して再度やったらバージョン変わりました。
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]


参考URL
http://qiita.com/skinoshita/items/2cf0c27a6ff4f0602568
https://gist.github.com/mochiz/4736183
http://www.d-wood.com/blog/2014/03/20_5847.html

2014年5月1日木曜日

Play FrameworkのSlickのevolutionでカラム追加

Play FrameworkのSlickのevolutionで管理してるテーブルにカラムを追加してみました。

バージョン
Play Framework 2.2.2
slick 2.0.1
play-slick 0.6.0.1

前回作ったclassに変数upd_dateとcountを追加
case class Twitter(id: Int, word: String, ins_date: Date, upd_date: Date, count:Int)

class Twitters(tag: Tag) extends Table[Twitter](tag,"twitter"){
  def id = column[Int]("id",O.PrimaryKey,O.AutoInc)
  def word = column[String]("word",O.NotNull)
  def ins_date = column[Date]("ins_date",O.NotNull)
  def upd_date = column[Date]("upd_date",O.NotNull)
  def count = column[Int]("count",O.NotNull)
  def * = (id,word,ins_date,upd_date,count) <> (Twitter.tupled,Twitter.unapply)
}
その他、呼び出し元や取得先など関係するところを修正する。
アプリケーションを起動してhttp://localhost:9000/にアクセスするとコンソールに以下が表示

[info] Compiling 2 Scala sources to /Users/xxxx/play/sample/target/scala-2.10/classes...
[info] Compiling 4 Scala sources to /Users/xxxx/play/sample/target/scala-2.10/classes...
[info] play - database [default] connected at jdbc:h2:file:database/play
[info] o.r.Reflections - Reflections took 107 ms to scan 1 urls, producing 9 keys and 10 values 
[error] application - ! @6i1gdpfi5 - Internal server error, for (GET) [/] -> 
play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution![An SQL script need to be run on your database.]
 at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1$$anonfun$apply$1.apply$mcV$sp(Evolutions.scala:486) ~[play-jdbc_2.10.jar:2.2.2]
 at play.api.db.evolutions.EvolutionsPlugin.withLock(Evolutions.scala:507) ~[play-jdbc_2.10.jar:2.2.2]
 at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:461) ~[play-jdbc_2.10.jar:2.2.2]
 at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:459) ~[play-jdbc_2.10.jar:2.2.2]
 at scala.collection.immutable.List.foreach(List.scala:318) ~[scala-library.jar:na]
 at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:459) ~[play-jdbc_2.10.jar:2.2.2]
[info] a.e.s.Slf4jLogger - Slf4jLogger started

画面上に以下のものが表示される。
Database 'default' needs evolution!
An SQL script will be run on your database - [Apply this script now!]

[Apply this script now!]ボタンを実行すると正常な画面が表示される。
テーブルにカラムも追加されている。
alterではなくて、dropしてcreateしてる模様
コンソールには以下が表示される。
[info] c.j.b.BoneCP - Shutting down connection pool...
[info] c.j.b.BoneCP - Connection pool has been shutdown.
[info] play - database [default] connected at jdbc:h2:file:database/play
[info] o.r.Reflections - Reflections took 11 ms to scan 1 urls, producing 9 keys and 10 values

開発中にカラムの変更入ったときとかは便利ですね。
そもそもそういうこと起きないように開発したいですが。。。