2015年4月30日木曜日

プログラム引数とVMの違いについて (eclipse plugin開発でメモリ不足発生時の対応)

手間取ったのでメモ。

Java VMでOutOfMemoryが出た場合、
VM引数にメモリ拡張のオプションを書くことが必要です。
例えばこんな感じ。

-Xmx512m -XX:MaxPermSize=256m

eclipseから起動する場合、起動構成のオプションに
引数を指定することができます。



これを上の欄の「プログラムの引数」に書いてたら反映されなかった。。

「プログラムの引数」と「VM引数」は何が異なるのか。

VM引数は、JavaVMへの引数です。
JavaVMで決められた引数(*)を指定します。
むしろ、それ以外の引数は渡しても意味がなく、
Javaアプリケーションへも渡りません。

*参考 http://docs.oracle.com/cd/E22289_01/html/821-1274/configuring-the-default-jvm-and-java-arguments.html#configuring-jvm-options

プログラムの引数は、文字通りプログラムへの引数です。
JavaVM上で動くアプリケーションには渡りますが、
JavaVMへは渡りません。

当たり前なことしか書いてない気もしますが、
自分がハマったんだから他の人もハマるはず...

2015年3月25日水曜日

Ajaxplorer(Pydi)のアップグレードに失敗したはなし

アップグレードしたら、ブラウザで何も表示されなくなった。

原因を調べるために、Pydiのログを…ってどこにあるかわからん!w

なので、普通にApacheのログを見ると、怪しい文章が。

[Sun Feb 22 14:43:10 2015] [error] [client ***.***.***.***] PHP Parse error:  syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /var/www/html/***/plugins/access.s3/class.s3AccessWrapper.php on line 23

なんだろうと思いぐぐってみると、以下の情報が出てきた。
(参考:http://stackoverflow.com/questions/13960277/error-parse-error-syntax-error-unexpected-t-string-expecting-t-constant-encap

Make sure they are running PHP 5.3 or later. If they are running an earlier version they won't have support for namespaces.

ということで、PHPをアップグレードしてみる。今までは5.2だった。

アップグレードはどうやるんだろうとググると、これまたすぐに情報が出てきた。
(参考:http://blog.ybbo.net/2013/07/09/centos-5-%E3%81%ABphp5-3%E7%B3%BB%E3%82%92yum%E3%81%A7%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/

というわけで、一度アンインストール後に、PHPのバージョンも指定してインストールする。(バージョンを指定しないとデフォルト?の5.1系がインストールされてしまった)

これでApacheを起動後、ブラウザからアクセスすると無事に表示された。

しかもちゃんとアップグレードできてた。まぁ、結果よかった。

2015年3月9日月曜日

シンタックスハイライトをhighlight.jsに乗り換えた

前のやり方のがメンドクサイのと、イマイチいけてなかったので、代わりを探してみた。
すると、軽くてオススメなのが、highlightjsらしい。
機能は少ないみたいだけど、簡単に定義できるので楽そう。
早速試してみる。

準備は簡単。
BloggerだとHTML/JavaScriptの要素を追加し、以下の定義を追加すればよい。
<link rel="stylesheet" href="/path/to/styles/default.css">
<script src="/path/to/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

あとは、記事の中で以下のように囲ってあげればOK。単純
 <pre><code> hogehoge </ pre> </code>

2015年3月1日日曜日

cronでRubyから呼び出しているコマンドが実行できなくなった

cronに登録していたRubyスクリプトがうまく実行されなくなってことがあったので、メモ。

cronに登録したコマンドの実行に失敗した場合、実行ユーザー宛にメールが届く。
(定義ファイル自身に誤りがあれば、/var/log/cronに書かれる。)

メールの内容を見ると、以下のようになっていた。(一部省略)
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:60: command not found: pcsensor -c
'pcsensor'というコマンドをRubyから実行しているが、これが見つからないよう。
直接、Rubyスクリプトを実行したときには問題なく実行できるのに。。

PATHが/usr/bin, /bin しかないので、それ以外のパスに格納されたコマンドが実行されないと推測。
Rubyスクリプトの呼び出し方法を以下のように修正。

# result =  `pcsensor -c`
result =  `/usr/local/bin/pcsensor -c`

この後は問題なく上記スクリプトが正しく動作し、cronのエラーも表示されなくなった。

しかし、なぜ急に実行されなくなったか不明。なにかいじったかな。。

2015年2月9日月曜日

Macでrbenvを使ってRubyをインストールしてみる

rvmがなぜか消えてたので、rbenvを入れてみる。
(seppukuした形跡があった。。)

Macなんで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

$ 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.
######################################################################## 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-
######################################################################## 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
######################################################################## 100.0%
==> Pouring openssl-1.0.1i.mavericks.bottle.3.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means 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.1i: 430 files, 15M
==> Installing ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20140919.tar.
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20140919: 128 files, 548K, built in 3 seconds
$ brew install rbenv-gemset                          [~]
==> Downloading https://github.com/jf/rbenv-gemset/archive/v0.5.8.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-gemset/0.5.8: 12 files, 56K, built in 2 seconds
$ brew install rbenv-gem-rehash                      [~]
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/archive/v1.0.0.t
######################################################################## 100.0%
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/commit/0756890cf
######################################################################## 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
$ 


楽ちんでした。
あとは「rbenv install 2.0.0」とかでインストールできちゃう。
楽ちん。