CentOSのGitを最新版にアップデートする
昨年12月19日に出ていたGitの脆弱性の件で、Gitを最新版にアップデートしようとして悩んだのでメモしておく。
MacでHomebrewを使っている場合はbrew update
してbrew upgrade git
すれば最新版になるので楽なのだが、CentOSのGitはソースインストールしないと最新版にはならないらしい。
Gitの最新バージョンの確認
リリースログを見ると「2.2.1」が最新版らしいので、今回はgit-2.1.1.tar.gz
をDLすることにした。
- リリースログ https://github.com/git/git/tree/master/Documentation/RelNotes
- DL可能なGitファイル https://www.kernel.org/pub/software/scm/git/
環境
いつもの通りVagrantを利用している。
[vagrant@localhost]$ cat /etc/redhat-release CentOS release 6.4 (Final) [vagrant@localhost]$ git --version git version 1.7.1
手順
既存のgitを削除する。
[vagrant@localhost]$ sudo yum -y remove git
スーパーユーザになる。
[vagrant@localhost]$ su - パスワード:
各種パッケージをインストールする。
※パッケージのインストール漏れがあるとmake prefix=/usr/local all
実行時にエラーが出る。
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker
最新版のGitをDLする。
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz
DLしたファイルの解凍する。
[root@localhost ~]# tar zxvf git-2.2.1.tar.gz [root@localhost ~]# ls git-2.2.1 git-2.2.1.tar.gz [root@localhost ~]# cd git-2.2.1
インストール先を設定するため、--prefix
オプションを利用してプレフィックスを設定する。
[root@localhost git-2.2.1]# ./configure --prefix=/usr/local
ビルドを実行する。
[root@localhost git-2.2.1]# make prefix=/usr/local all
ビルドしたものをインストールする。
[root@localhost git-2.2.1]# make prefix=/usr/local install
Gitのバージョンを確認する。
[root@localhost git-2.2.1]# git --version git version 2.2.1
最新版になった!
参照
VimでScssファイルをシンタックスハイライトさせる
.vimrc
ファイルに下記を追記する。
au BufRead,BufNewFile *.scss set filetype=sass
こんな感じに。
参照
サーバー(CentOS 6.4)の時刻を日本標準時刻に合わせる
環境
/etc/localtimeの設定
$ sudo cp -p /usr/share/zoneinfo/Japan /etc/localtime
/etc/localtime
ファイルの設定をしておかないと、日本標準時刻が設定されない。
NTPサーバーのインストール
NTP(Network Time Protocol)とは、ネットワーク内の時刻を同期させるのに利用する通信プロトコルで、NTPを使用するすべてのホストの時刻をUTC(Coordinated Universal Time、協定世界時)に合わせるために利用している。
$ sudo yum -y install ntp
NTPサーバーの日付を設定
NTPサーバー「ntp.nict.jp*1」へ日付と時刻を問い合わせ、正確な日付と時刻を、NTPを使用しているローカルホストに同期させる。
ntpdateコマンド:ntpdate [オプション] NTPサーバー
$ sudo ntpdate ntp.nict.jp 25 Dec 03:08:27 ntpdate[7711]: adjust time server 133.243.238.244 offset -0.105988 sec
/etc/ntp.confの編集
設定ファイルに、参照するNTPサーバーのIPアドレスをserverオプションで指定する。
$ sudo vi /etc/ntp.conf
「centos.pool.ntp.org」の行をコメントアウトし、「server -4 ntp 〜」の行を追加する。
# server 0.centos.pool.ntp.org iburst # server 1.centos.pool.ntp.org iburst # server 2.centos.pool.ntp.org iburst # server 3.centos.pool.ntp.org iburst server -4 ntp.nict.jp server -4 ntp1.jst.mfeed.ad.jp server -4 ntp2.jst.mfeed.ad.jp server -4 ntp3.jst.mfeed.ad.jp
ntpdデーモン*2の起動
$ sudo service ntpd start Starting ntpd: [ OK ]
ntpqコマンド(オプションについてはここを参照)でNTPサーバが動作しているかを確認できる。
$ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *vps.jre655.com 10.84.87.146 2 u 5 64 1 5.580 -65.777 0.658 s97.GchibaFL4.v 61.114.187.55 2 u 4 64 1 8.820 -66.847 2.275 chobi.paina.jp 131.113.192.40 2 u 4 64 1 5.490 -65.686 0.847 x.ns.gin.ntt.ne 103.1.106.69 2 u 3 64 1 4.449 -68.201 1.016
自動起動の設定
サーバー起動時にntpdを自動的に起動させるため、chkconfigコマンドを実行しておく。
$ sudo chkconfig ntpd on $ chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
結果
設定前
$ ls -all 合計 16 -rw-rw-r-- 1 vagrant vagrant 2326 12月 24 07:49 2014 rails_helper.rb drwxrwxr-x 2 vagrant vagrant 4096 12月 24 11:20 2014 requests -rw-rw-r-- 1 vagrant vagrant 4237 12月 24 08:11 2014 spec_helper.rb
設定後
$ ls -all 合計 16 -rw-rw-r-- 1 vagrant vagrant 2326 12月 24 16:49 2014 rails_helper.rb drwxrwxr-x 2 vagrant vagrant 4096 12月 24 20:20 2014 requests -rw-rw-r-- 1 vagrant vagrant 4237 12月 24 17:11 2014 spec_helper.rb
日本標準時刻が設定された。
参照
ArgumentError: rack-test requires a rack application, but none was given
2014/12/19追記:
前回第3章を進めていた時は spec_helper.rb が存在しており、今回進めた時は spec_helper.rb がなかったということで、単純にrails generate rspec:install
を実行し忘れていたのが原因。
$ rails generate rspec:install create .rspec exist spec create spec/spec_helper.rb
『パーフェクトRuby on Rails』(p244)を読むと下記のように書いてあった。
spec_helper.rb は 、RSpec を利用したテストを行う際に利用する設定ファイル
rails generate rspec:install
して生成された spec_helper.rb の内容
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| # ## Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = "random" end
app/views/static_pages/home.html.erb を修正せずにテストコードを実行すると、Railsチュートリアルの実行結果と同じ内容になる。
$ bundle exec rspec spec/requests/static_pages_spec.rb F Failures: 1) Static pages Home page should have the content 'Sample App' Failure/Error: expect(page).to have_content('Sample App') expected #has_content?("Sample App") to return true, got false # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' Finished in 0.03245 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/static_pages_spec.rb:6 # Static pages Home page should have the content 'Sample App' Randomized with seed 34550
Railsチュートリアル第3章のリスト3.11「Homeページ用コード」を追加後、テストコードを実行しようとしたが、図3.4のようにテストが成功しなかった。
修正前
各ファイルの設定
Gemfile
(省略) group :test do gem 'selenium-webdriver', '2.35.1' gem 'capybara', '2.1.0' end (省略)
spec/requests/static_pages_spec.rb
require 'spec_helper' describe "Static pages" do describe "Home page" do it "should have the content 'Sample App'" do visit '/static_pages/home' expect(page).to have_content('Sample App') end end end
spec/spec_helper.rb
require 'capybara/rspec' RSpec.configure do |config| config.include Capybara::DSL end
テストコードの実行
app/views/static_pages/home.html.erb は修正済みで Failures:1 は出ないはずだが、テストが成功しない。
※そして何故かRailsチュートリアルの図3.3とメッセージが異なっている・・・。
$ bundle exec rspec spec/requests/static_pages_spec.rb Static pages Home page An error occurred in an after hook ArgumentError: rack-test requires a rack application, but none was given occurred at /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rack_test/driver.rb:16:in `initialize' should have the content 'Sample App' (FAILED - 1) Failures: 1) Static pages Home page should have the content 'Sample App' Failure/Error: visit '/static_pages/home' ArgumentError: rack-test requires a rack application, but none was given # ./spec/requests/static_pages_spec.rb:7:in `block (3 levels) in <top (required)>' Finished in 0.00145 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/static_pages_spec.rb:6 # Static pages Home page should have the content 'Sample App'
修正後
解決方法
spec/spec_helper.rb に下記を追記する。
ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails'
spec/spec_helper.rb
require 'capybara/rspec' RSpec.configure do |config| config.include Capybara::DSL end # 追記した設定 ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails'
テストコードの実行
$ bundle exec rspec spec/requests/static_pages_spec.rb Static pages Home page should have the content 'Sample App' Finished in 0.03796 seconds 1 example, 0 failures
参照
An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue.
久しぶりにRails Tutorial 3章のおさらいをしようしてbundle update
すると、前回と同じようなメッセージが出てしまった。
前回と同様に下記を実行したのだが、bundle update
で失敗してしまう。
$ sudo yum install libxml2-devel libxslt-devel $ gem install nokogiri $ bundle update (省略) An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.5'` succeeds before bundling.
メッセージの指示通りにgem install nokogiri -v '1.6.5'
してみたが、やはりエラーのまま。
しかも前回からnokogiriのバージョンが上がっている。
解決方法
システムのライブラリーを使用するように設定する。
$ bundle config build.nokogiri --use-system-libraries
上記の設定をするだけで解決!
$ bundle update Fetching gem metadata from https://rubygems.org/......... Resolving dependencies... (省略) Your bundle is updated! Gems in the group production were not installed. $ bundle install (省略) Your bundle is complete! Gems in the group production were not installed. Use `bundle show [gemname]` to see where a bundled gem is installed.
参照
Pepper開発体験ワークショップ(SDK基本編#1)に参加してきました #pepper_3331
Pepperに当選者を選んでもらったPyConの抽選会や、実際にPythonでプログラミングした方の話を聞く機会があり(人づてだが)、「面白そう!」と思ったのが参加のきっかけ。本当に興味があるというだけで参加しました。会社でPepperを導入する予定だったり、研究分野での利用を考えていたり、参加者の中にはすでにPepperを触っている方もいたようです。
会場となったアルデバラン・アトリエ秋葉原は、旧練成中学校を利用したアートセンター「3331 Arts Chiyoda」。
同じフロアには「はんだづけカフェ」が!
たくさんのPepperが待機中。
基本編ということでSDK「Choregraphe(コレグラフ)」の説明をしていただき、各テーブルごとに1体のPepperを共有して実際に動かしてみる、ということをやりました。
私が中学生の時に家庭教師をしてくれた方がロボット工学を専門としていた大学院生だったのですが、まさか自分でロボットのプログラミングが簡単にできるようになるとは・・・。感慨深いです。
HomebrewでインストールしたMySQLを自動起動させる
brew services
コマンドは利用できないということで、launchctl
コマンドを利用してMySQLを自動起動させる。
これらの記事の続き。
- HomebrewでインストールしたMySQLを自動起動させる - ponkiti's blog
- brew services コマンドで Error: Unknown command: services というメッセージが出る - ponkiti's blog
MySQLのプロパティリストを確認
プロパティリストの格納場所を調べる。
インストール時に格納先を指定しなかった場合は、一律で/usr/local/Cellar
以下のディレクトリにインストールされるのだろうか?brew link mysql
はMySQLのインストール先を調べるのに使っているが、いいやり方でない・・・。
$ brew link mysql Warning: Already linked: /usr/local/Cellar/mysql/5.6.21 To relink: brew unlink mysql && brew link mysql
/usr/local/Cellar/mysql/5.6.21
ディレクトリ直下にhomebrew.mxcl.mysql.plist
ファイルが作成されている状態。.plist
とはプロパティリストの略で、 xml形式の設定ファイルのこと。
$ ls /usr/local/Cellar/mysql/5.6.21 (省略) homebrew.mxcl.mysql.plist
プロパティリストをLaunchAgentsディレクトリにコピー
homebrew.mxcl.mysql.plist
ファイルを~/Library/LaunchAgents/
ディレクトリにコピーする。
cp /usr/local/Cellar/mysql/5.6.21/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
プロパティリストの編集
homebrew.mxcl.mysql.plist
ファイルを編集する。
Xcodeで編集する場合
Xcodeでファイルを開き、KeepAlive
をNo
にしておく。
ファイルを直接編集する場合
Vimで直接編集してもいいはず・・・?KeepAlive
の設定を<true/>
から<false/>
に変更する。
変更前
$ cat ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist (省略) <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> (省略)
変更後
$ cat ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist (省略) <plist version="1.0"> <dict> <key>KeepAlive</key> <false/> (省略)
launchctl loadの実行
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist