/dev/null

(◞‸◟)

MacPortsなしでMacOS X 10.8にZenityをインストールしようとしたら頓挫

winetrickのGUIフロントエンドを起動させるにはZenityと呼ばれる物が必要なようです。

MacPortsだと簡単に入るっぽいのですがパッケージ管理はhomebrewに一任していて、何よりMacPortsの関連バイナリフルインストールな思想が辛いのでもう使いたくありません。 しかたがないのでソースからインストールしてみます。

以下殴り覚書

まずZenityをDL.

http://ftp.nara.wide.ad.jp/pub/X11/GNOME/sources/zenity/2.20/zenity-2.20.1.tar.gz

解凍したからターミナルから作業します。

とりあえずconfigure

~/Downloads/zenity-2.20.1]$ ./configure                                                                                                                             [13:37:20]
checking for a BSD-compatible install... /usr/local/bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
configure: error: gnome-doc-utils >= 0.3.2 not found

gnome-doc-utilsをインストール。

[~/Downloads/zenity-2.20.1]$ brew install gnome-doc-utils

再configure

checking for intltool >= 0.35.0... 0.36.1 found
checking for xgettext... no
checking for msgmerge... no
checking for msgfmt... no
configure: error: GNU gettext tools not found; required for intltool

getTextがないのでインストール

$ brew install gettext                                                                                                                    
Warning: gettext-0.19.2 already installed

既に入ってるぽいのに読み込まれない。

brewのファイルをリンクさせます

$ brew link gettext                                                                                                                      
Warning: gettext is keg-only and must be linked with --force
Note that doing so can interfere with building software.

forceをつけないといけない

$ brew link gettext --force                                                                                                              
Linking /usr/local/Cellar/gettext/0.19.2... 194 symlinks created

再度configure

checking for ZENITY... configure: error: Package requirements (gtk+-2.0 >= 2.9.2 libglade-2.0 libgnomecanvas-2.0 glib-2.0) were not met:

No package 'gtk+-2.0' found
No package 'libglade-2.0' found
No package 'libgnomecanvas-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZENITY_CFLAGS
and ZENITY_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

とりあえずgtk+をいれる

$ brew install gtk+

configure


checking for ZENITY... configure: error: Package requirements (gtk+-2.0 >= 2.9.2 libglade-2.0 libgnomecanvas-2.0 glib-2.0) were not met:

Package 'xcb-shm', required by 'cairo', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZENITY_CFLAGS
and ZENITY_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

xcb-shmとかいうのはbrewにない。 pkg-config-pathを教える。 https://github.com/Homebrew/homebrew/issues/14123

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

configure

checking for ZENITY... configure: error: Package requirements (gtk+-2.0 >= 2.9.2 libglade-2.0 libgnomecanvas-2.0 glib-2.0) were not met:

No package 'libglade-2.0' found
No package 'libgnomecanvas-2.0' found

libgladeとlibgnomecanvasいれる

$ brew instal libglade

$ brew instal libgnomecanvas

再度configure


checking for ZENITY... configure: error: Package requirements (gtk+-2.0 >= 2.9.2 libglade-2.0 libgnomecanvas-2.0 glib-2.0) were not met:

Package 'libxml-2.0', required by 'libglade-2.0', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZENITY_CFLAGS
and ZENITY_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

libxml2はalready installedなのでlink

$ brew link libxml2 --force                                                                                                              
Linking /usr/local/Cellar/libxml2/2.9.1... 20 symlinks created

configure

configure: creating ./config.status
config.status: creating Makefile
config.status: creating zenity.spec
config.status: creating po/Makefile.in
config.status: creating src/Makefile
config.status: creating src/gdialog
config.status: creating data/Makefile
config.status: creating help/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing intltool commands
config.status: executing default-1 commands
config.status: executing po/stamp-it commands

多分通った。 makeをかける

$ make                                                                                                                                 
make  all-recursive




Making all in data
make[2]: Nothing to be done for `all'.
Making all in help
/bin/sh: scrollkeeper-config: command not found
/bin/sh: scrollkeeper-config: command not found
The file '/Templates/C/scrollkeeper_cl.xml' does not exist.
Please check your ScrollKeeper installation.
make[2]: *** [zenity-C.omf] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

makeでコケて力尽きたのでここまで。

MacOS X 10.8でab(apache bench)でConnection reset by peerが出た時の対処方法

タイトル通り。

簡単に負荷テストがてらabを実行した場合に

$ab -n 10 -c 100 http://hoge.server.com/

Benchmarking hoge.server.com/(be patient)...apr_socket_recv: Connection reset by peer (54)

となってしまう。

これはabが腐ってるからっぽいので自前でインストールする。

まず最新版のhttpdを持ってきて解凍する

wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.4.9.tar.gz

で解凍してconfigure→make

./configure 



onfigure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no
configure: error: in `/Users/UserName/Downloads/httpd-2.4.9':
configure: error: C compiler cannot create executables
See `config.log' for more details
 

が、上記のようなconfigure時にエラーがでてしまう

/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc

が見つからないらしい。 でこの辺りのディレクトリを掘ってみると /Applications/Xcode.app/Contents/Developer/Toolchains/ まではあるが実際にあるのはXcodeDefault.xctoolchainになってる。 10.8の頃からこうなったぽい。 Xcode周りのパスが変わるの度々あるらしいのでこうなる。

とりあえず10.8の名前でシンボリックリンクを貼る。

cd /Applications/Xcode.app/Contents/Developer/Toolchains/

sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain

これでもう1回 ./configureしてみる。

多分成功する(pcre周りでエラー出たら brew install pcreする)と思うので、makeをかける。

make installしても良いが、特にhttpd自体が必要なわけじゃないのでsupportディレクトリにあるabだけコピーする。

sudo cp /usr/sbin/ab /usr/sbin/ab.original

sudo cp support/ab /usr/sbin/ab

で、再度abを実行すると多分正しく実行できるようになる。

負荷テストツールGatlingを使ってみている話

負荷テストするためのツールといえばApache JMeterですが、人間が読むには大分辛いconfigと分かりづらめな結果が割と不満でした。

で、なんかモダンな感じの良さげなツールがないか探していると最近はGatlingなるものが良いらしい。

gatling-tool.org - このウェブサイトは販売用です! - gatling tool リソースおよび情報

特徴的なのは設定をScalaDSLによるコードベースで書くところ。

Scalaといってもそんな特殊な関数型バリバリなコードじゃなくて平易な文法、Java感ありーのスクリプト言語っぽさありーのな感じのDSLなんで分かりやすいっぽい。

まだ全然使いこなせてないし、JMeterで出来たアレってそもそも出来るのどれなの?みたいなのが色々あるので使い込んでいきたい。日本語情報少なめなのが大分辛い。

これから何回かに分けて基礎的な部分をまとめて書いていこうと思っていたりする。

GNU ScreenでWindowの中で別のSessionにAttachしてしまった時にdetachする方法

自分はtmuxではなくGNU Screenを使っています。

いくつかSessionを持っていて「本番鯖管理用Session」「テス鯖とか日常作業用Session」などなど。

あるとき、作業用Sessionの中で間違えて本番管理用SessionにAttachしてしまいました。

Screen in Screenです。

f:id:gitpub:20140627141404p:plain

とりあえずdetachしようと思ってz-dしましたが(escape ^Zz設定)、親の作業用Sessionがdetachされてしまいます。

子の本番用Sessionだけをdetachしたい場合どうすればよいでしょうか。

とりあえず考えたのはもう1本そのサーバーにSSHを貼ってそこから本番用Sessionにattachすることです。

-xオプションで入らない限り、ScreenのSessionは排他ですし上手いこと日常作業用Sessionの方が抜けてくれます。

他に方法がないかなと探したら、ありました。

How do you detach the 2nd screen from within another screen? - Unix & Linux Stack Exchange

ctrl-a a dだそうで。

僕の環境で言えばctrl-z z aですね。

ctrl-z zすることで子のSessionにコマンドを投げる状態に出来るので、そこにdetachコマンドを投げることで子のSessionのみをdetachすることが出来るようになるみたいです。

たまにやらかしちゃう時があるので覚えておいて損はないなと思いました。

※追記

子のSessionにコマンドを投げるというのは正しくなく、screen内部にコマンド文字を投げるというのが正しいようです。

npmでのiconvインストールがコケた話

社内用に立ててるhubotのインストールの簡略化の為にpackage.jsonに色々書いてnpm installすれば終わるので楽をしているのですが、あるときインストールが失敗するようになってしまいました。

エラーログはこんな感じ。

npm http GET https://registry.npmjs.org/nan/-/nan-1.1.2.tgz
npm http 200 https://registry.npmjs.org/nan/-/nan-1.1.2.tgz

> iconv@2.1.3 install /home/user/hubot/node_modules/iconv
> node-gyp rebuild

make: ディレクトリ `/home/user/hubot/node_modules/iconv/build' に入ります
  CC(target) Release/obj.target/libiconv/deps/libiconv/lib/iconv.o
  AR(target) Release/obj.target/iconv.a
  COPY Release/iconv.a
  CXX(target) Release/obj.target/iconv/src/binding.o
../src/binding.cc:120: error: ‘template<class T, class P> static void<unnamed>::Iconv::_Nan_Weak_Callback_WeakCallback(const _NanWeakCallbackData<T, P>&)’ cannot be overloaded
../src/binding.cc:120: error: with ‘template<class T, class P> static void<unnamed>::Iconv::_Nan_Weak_Callback_WeakCallback(const _NanWeakCallbackData<T, P>&)’
../src/binding.cc:120: 警告: inline function ‘static void<unnamed>::Iconv::_Nan_Weak_Callback_WeakCallback(const _NanWeakCallbackData<T, P>&) [with T = v8::Object, P = <unnamed>::Iconv]’ used but never defined
make: *** [Release/obj.target/iconv/src/binding.o] エラー 1
make: ディレクトリ `/home/user/hubot/node_modules/iconv/build' から出ます
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 2.6.32-358.18.1.el6.x86_64
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/user/hubot/node_modules/iconv
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok
npm ERR! iconv@2.1.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the iconv@2.1.3 install script.
npm ERR! This is most likely a problem with the iconv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls iconv
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 2.6.32-358.18.1.el6.x86_64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /home/jenkins/nabbit/hubot
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/user/hubot/npm-debug.log
npm ERR! not ok code 0

どうやらiconvが悪そう。

package.jsonには

 "dependencies" : {
        "iconv": "2.1.3"
  }

みたいに書いてました。

npmを見ると最新Versionは2.1.4

iconv - npm

これをpackage.jsonに書けばインストールが成功するようになりました。

いままで2.1.3指定で上手くインストールできてたのに不思議ですがとりあえず良しとします。

が、不安なのはiconvのバージョンが上がる度に前のバージョンだとコケるなんていう事態。

どうせ最低限の機能しか使っていないのでいつでも最新バージョンを追従してほしい。

その場合の書き方は

 "dependencies" : {
        "iconv": "*"
  }

となる。

身も蓋もない書き方ですが、こうすることで現在npmの最新を持ってきてくれるようです。

まぁ破壊的変更加えられたらこれもこれでscript側が死にそうですがそれはそれということで。

Vagrant上にMaxOS環境を構築してみる

Vagrant、とても便利なので使っている方は多いと思います。

大抵の場合、Vagrant上に構築するVMとしてはGNU/Linux系のOSディストリが多いと思います。

でも今回はちょっと変えて、MacOS X 10.9.2を構築します。

そこまで多いユースケースじゃないとは思うんですが、例えば環境構築用のBrewfileをつくろうと思った時に、真っ更なMac OSがあると毎度それにbrew bundleすればいいだけなのでテストしやすいです。

構築するといってもいつも通りboxファイルを指定してvagrant initからのvagrant upだけで終わります。

boxファイルは下記サイトの下部にMac OS X Mavericks 10.9.2 (source) with XCode, homebrew and command line toolsというものがあります。

A list of base boxes for Vagrant - Vagrantbox.es

ですが2014-05-17 14:30:00現在、このリンクは404になってしまっています。

なので、これを公開している方のgithubリポジトリにいきます。

GitHub - AndrewDryga/vagrant-box-osx: Issue tracker for macOS Sierra Vagrant box.

すると、DegitalOcean or AWS上にboxファイルが置かれているのでAWSを指定してboxを持ってきます

vagrant box add mac https://s3-eu-west-1.amazonaws.com/dryga.files/osx-mavericks-0.1.0.box

ファイルサイズが大きく数時間かかると思うので待ちます。

DLが終わったらいつも通り初期化して起動。

vagrant init mac

vagrant up

起動に多少の時間がかかりますが起動します。

このままでもvagrant sshなのでコンソールに入ることは出来ますがX環境に触れません。割と無意味です。

普通に使うにはVagrantからの起動ではなくVirtualBox経由で通常起動させます。

立ち上げたvagrantVMを終了し、VirtualBoxを起動。

するとさっき作ったMaxOS Xがリストに存在するのでそれを起動することで、いつものMacの画面が表示できます。

ちなみにMac OSVirtualBox上で使ってもGuestAdditionが使えるわけではありません。

このBoxファイルにはXcode, Xcode CommandLineTools,Homebrewがあらかじめインストールされているのでbrewfileなどが簡単に試せてとても便利です。

それと気になるライセンスですが、自分のMacのハードウェア上では2つまでVM起動していいっぽいので問題はなさそうです。

(iii) to install, use and run up to two (2) additional copies or instances of the Apple Software within virtual operating system environments on each Mac Computer you own or control that is already running the Apple Software, for purposes of: (a) software development; (b) testing during software development; (c) using OS X Server; or (d) personal, non-commercial use.

http://www.apple.com/legal/sla/docs/OSX109.pdf http://www.apple.com/legal/sla/docs/OSX109.pdf

使い道は少なそうですがあると便利というものでした。

ちなみにWindows上のVagrantで起動はしませんのであしからず。夢は見れません。

Sphinxでのドキュメント作成をそれなりに快適に書く方法

前回書いた通り、ドキュメント作成にSphinxを使い始めています。

Markdownと違って単一のページを書くのはちょっと大仰な感じしますが、体系的なドキュメント書くのには構造がしっかりしている分いい感じ。

ところがMarkdownと違って書いてプレビューしたいなと思う度に make html するのは辛い。しかもその後ブラウザで開く必要あり。開いていてもリロード。

これではSphinx始めたてで、文法と文書がリンクできない人間にはちょっとつらい。

前回、コマンド一発でhtmlが吐かれるところまではできています。

SublimeText2でSphinx-Build - /dev/null

これはあんまり苦じゃありません。そこまでbuildが遅いわけでもないので。大体1秒もあれば終わる。

あとはこれを自動でプレビューし変更を感知してリロードしてくれればそれなりに書ける環境が出来上がるのではないか。

そこで、いい感じのツールを見つけました。

ファイル編集したら即ブラウザー再読込させる LiveReloadX を作った - てっく煮ブログ

npm install -g livereloadx でlivereloadxをインストール。

ブラウザ拡張入れたり、jsを全ページに入れるのは面倒なのでstaticモードで実行します。

livereloadx -s document/_build/

を実行。

その後に

http://localhost:35729/html/index.html

にアクセスすると作られたドキュメントがプレビューされます。

あとは.rstなドキュメントを書いて、Sublime上でショートカットでbuild。ブラウザはファイルの変更を検知して自動でリロードをかけてくれるので最新の状態が手軽にプレビューすることができます。

これで大分Sphinxでドキュメント書くのが楽しくなりそうです。