PHP+OpenSSLバージョンアップ

PHP+OpenSSLバージョンアップ

概要

ベリトランスモジュールのバージョンアップに際して
2016 年以内にSSL v3.0/TLS 1.0 無効化処理が必須となりました。

世界的なセキュリティ対策の一環として必須事項なので
ベリトランス以外の決済も、また決済以外でもシステムの対策必須です。

Google、SSL 3.0 の脆弱性「POODLE」を公表、SSL 3.0 は今後サポート廃止の意向

EC-CUBE でベリトランスの決済モジュールでは
PHP から OpenSSL ライブラリを利用して決済へ通信を実施しています。

その PHP の OpenSSL ライブラリを 1.0.1i 以上(最新が推奨)に
バージョンアップする必要があります。

対応する ToDo としては以下になります。

TLS1.1 以上を利用するには openssl 1.0.1i 以上を利用する必要アリ
→ openssl バージョンアップ (1.0.1i 以上)
→ PHP の再コンパイルし OpenSSL ライブラリ(1.0.1i 以上)をバージョンアップ

上記対応をまとめました。

※ Apache の SSL v3.0/TLS1.0 利用不可設定は別途
ググればすぐ出てきます ♪

環境

  • CentOS release 6.6 (Final)
  • PHP 5.3.9
  • openssl 1.0.1g

手順

PHP で利用している OpenSSL のライブラリバージョン確認

これから PHP をコンパイルし直すので
OpenSSL support が disable でも問題ないです。

※今回では既にインストール済みであるというケースを想定しています。

1
2
3
4
5
6
# php -i | grep OpenSSL

OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1g 28 Jan 2016
OpenSSL Header Version => OpenSSL 1.0.1g 28 Jan 2016
OpenSSL support => enabled

PHP でで利用される OpenSSL Library, Header Version が 1.0.1g であることが確認できました。

既存 openssl バックアップ

既にインストール済みかと思いますので
現行バージョンを一旦退避します。

1
2
3
4
5
6
7
8
# openssl version
1.0.1g

# which openssl
/usr/local/bin/openssl

// 名前変更でバックアップとして残す
# mv /usr/local/bin/openssl /usr/local/bin/openssl1.0.1g

何か不具合が発生した場合にまきもどせるように、念のためバックアップをとりました。

openssl バージョンアップ

ソースからビルドします。

1
2
3
4
5
6
7
# cd /usr/local/src
# wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz
# tar xzvf openssl-1.0.2f.tar.gz
# cd openssl-1.0.2f
# ./config --prefix=/usr/local shared -fPIC
# make
# make install

-fPIC は 動的共有オブジェクト(DSO)として mod_ssl をビルドし
PHP のバイナリ実行ファイルからフックして利用する為に必要、
と言ったところでしょうか。

openssl バージョンアップ確認

正しくバージョンアップされていることを確認しました。

1
2
3
# openssl version

OpenSSL 1.0.2f 28 Jan 2016

PHP 再コンパイル

  • 既存 PHP がどのように configure されているか確認
1
2
3
# php -i | grep config

Configure Command => './configure' '--enable-mbstring' '--enable-zend-multibyte' '--with-mysql' '--with-mysqli' '--enable-mbregex' '--with-gd' '--with-jpeg-dir=/usr/lib' '--with-png-dir=/usr/lib' '--with-freetype-dir=/usr/lib' '--with-zlib-dir' '--with-libdir=lib64' '--enable-soap' '--with-apxs2=/etc/httpd/bin/apxs' '--with-openssl=/usr/local'

--with-openssl がない場合は上記のように追加します。
今回は既に指定済みです。

上記の conigure 情報を利用して
–with-openssl があることを確認した上で
再コンパイルします。

  • 再コンパイル
1
2
3
4
# cd /usr/local/src/php-5.3.9
# ./configure --enable-mbstring --enable-zend-multibyte --with-mysql --with-mysqli --enable-mbregex --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib --with-zlib-dir --with-libdir=lib64 --enable-soap --with-apxs2=/etc/httpd/bin/apxs --with-openssl=/usr/local
# make
# make install

以下のようなエラーが出る場合は、手順)「openssl バージョンアップ」をご確認下さい。
新たに openssl をソースからコンパイルしてビルドしたときなどに出るエラーです。

1
configure: error: Cannot find OpenSSL's <evp.h>

PHP で利用する OpenSSL ライブラリのバージョン確認

1
2
3
4
5
6
# php -i | grep OpenSSL

OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.2f 28 Jan 2016
OpenSSL Header Version => OpenSSL 1.0.2f 28 Jan 2016
OpenSSL support => enabled

OpenSSL Library, Header Version が共に指定通りとなりました。

以上です。

Install latest Git on CentOS.

Install latest Git on CentOS.

Environment Information

  • CentOS release 6.6 (Final)

Install required modules

1
# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

Compile & Install

Please access the below url, get latest archive.
Official Repository

1
2
3
4
5
6
# cd /usr/local/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.7.2.tar.gz
# tar xvf git-2.7.2.tar.gz
# cd git-2.7.2
# make prefix=/usr/local all
# make prefix=/usr/local install

Show git version.

1
2
3
# git --version

git version 2.7.2

Thank.

MacOSX python 3.4.3 インストール

概要

機械学習養成読本という素晴らしい本を頂き早速学習を深めています。

115ページ 第2部 第1章
「Pythonのインストール」がすんなりいかなかったのでメモです。

pyenv install 3.4.3 を実行すると以下のようなエラー出ませんでしたか?

1
2
3
4
5
6
7
8
9
Downloading Python-3.4.3.tgz...
-> https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
Installing Python-3.4.3...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems

BUILD FAILED (OS X 10.11.2 using python-build 20150519)

環境

  • MacOSX ElCapitan 10.11.2(15C50)
  • Homebrew 0.9.5
1
2
3
4
5
6
7
8
$ brew install sqlite3
$ brew install readline
$ brew install openssl
$ brew install pyenv
$ export CFLAGS="-I$(brew --prefix openssl)/include"
$ export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix sqlite3)/lib"
$ export CPPFLAGS="-I$(brew --prefix sqlite3)/include"
$ pyenv install 3.4.3

以下コンパイラに渡す変数の設定が肝でした。

  • CFLAGS
  • LDFLAGS
  • CPPFLAGS

10.3 Variables Used by Implicit Rules

気をつければいけないのはMacにデフォルトでインストールされているPython
Python のPATH(/usr/local/bin)から外す

1
2
3
4
$ which python
/usr/local/bin/python

$ mv /usr/local/bin/python /usr/local/bin/python2.7.10

pip もインストール済みであるならば同様にパスから外す。

1
2
3
4
$ which pip
/usr/local/bin/pip

$ mv /usr/local/bin/pip /usr/local/bin/pip2.7

他にPythonのPATHをexportしていなければ
pyenv でインストールしたPythonにパスが通るはずです。

1
2
$ which python
/Users/kenzo/.pyenv/shims/python ←このように表示されればOK♪

Pythonエラー対応: UnicodeEncodeError: 'ascii' codec can't encode characters

結論

Pythonの文字コードを utf-8 に設定する。

概要

python で以下のような画像URLから画像をダウンロードする処理を実装した所
掲題のエラーが発生しました。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- coding: utf-8 -*-

import urllib
import urllib2
import os.path
import sys
from HTMLParser import HTMLParser

def download(url):
img = urllib.urlopen(url)
localfile = open(os.path.basename(url),'wb')
localfile.write(img.read())
img.close()
localfile.close()
  • 具体的にはここでこけてました。
1
localfile.write(img.read())

環境

  • CentOS Linux release 7.0.1406 (Core)
  • Python 2.7.5

文字コード確認

以下対話式で確認してみると ascii と表示されました。
これを utf-8 に変更します。

1
2
3
4
$ python
>>> import sys
>>> sys.getdefaultencoding()
'ascii'

pip パス確認

バージョン確認時にパスが出力されます。

1
2
$ pip --version
pip 7.1.0 from /usr/lib/python2.7/site-packages (python 2.7)

site-packages配下に sitecustomize.py を作成

1
vi /usr/lib/python2.7/site-packages/sitecustomize.py
1
2
import sys
sys.setdefaultencoding('utf-8')

上記内容で保存。

再度文字コード確認

utf-8 になりました。

1
2
3
4
$ python
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

これで掲題のエラーが解決されました。

no-ipでAWSインスタンスの動的ip更新対応 ~いつも同じドメイン名でアクセスしたい~

概要

AWSの起動停止をするとElasticIPを設定していない限り
Public IPが変更されてしまいます。

ElasticIPは設定するとAWSを停止していても費用が発生します。

検証用環境など一時的に利用するインスタンスについて
起動時にIPが変更したことを関係者に周知するなどの手間が掛かります。

その為No-IPを利用しドメインを固定しIP変更に対応するようにしました。

No-IPは無料のドメインサービスで動的IP変更を検知するLinux用モジュールも配布しています。

環境

  • Amazon Linux AMI release 2015.09
  • noip 2.1.9

手順

まずnoipサイトで会員登録し利用したいドメインを登録します。
ipはとりあえず適当で良いです。

http://www.noip.com/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// rootユーザで実行
$ sudo su
# cd /usr/local/src

// noipモジュール
# wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
# tar xzf noip-duc-linux.tar.gz
# cd noip-2.1.9
# make
# make install

// 起動スクリプト作成
# cp redhat.noip.sh /etc/init.d/noip
# chmod 755 /etc/init.d/noip

// 起動設定
# /sbin/chkconfig noip on

// 起動
# /etc/init.d/noip start

起動後、no-ipのコンソール上で指定ドメインのIPが
1分もしない程度で切り替わっていることが確認できます。

今後

No-IPはMicroSoftによりマルウェアの温床となっておりユーザを保護すべく
22のNO-IPドメイン差し止めを連邦裁判所に申し立て、受理されましたが

No-IP側としては相談していただければ対応もできた、とし申し立て後
対応し随時ドメインの復活を果たしています。

ある程度セキュリティを加味して利用する必要がありますね。
今の所、AWSのセキュリティグループで特に外部アクセスはなく
問題なく動作しています。

また、
以下のようなGREEさんの記事がありました。

AWS EC2 での最強の Public IP 取得方法

内部関係者に聞いてみたいと思います。

===追記===

GREEさんの記事の件、内部関係者に聞いた所ubuntuのみで利用しているそうです。

CentOS7用 Revel(Golang)フレームワークの起動スクリプト 書いてみた。

CentOS7用 Revel(Golang)フレームワークの起動スクリプト 書いてみた。

起動スクリプト作成

まず成果物から

1
# vim /usr/lib/systemd/system/revel.service
1
2
3
4
5
6
7
8
9
10
[Unit]
Description=RevelBuildScript
After=nginx.service mysqld.service

[Service]
Type=simple
ExecStart=/bin/bash /var/golang/run.sh

[Install]
WantedBy=multi-user.target

※After … 上記では nginx と mysqld 起動後に revel を起動させるという設定です。

※ExecStart … /bin/bash /var/golang/run.sh については
以前の記事でローカルビルドによる
デプロイ方法を採用しているというお話をしましたが
その際に作成される run.sh のパスを指しています。

起動設定

1
# systemctl enable revel.service

起動

1
# systemctl start revel.service

停止

1
# systemctl start revel.service

以上です。

導入経緯

AWS での運用をしていると検証環境は
検証時のみに利用し余計なコストは掛けたくないものです。

なので、しょっ中、起動・停止を繰り返します。

Revel フレームワークは起動スクリプトが標準装備されていない為
インスタンス起動時に手動で起動する手間が発生していました。

その為、デザインの修正でもシステムさんお願いします〜というような依頼があり
相互に手間が発生していたのでその解決として作成しました。

現在は Slack 経由で hubot から Jenkins ジョブを実行させ
Revel の乗ってる AWS インスタンスの起動・停止できるようにしています。

ip も ElasticIP は使用せず、No-IP を利用して Public IP が変更されても
同ドメインでアクセスできるようにしています。

こちらもインスタンス起動時にドメイン管理している No-ip へ Public IP を通知し
動的にドメインと IP を紐付けるようにしています。

http://www.noip.com/

極力費用を抑えた、AWS における検証環境構築の参考にもしていただければと思います。

以上です。

※ 検証環境 はローカル開発環境と異なり、あくまで本番デプロイ前の検証用という認識です。

MySQLトラブルシューティング - mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need (at least one of) the RELOAD privilege(s) for this operation (1227)

概要

以下のように mysqldump コマンド実行時に掲題のエラーが発生しました。

1
2
3
$ mysqldump --lock-all-tables --events -h <host_name> -u <user> -p<password> --no-create-info <db_name> <table, ...> > output.sql

mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need (at least one of) the RELOAD privilege(s) for this operation (1227)

対策

エラー文の通り、RELOAD権限を付与する。

1
2
mysql> GRANT RELOAD ON *.* TO '<user>'@'<host_name>';
mysql> FLUSH PRIVILEGES;

以上

MySQLトラブルシューティング - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

概要

ローカルでMacOSXでMAMPを使っていてある日誤った操作により以下のようなエラーが発生した為
対応まとめました。

1
2
$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

ローカル環境でrootユーザのアクセス権を誤って削除してしまったときなどに発生します。

対策

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// mysql停止
$ service mysqld stop

// rootユーザのアクセス権限が失われている
// → テーブル権限をスキップ(無視)して作業するオプション付きでセーフモードでmysql起動
$ mysqld_safe --skip-grant-tables &

// rootユーザでアクセス
$ mysql -u root

// 現状の権限設定テーブルを空にする
mysql> TRUNCATE TABLE mysql.user;
Query OK, 0 rows affected (0.00 sec)

// 権限反映
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

// rootユーザにlocalhostの全DBアクセス権限付与
mysql> GRANT ALL PRIVILEGES on *.* to root@localhost IDENTIFIED BY '(root's password)' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

// 権限反映
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

// 権限設定確認
mysql> SELECT host, user FROM mysql.user;

// mysql CLIモード停止 (Ctl+c)でもOK
mysql> quit;

// safe modeで起動させたmysql 関連psをkillする
$ ps aux | grep mysql | grep -v grep | awk '{print "kill -9", $2}'|sh

// mysql 起動
$ service mysqld start

// rootユーザでmysqlアクセス
$ mysql -u root -p(root's password)
mysql>

rootユーザに権限が失われお手上げ状態になったとき、困ったときに safe_mode 使えます。

以上

Hubot + Slack on Amazon Linux

Prerequisite

  • Amazon Linux AMI 2015.09.1 (HVM), SSD Volume Type(t2.nano)
  • npm 1.3.6
  • hubot 2.17.0
  • coffeescript 1.10.0

I use t2.nano released at December 2015.

first to do.

  • summarized in the following site.

AWS EC2 Amazon Linuxインスタンス起動後、最初にやることまとめ

Install npm

1
2
3
4
$ sudo yum install -y npm --enablerepo=epel

$ npm -v
1.3.6

Install hubot, coffee-script, yo, generator-hubot

1
2
3
4
5
6
7
$ sudo npm install -g hubot coffee-script yo generator-hubot

$ hubot -v
2.17.0

$ coffee -v
CoffeeScript version 1.10.0

create hubot

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ mkdir mybot
$ cd mybot
$ yo hubot

? ==========================================================================
We're constantly looking for ways to make yo better!
May we anonymously report usage statistics to improve the tool over time?
More info: https://github.com/yeoman/insight & http://yeoman.io
========================================================================== (Y/n) n
_____________________________
/ \
//\ | Extracting input for |
////\ _____ | self-replication process |
//////\ /_____\ \ /
======= |[^_/\_]| /----------------------------
| | _|___@@__|__
+===+/ /// \_\
| |_\ /// HUBOT/\\
|___/\// / \\
\ / +---+
\____/ | |
| //| +===+
\// |xx|

? Owner (User <user@example.com>) tech@xxxxxxxx.jp
? Bot name (mybot) hubot
? Description xxxxxxx's hubot
? Bot adapter slack
...
...
hubot-maps@0.0.2 node_modules/hubot-maps

$ ls
Procfile bin hubot-scripts.json package.json
README.md external-scripts.json node_modules scripts

こんなエラーが出たときは

/root/.config へのアクセス権限がないと言われています。

1
2
3
4
5
6
7
8
9
10
11
Error: EACCES, permission denied '/root/.config'
at Object.fs.mkdirSync (fs.js:654:18)
at sync (/usr/lib/node_modules/yo/node_modules/configstore/node_modules/mkdirp/index.js:71:13)
at Function.sync (/usr/lib/node_modules/yo/node_modules/configstore/node_modules/mkdirp/index.js:77:24)
at Object.create.all.get (/usr/lib/node_modules/yo/node_modules/configstore/index.js:38:13)
at Object.Configstore (/usr/lib/node_modules/yo/node_modules/configstore/index.js:27:44)
at new Insight (/usr/lib/node_modules/yo/node_modules/insight/lib/index.js:37:34)
at Object.<anonymous> (/usr/lib/node_modules/yo/lib/cli.js:156:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
  • 全権限付与
1
2
# mkdir /root/.config
# chmod -R 0777 /root/.config

上記で問題なくyo コマンドが通りました。ほっ(-o-)

  • Initial setting hubot.
Item Value
Owner E-mail address
Bot name same the hubot integrated slack
Descriiption -
Bot adapter slack

Imgur

Install hubot-slack

1
$ sudo npm install hubot-slack --save

modify external-scripts.json

1
2
3
4
5
$ echo '[]' > external-scripts.json

// confirm setting.
$ cat external-scripts.json
[]

Add to bin/hubot

1
$ vim bin/hubot
  • run hubot via port 80
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh

set -e

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

# add start
export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export PORT=80
# add end

exec node_modules/.bin/hubot --name "hubot" "$@"

creat hubot script

1
$ vim scripts/hello.coffee

save the belowing scripts as scripts/hello.coffee

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Description:
# hubot basic command.
#
# Commands:
# hubot who are you - I'm hubot!
# hubot hello
# hubot who am I - You are <user_name>
# hubot what is this <*> - This is <$1>

module.exports = (robot) ->
robot.respond /who are you/i, (msg) ->
msg.send "I'm hubot!"

robot.hear /HELLO$/i, (msg) ->
msg.send "hello!"

robot.respond /who am I/i, (msg) ->
msg.send "You are #{msg.message.user.name}"

robot.respond /what is this (.*)/i, (msg) ->
msg.send "This is #{msg.match[1]}"

run hubot

sudo is required and in order to access http port.
You will require hubot integrated with outside site - ex) JIRA etc…

1
2
3
4
5
$ sudo bin/hubot -a slack

[Wed Jan 13 2016 13:43:08 GMT+0900 (JST)] INFO Connecting...
[Wed Jan 13 2016 13:43:10 GMT+0900 (JST)] INFO Logged in as hubot of RUBY GROUPE, but not yet connected
[Wed Jan 13 2016 13:43:11 GMT+0900 (JST)] INFO Slack client now connected
  • no sudo execution result …(>_<)
    Error occured!!
1
2
3
4
5
6
7
8
9
10
11
12
13
$ bin/hubot -a slack

[Wed Jan 13 2016 16:40:59 GMT+0900 (JST)] INFO Connecting...
[Wed Jan 13 2016 16:40:59 GMT+0900 (JST)] ERROR Error: listen EACCES
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1024:19)
at listen (net.js:1065:10)
at net.js:1147:9
at dns.js:72:18
at process._tickCallback (node.js:442:13)

[Wed Jan 13 2016 16:41:00 GMT+0900 (JST)] INFO Logged in as hubot of RUBY GROUPE, but not yet connected
[Wed Jan 13 2016 16:41:02 GMT+0900 (JST)] INFO Slack client now connected

Invite hubot at Slack

ex) botname=hubot

1
/invite @hubot

Imgur

Input text at Slack

1
2
[me]    hubot hello
[hubot] hello!

Imgur


daemonize hubot

Install forever

1
2
3
4
$ sudo npm install --save forever

$ forever --version
v0.15.1

set path as not root user.

1
2
$ echo 'export PATH=$PATH:/home/<user>/mybot/node_modules/forever/bin' >> ~/.bashrc
$ source ~/.bashrc
  • root user too.
1
2
3
4
5
6
// change to super user.
$ sudo su
# echo 'export PATH=$PATH:/home/<user>/mybot/node_modules/forever/bin' >> ~/.bashrc
# source ~/.bashrc
# echo $PATH
.......:/home/<user>/mybot/node_modules/forever/bin:......

Modify bin/hubot

daemonize start hubot - sudo bin/hubot -a slack

1
$ sudo bin/hubot start

stop daemonized hubot

1
$ sudo bin/hubot stop

restart hubot

1
$ sudo bin/hubot restart

check forever list

1
2
3
4
5
6
$ sudo su
# forever list

info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] sICk coffee node_modules/.bin/hubot -a slack 30494 30496 /root/.forever/sICk.log 0:0:5:35.399

another way stop forever process

  • check process. kill -9 process
1
2
3
4
5
6
7
$ ps aux | grep hubot | grep -v grep

root 31144 0.3 3.1 723820 32392 ? Ssl 17:58 0:00 /usr/bin/node /home/hu/mybot/node_modules/forever/bin/monitor node_modules/.bin/hubot
root 31146 1.1 6.7 979588 69196 ? Sl 17:58 0:00 node node_modules/hubot/node_modules/.bin/coffee /home/hu/mybot/node_modules/.bin/hubot -a slack

// kill forcibly process
$ sudo kill -9 31146
  • another one.
1
# ps aux | grep hubot | grep -v grep | awk '{print "kill -9", $2}' | sh

Thanks.

pod install で ASSERSION対策

pod install で ASSERSION対策

概要

pod install 実行時に正常にインストール処理ができなかったのでメモ。

冬休み中にSwift2.0をほんきで学ぶ為、以下書籍購入してチャレンジ。

これの LESSON 31 でCocoaPodsインストール手順がありますが
その通りに進めた際にエラー発生したので対策をまとめました。

この手のエラーは環境依存が主ですし、
書籍の執筆時も技術は日進月歩進んでおりますので書籍を責めず
CocoaPodsオフィシャルサイトやStackOverFlowなどで情報探ってみるのが
精神衛生上も良いかもしれないです。

環境情報

  • Xcode 7.2 (7C68)
  • ruby 2.0.0p645
  • gem 2.5.0

書籍に記載されているコマンド

CocoaPodsインストール

1
$ sudo gem install -n /usr/local/bin cocoa pods

エラー内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ pod install
[!] Unable to load a specification for the plugin `/opt/homebrew-cask/Caskroom/cocoapods/0.37.0/CocoaPods.app/Contents/Resources/bundle/lib/ruby/gems/2.2.0/gems/cocoapods-plugins-install-0.0.1`
Analyzing dependencies

CocoaPods 1.0.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Downloading dependencies
Installing Realm (0.97.0)
Installing RealmSwift (0.97.0)
Generating Pods project
2015-12-31 10:51:38.680 ruby[6275:47591] [MT] DVTAssertions: ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-9548/IDEFoundation/Initialization/IDEInitialization.m:590
Details: Assertion failed: _initializationCompletedSuccessfully
Function: BOOL IDEIsInitializedForUserInteraction()
Thread: <NSThread: 0x7fc66d067980>{number = 1, name = main}
Hints: None
Backtrace:
0 0x000000010e001f7f -[DVTAssertionHandler handleFailureInFunction:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation)
1 0x000000010e00170c _DVTAssertionHandler (in DVTFoundation)
2 0x000000010e001978 _DVTAssertionFailureHandler (in DVTFoundation)
3 0x000000010e0018da _DVTAssertionFailureHandler (in DVTFoundation)
4 0x0000000110e5154d IDEIsInitializedForUserInteraction (in IDEFoundation)
5 0x000000011393a631 +[PBXProject projectWithFile:errorHandler:readOnly:] (in DevToolsCore)
6 0x000000011393c1b6 +[PBXProject projectWithFile:errorHandler:] (in DevToolsCore)
7 0x00007fff93b2af14 ffi_call_unix64 (in libffi.dylib)
zsh: abort pod install

対策

1
2
3
4
5
# 既にインストール済みのCocoaPodsをアンインストールする
$ sudo gem uninstall cocoapods

# 再度 `cocoapods` をインストールする。
$ sudo gem install -n /usr/local/bin cocoapods

実行確認

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$  pod install
Updating local specs repositories

CocoaPods 1.0.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Analyzing dependencies
Downloading dependencies
Installing Realm (0.97.0)
Installing RealmSwift (0.97.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `Chapter6.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods
installed.

~/honki_swift/Chapter6/LESSON31/before/Chapter6

無事、 .xcworkspace, Podfile.lock, Pods が作成されました。

1
2
3
4
5
6
7
8
[~/honki_swift/Chapter6/LESSON31/before/Chapter6]$ tree -L 1
.
├── Chapter6
├── Chapter6.xcodeproj
├── Chapter6.xcworkspace
├── Podfile
├── Podfile.lock
└── Pods

以上です。