Net Radio Archiveのアップデートが面倒

コマンドを結構打たないといけないので面倒。
次の関数を.bashrcに加えてみた

update-net-radio-archive(){
git pull origin master
git submodule update --init --recursive
bundle install --without development test agon
RAILS_ENV=production bundle exec rake db:migrate
bundle exec whenever --update-crontab
}

lsでファイル名が文字化けした

lsで何が転がっているか確認しようと思い、実行したら日本語が?????に文字化けしていた。sshで直接ログインした場合にのみ現象が発生して、rootでログインしてsu -で入った場合は何故か文字化けしなかった。そして、echo *は文字化けが起こらなかった。$LANGを調べてみたら、直接ログインして文字化けが起こる場合はja_JP.UTF-8で、su -で入った場合はen_US.UTF-8だった。推測だが、入っていないロケールになっているとlsで文字化けが発生するのかな。入っていないロケールの場合だとLANG=Cとでも解釈されるんだろうか。よくわからない。後でja_JP.UTF-8でも入れてみるかな。

Net Radio ArchiveにPull Requestを送ってみたら取り込まれた

新幹線で移動中にRubyの勉強をしながら書いた汚いコードを送ったら採用されて、手直しされていた。github.com
github.com

そのまま採用出来ないPull Requestで、直す手間をかけさせて何だか申し訳なかった。
きれいなコードを書けるようにもっと勉強をせねば…
名前をつけるセンスもないし…
TOEICで900点超を取って、英語を聞いたり読んだりすることはある程度出来るけど、書いたり話したりするのは下手だ。英語が書けるようになりたい。

そういえば、欲しい機能があったのでIssueをあげたけど、後からPRを送ってしまうのはどうなんだろう。これで良かったのか…。無駄にIssueやPRの番号を増やしてしまうから避けるべきなのだろうか。自分がRubyを書けるようになるまで時間がかかりそうだったから、誰かが代わりに書いてくれることを期待してIssueをあげたけど、思ったより早くなんとかなってしまった。

あとは、Net Radio Archiveで喫茶黒うさぎがとれる様になったら今までの録音環境は用済みになりそうだ。万全を期すために残すだろうけど、安定して動いてくれたら今までの録音環境は不要だな。

net-radio-archiveを入れてみる

# apt-get update
# apt-get install rtmpdump libav-tools swftools ruby git
# gem install bundler
# adduser radioarc
# su - radioarc
$ git clone https://github.com/yayugu/net-radio-archive.git
$ cd net-radio-archive
$ git submodule update --init --recursive

ここまで実行したら次のようなエラーが出る。

$ git submodule update --init --recursive
Cloning into 'niconico'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Clone of 'git@github.com:yayugu/niconico.git' into submodule path 'niconico' failed

ニコ動は取らないのでとりあえず無視しておく。

$ bundle install --without development test agon

しまった。root権限を求められた。

# bundle install --without development test agon

rootで実行してみた。

Installing unf_ext 0.0.7.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.1.0/gems/unf_ext-0.0.7.1 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/unf_ext-0.0.7.1/gem_make.out
An error occurred while installing unf_ext (0.0.7.1), and Bundler cannot
continue.
Make sure that `gem install unf_ext -v '0.0.7.1'` succeeds before bundling.

何かが足りない。ruby-develって無いのかな。
Debian — Package Contents Search Results — ruby.hで調べてみた。

# apt-get install ruby-dev

ruby-devだった。

You have to install development tools first.

あー、build-essentialが入っていないか。

# apt-get install build-essential

これで、unf_ext 0.0.7.1 with native extensionsが入った。
のこぎりのインストールにしばらく時間がかかる。

Installing mysql2 0.3.17 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

lmysqlclientが足りないか。

# apt-get install libmariadb2

こうかな。
まだ足りない。

# apt-get install libmariadbd-dev

違った…

# apt-get install mariadb-client
# apt-get install libmariadb-client-lgpl-dev

これも違う…

# gem install mysql2
# apt-get install libmysqld-dev

これだとうまく行った。
どうやらmysqlにしか対応していない?

$ cp config/database.example.yml config/database.yml
$ cp config/settings.example.yml config/settings.yml
$ vim.tiny config/database.yml
$ vim.tiny config/settings.yml
apt-get install mariadb-server

mariadbのrootパスワードの設定を求められるので、head -c 16 /dev/random | base64で生成した。

$ RAILS_ENV=production bundle exec rake db:create db:migrate
Could not find gem 'niconico (>= 0) ruby' in source at niconico.
Source does not contain any versions of 'niconico (>= 0) ruby'

orz
niconicoが無いとダメなのか…
困った。
SSH経由でサブモジュールを読み込むらしいが、これはSSH鍵による認証が必要だ。
SSH鍵を管理するのはなかなか面倒なんだよな。

16:56追記:
鍵を作ってgithubに登録した。

$ git submodule update --init --recursive
$ RAILS_ENV=production bundle exec rake db:create db:migrate
rake aborted!
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

うぇ。何かが足りない。

# apt-get install nodejs

jessie標準なので古そうだが動いて欲しい。

$ RAILS_ENV=production bundle exec rake db:create db:migrate
== 20150515174349 CreateJob: migrating ========================================
== 20150515174349 CreateJob: migrated (0.0141s) ===============================
== 20150515174821 CreateOnsenProgram: migrating ===============================
== 20150515174821 CreateOnsenProgram: migrated (0.0123s) ======================
== 20150515174949 CreateHibikiProgram: migrating ==============================
== 20150515174949 CreateHibikiProgram: migrated (0.0112s) =====================
== 20150521174524 CreateAnitamaProgram: migrating =============================
== 20150521174524 CreateAnitamaProgram: migrated (0.0113s) ====================
== 20150527135411 CreateNiconicoLivePrograms: migrating =======================
== 20150527135411 CreateNiconicoLivePrograms: migrated (0.0120s) ==============
== 20150602100911 NicoAddColumn: migrating ====================================
== 20150602100911 NicoAddColumn: migrated (0.0361s) ===========================
== 20150607130411 KeyValue: migrating =========================================
== 20150607130411 KeyValue: migrated (0.0115s) ================================
== 20151002075432 CreateAgonProgram: migrating ================================
== 20151002075432 CreateAgonProgram: migrated (0.0146s) =======================

うまく行ったっぽい。

$ bundle exec whenever --update-crontab
[write] crontab file updated

これでセットアップ完了か?

新幹線の無線LANの遅延がひどすぎて、作業がなかなか進まなかったが、なんとか完了したようだ。

アップデート

$ git pull origin master
$ git submodule update --init --recursive
$ bundle install --without development test agon
$ RAILS_ENV=production bundle exec rake db:migrate
$ bundle exec whenever --update-crontab

journalctlでログを眺めていたら次のようなログあった。

error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

ConoHaが提供しているイメージに何か問題があるのか、ed25519鍵に何らかの問題があるから意図的に止めているのか。謎である。
しかし、赤文字で表示されるエラーが大量に残るのは何か気持ちが悪いな。

ConoHa使い始めた

10年近くぶりにはてな記法を使うのでだいぶ忘れている…

とりあえず最初に行った事

  1. 自分で生成したSSH鍵を転送
  2. /etc/ssh/sshd_configでPermitRootLogin without-password
  3. HostbasedAuthentication no
  4. PasswordAuthentication no
  5. UsePAM no

こんなもんかな…

Twitterでツイートばかりしていると、長い文章を書く能力が損なわれる…