goo blog サービス終了のお知らせ 

つれづれなるまゝに

単なる作業メモ。主に、Linux, arduino, raspberry piとか?

Heroku と Ruby on rails その1

2014-05-25 19:57:39 | linux
さて、今日はRuby on railsをHerokuで動かそうとチャレンジ

こちらのサイトを参考に進める。
Herokuで作るFacebookアプリ

が、"git push heroku master"とするとsqlite.hがないとうエラーが発生。
調べてみると、どうやらHerokuではDBはpostgresにしか対応していない。が、railsで標準的に使われるのはsqlite3。

ということで、"git push heroku master"する前に、以下の作業が必要。

1. Gemfileを修正

group :development do
 gem 'sqlite3'
end
group :production do
 gem 'pg'
 gem 'rails_12factor'
end

2. 修正の反映

bundle install --without production
git commit -a -m "ホゲホゲ"

ここまでしてから"git push heroku master"すれば、Herokuではpostgresを使って環境が構築される模様。
※このあたりは、ここを参考にさせてもらった

今日はここまで。次はDB構築とマイグレーション。

--- 追記 ---

scaffold でひな形つくって動かそうとすると、ExecJS::RuntimeErrorが発生。
Windows8だと以下の修正が必要だった。

Windows 8 で ExecJS::RuntimeError が出たときは

私だけの話なのかもしれないが、Rubyがらみではいつもポコポコとつまずく。このあたりが、Rubyの悪いところじゃないかなぁ。

QNAPのNAS増強

2014-01-02 21:51:28 | linux
年末、QNAPのNASをTS-110からTS-421あたりに増強しようかと考えていたが、結局やめました。

理由は、
・今はそれほど頻繁にアプリを使ってないので、高速のCPUは必要ない
 →今後、必要になった時でいいや
・RAID1はやっぱりいらない
 ダウンタイムを短くしたいなら必要だろうが、使ってるのは自分メインなので、問題おこったら自分は復旧作業してるし、その間は使わない

ただ、データの損失は避けたいので、HDDだけは増設したい。
いまは使わなくなった小容量の外付けHDDを2台(160GH + 300GH)つないで、バックアップ等に使っている。
最近この1台がやたらディスクアクセス音(カラカラ音)がするし、起動時のHDD認識が遅いのかバックアップタスクがよく失敗するわ、電源ケーブルやランプいっぱいで少し野暮ったいわで、これをどうにかしたい。

それだけに4xxを買うとなると出費が大きいので、外付けのHDD増設ケースを探す。


最初の候補はCenturyの”裸族の集合住宅5Bay”で、これがamazonで17800円だった。ただ、QNAPのeSATAはポートマルチプライヤー非対応とのこと。なんでかなぁ。。。※

※<余談>気になってちょいと調べてみた
そもそも、SoCの88F6282制限かとおもったが、Port Multiplier対応はLinux向けドラバー側の問題のようで、ここを見ると安定性に欠けるみたいだ。待っていれば将来は対応されるのだろうか。QNAPとしては4xxとか8xxとか買ってもらいたいだろうし、あくまでeSATAはおまけとい考えで優先度低いでしょうねぇ。。。


なので、USB専用で4ドライブだけどもっとちょっと安い”裸族のカプセルホテル CRCH35U3IS”(amazonで14000円弱)も候補に。こいつは個々の電源スイッチが前にあるのが便利。

もう少し探していると、LogitecのLHR-4BNEU3がamazonで9,980円(現在は品切れ状態)を発見。ほぼ1万円という価格が決め手となり、こいつに決定。とくに必要ないけど、USB3.0対応でeSATAも持っている。ただ4TBには対応してないとのことだが、4TBで動いたという話もあり。まぁ、今の手持ちは2.5TBまでなのでよいかなと。

あわせて別途、WDのREDの3TBも購入。


現状、問題なく動作中。電源連動で、連動先が停止するとスリープ状態に設定しておくと、QNAP起動・終了に対応して、ちゃんと起動・スリープしてくれる。
起動時のバックアップ処理は相変わらず失敗するので、バックアップタイミングを変更することにする。

最初、3TBのディスクを初期化する場合、QNAPからは3TB認識されなかった。PC側にてフォーマッターつかって3TBでフォーマット後に挿すと認識してくれた(少し手こずったが。。。)。

QNAPでruby on rails その2

2013-11-23 20:14:12 | linux
いろいろ調べてみるが、まだ解決策が見つからない。

単純に/home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-gccのシンボリックリンクを作成すれば動く気もするが、急ぐものでもないので少し勉強してみようと思う。

問題個所はjsonの拡張ライブラリを作成している個所。
extconf.rbはmkmfを使ってMakefileを使っている。
その際に、RbConfig::ConfigにあるCCの情報を使っているというのは理解したが、このCCの情報をどこからとってきてるのかがまだわからない。。。

以下余談。うちのQNAPはTS110だが

# cat /proc/cpuinfo
Processor name : Feroceon 88F6281 rev 1 (v5l) @
BogoMIPS : 799.53
Features : swp half thumb fastmult edsp
CPU implementer : 0x56
CPU architecture: 5TE
CPU variant : 0x2
CPU part : 0x131
CPU revision : 1

Hardware : Feroceon-KW ARM
Revision : 0000
Serial : 0000000000000000

ということで、CPU自体は先日ポイした玄箱のCPUと同じでクロック違いのようだ。

そろそろ新しいのに替えたい。TS-421くらいが欲しいなぁ。

QNAPでruby on rails

2013-11-17 22:08:26 | linux
自作機のRailsを4.0にしたいので、QNAP側にredmineを移せないかを検討。

AppCenterをみるとRailsがあったので、インストール
-> /opt/binの配下に,ruby,gem,rakeはインストールされる

# ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [arm-linux-eabi]

# gem -v
1.3.1

さて、railsはどこに???

# gem install rails
/opt/lib/ruby/1.9.1/rubygems/digest/md5.rb:8:in `require': libcrypto.so.0.9.8: cannot open shared object file: No such file or directory - /opt/lib/ruby/1.9.1/arm-linux-eabi/digest/md5.so (LoadError)
from /opt/lib/ruby/1.9.1/rubygems/digest/md5.rb:8:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/package.rb:12:in `require'
from /opt/lib/ruby/1.9.1/rubygems/package.rb:12:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/format.rb:9:in `require'
from /opt/lib/ruby/1.9.1/rubygems/format.rb:9:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/installer.rb:11:in `require'
from /opt/lib/ruby/1.9.1/rubygems/installer.rb:11:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/dependency_installer.rb:3:in `require'
from /opt/lib/ruby/1.9.1/rubygems/dependency_installer.rb:3:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/commands/install_command.rb:4:in `require'
from /opt/lib/ruby/1.9.1/rubygems/commands/install_command.rb:4:in `<top (required)>'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:140:in `require'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:140:in `rescue in load_and_instantiate'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:132:in `load_and_instantiate'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:65:in `[]'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:118:in `find_command'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:104:in `process_args'
from /opt/lib/ruby/1.9.1/rubygems/command_manager.rb:75:in `run'
from /opt/lib/ruby/1.9.1/rubygems/gem_runner.rb:39:in `run'
from /opt/bin/gem:24:in `<main>'

とおこられるので、インストールに失敗している模様。
ここに解決策が書いてある。
が、

gem install openssl

だと、同じエラーが。これipkg install opensslじゃね?と思って実行。

# ipkg install openssl
Installing openssl (0.9.8v-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/openssl_0.9.8v-2_arm.ipk
Configuring openssl
Successfully terminated.

やっぱりw

でもって、

# gem install rails --version "3.2.4"

・・・
なかなか応答がかえってこない(1時間くらい???)。で、結果が、、、

ERROR: Error installing rails:
bundler requires RubyGems version >= 1.3.6
Updating class cache with 0 classes...

ぐはっ。ではと、

# gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-2.1.11
:0:Warning: Gem::SourceIndex#search support for String patterns is deprecated
Updating RubyGems to 2.1.11
Installing RubyGems 2.1.11
RubyGems 2.1.11 installed
Installing ri documentation for rubygems-2.1.11
/opt/lib/ruby/1.9.1/rdoc/rdoc.rb:275: warning: conflicting chdir during another chdir block
/opt/lib/ruby/1.9.1/rdoc/rdoc.rb:282: warning: conflicting chdir during another chdir block

=== 2.1.10 / 2013-10-24
・・・

If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.

# gem -v
2.1.11

とアップデート成功。ドキュメントのインストールなしでもよかったなと後で思う。

さて、再度railsを。

・・・
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/opt/bin/ruby extconf.rb
creating Makefile

make
sh: make: command not found

なるほど。
ここを参考に必要そうなものをipkgでインストール。


# ipkg install make
Installing make (3.82-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/make_3.82-1_arm.ipk
Configuring make
Successfully terminated.

# ipkg install gcc
Installing gcc (4.2.3-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/gcc_4.2.3-1_arm.ipk
Installing binutils (2.19.1-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/binutils_2.19.1-1_arm.ipk
Installing libc-dev (2.5-5) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/libc-dev_2.5-5_arm.ipk
Installing libnsl (2.5-4) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/libnsl_2.5-4_arm.ipk
Configuring binutils
update-alternatives: Linking //opt/bin/strings to /opt/bin/binutils-strings
Configuring gcc
Configuring libc-dev
Configuring libnsl
Successfully terminated.

以下の2つは必要かは不明

# ipkg install gawk
Installing gawk (4.0.1-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/gawk_4.0.1-1_arm.ipk
Configuring gawk
update-alternatives: Linking //opt/bin/awk to /opt/bin/gawk
Successfully terminated.
# ipkg install sed
Installing sed (4.2.2-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/sed_4.2.2-1_arm.ipk
Configuring sed
update-alternatives: Linking //opt/bin/sed to /opt/bin/gnu-sed
Successfully terminated.


で、再度railsを。

ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/opt/bin/ruby extconf.rb
creating Makefile

make
/home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-gcc -I. -I/opt/include/ruby-1.9.1/arm-linux-eabi -I/opt/include/ruby-1.9.1/ruby/backward -I/opt/include/ruby-1.9.1 -I. -DJSON_GENERATOR -O2 -pipe -I/home/slug/optware/cs08q1armel/staging/opt/include -D_FILE_OFFSET_BITS=64 -fPIC -O2 -g -Wall -Wno-parentheses -fPIC -O3 -Wall -O0 -ggdb -o generator.o -c generator.c
make: /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-gcc: Command not found
make: *** [generator.o] Error 127


Gem files will remain installed in /opt/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to /opt/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

んー、makefileのパスがおかしい。。。

今夜はここまで。

rails アプリ編 はじめてのアプリ

2013-11-07 23:09:13 | linux
こちらを参考に、まずはViewとControlerだけの簡単なアプリをつくってみる。

バージョンの関係か、記載の通りでは動かない。以下に、異なる点を列記。

1) コマンド名
 ruby script/xxx となってるが、rails xxx と読み替える。

2) ビューの作成
作成するビューの拡張子がrhtmlとなっているが、htmlでよい。

3) ルーティング設定
 参考元ではなにも記載ないが、以下の対応が必要。

 config/routes.rbを編集
 → match ':controller(/:action(/:id))(.:format)'のコメント外す

以上の差分で動作した