manatee-itの備忘ログ

プログラム初心者のブログ。ruby on railsでWebサービスを作成中。(仕事が忙しくなかななか進まず) つまずいた所をなんでも記録。 環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite/MySQL)

Windows8.1 +無線ルーターでWi-Fi ネットワーク「制限あり」

以前利用していた無線ルーターの調子が悪くなったので、新しいバッファローの無線ルータに買い換えたところ、ネットワークに制限ありとでてしまい、通信が全くできなくなった。
ネットワークIPアドレスは割り当てられるものの、pingが通らない。

[構成]
AirStation HighPower Giga WSR-1166DHP
lenovo Z480+Windows8.1

http://support.lenovo.com/jp/ja/documents/ht080645
WINDOWS 8.1WIFI アイコンに黄色い ! マークが付く - ノートブック

上記レノボのサポートURLの方法 1~方法 4を試したが、状況かわらず接続不可。

WPA2-パーソナルをWPA2-エンタープライズに変えることができるのかも不明。

方法 5のドライバーのアップデートで接続できるようになったものの、たびたび
ネットワークで「制限あり」の状態が再発している状況。

http://ztms.blog.fc2.com/blog-entry-53.html
Lenovo G500 (Windows 8.1) で無線LAN接続が「制限あり」となり通信できないのは… | いなじゅん


上記のブログサイトで紹介されていたWMMを無効化する方法を実施したところ、現状問題がない様子。

WMM
Wireless Multimedia Extensions - Wikipedia

帯域制御が行われないらしく、有効→無効に変更して測定したところ、回線速度24Mbps→15~18Mbps程度に下がってしまった。

linuxサーバ+radiko+ dropboxでサウージ!サウダージ

j-wareの「サウージ!サウダージ」をずっと聞いていたいので、
linuxサーバでradikoの番組を録音する設定を設定してみました。

環境:CentOS6

linuxサーバでradikoを録音

参考にさせていただいたURL
http://linux.matchy.net/archives/152
http://namaraii.com/archives/19670

yumリポジトリを使用するために、以下をインストール
rpmforge-release-0.5.3-1.el7.rf.x86_64
epel-release-6-8.noarch
remi-release-6.4-1.el6.remi.noarch

radiko録音スクリプトのrec_radiko.shをダウンロード

radiko録音スクリプトを利用するために、以下のパッケージをyumからインストール
swftools-0.9.1-1.el6.rf.x86_64
zziplib-0.13.62-1.el6.x86_64
libmp3lame0-3.99.3-23.el6.x86_64
fftw3-3.3.3-44.1.x86_64
rtmpdump-2.3-1.el6.rf.x86_64
librtmp-2.3-1.el6.rf.x86_64

試しにスクリプトを実行
# ./rec_radiko.sh FMJ 3 /tmp test.mp3
RTMPDump v2.3
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
WARNING: No application or playpath in URL!
Connecting ...
WARNING: Trying different position for server digest!
INFO: Connected...
Starting Live Stream
For duration: 180.000 sec
INFO: Metadata:
INFO: StreamTitle
1096.188 kB / 180.01 sec
Download complete
./rec_radiko.sh: line 152: ffmpeg: コマンドが見つかりません

ffmpegを入れ忘れていた。

ffmpegrpmインストール

参考させていただいたURL
http://fujimi.eshi-net.org/archives/1007

以下のメッセージが出力され、なぜかうまくいかない。
# yum install ffmpeg
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
Setting up Install Process
No package ffmpeg available.
Error: Nothing to do

何の操作で変わったかふめいですが、途中で、以下のエラーが発生。
# yum install ffmpeg
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* rpmforge: ftp.kddilabs.jp
* updates: www.ftp.ne.jp
rpmforge | 1.9 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Wed Jun 25 10:46:36 2014
Downloaded: Tue Jun 24 10:46:27 2014
Setting up Install Process
No package ffmpeg available.
Error: Nothing to do

以下を実行して解消。
# yum clean all

Linuxdropbox の設定

参考させていただいたURL
http://www.maruko2.com/mw/Dropbox%E3%82%92Linux%E3%81%A7%E5%88%A9%E7%94%A8%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95
http://linux.matchy.net/archives/152


$ ~/.dropbox-dist/dropboxd
このコンピュータは Dropbox アカウントにリンクされていません...
このデバイスをリンクするには、https://www.dropbox.com/cli_link?host_id=xxxxxxxxxxxxxxxxxx にアクセスしてください。
このコンピュータは Dropbox アカウントにリンクされていません...
このデバイスをリンクするには、https://www.dropbox.com/cli_link?host_id=xxxxxxxxxxxxxxxxxx にアクセスしてください。
このコンピュータは Dropbox アカウントにリンクされていません...
このデバイスをリンクするには、https://www.dropbox.com/cli_link?host_id=xxxxxxxxxxxxxxxxxx にアクセスしてください。
:
:
:
Linuxサーバ上でブラウザを開くものだと思って慌てましたが、違いました。
他のPCで上記の「https://www.dropbo....」にアクセスしてログイン
:
:
このコンピュータは Dropbox にリンクされました。ようこそ、xxxxxxxx さん。

$ dropbox.py status
Dropbox isn't running!
$ dropbox.py start
Starting Dropbox...Done!
$ dropbox.py status
インデックスを作成中...
$ dropbox.py status
同期中(残り 14 件のファイル, 残り 6 分)

14 件のファイルをダウンロード中 (6,580KB/秒、残り 6 分)
$ dropbox.py status
同期中(残り 2 件のファイル, 残り 1 分)
「2012-09-28 22.01.46.mp4」のインデックスを作成中...
「20131012_xxxxxxxx.zip」をダウンロード中 (8,692KB/秒、残り 1 分)
$ dropbox.py status
最新の状態
% dropbox.py lansync n

テストがうまくいきました。/usr/local/bin/とかに入れるべきでしょうか。
$ /etc/rec_radiko/rec_radiko.sh FMJ 1 /tmp test

サウージサウダージの時間に/etc/crontabを設定 (1分前開始、ntpd時刻同期は設定済み)
59 16 * * 7 root /etc/rec_radiko/rec_radiko.sh FMJ 55 /home/xxxxxx/Dropbox/public/radiko SAUDE_SAUDADE

番組終了後、ファイルができていた。これでスマートフォンからいつでも聞けます。

OS再起動後も動作するようにdropbox起動スクリプトの設定も実施しました。

#2018-02-25追加
ファイル管理ができていなくてドライブ使用容量が100%となっていました。容量を確保しましたが、録音がエラーとなるので、調べてみると2016/10/12からradikoの仕様が変更されていたとのこと。以下URLを参考させていただき、修正しました。
ドライブがいっぱいになったと思われる2017-08-20まではなぜか録音できていたようなのですが、、
radikoの仕様変更によるRaspberry Piでの録音失敗対応 - Qiita

hidden_fieldでログインしているユーザのIDを自動で追加

入力フォームで「タイトル」を入力してもらい、その際にユーザIDを自動でデータベースのレコードに追加したい。

Viewにhidden_fieldを記載。

# vim app/views/programs/_form.html.erb
      :
<%= f.hidden_field :uid, :value => current_user.id %>
      :
<%= f.label :title %>

<%= f.text_field :title %>
      :

コントローラの記載でuidを許可
# vim app/controllers/programs_controller.rb
      :
params[:program].permit(:title)

params[:program].permit(:title,:uid)

ログインしたユーザが登録したタイトルのみが表示されるようになった。

「Could not find a JavaScript runtime」のエラー、therubyracerをコメントアウトして対応

# rails g scaffold programs name:string
/usr/local/lib/ruby/gems/2.1.0/gems/execjs-2.1.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /usr/local/lib/ruby/gems/2.1.0/gems/execjs-2.1.0/lib/execjs.rb:5:in `'
from /usr/local/lib/ruby/gems/2.1.0/gems/execjs-2.1.0/lib/execjs.rb:4:in `'
from /usr/local/lib/ruby/gems/2.1.0/gems/uglifier-2.5.0/lib/uglifier.rb:3:in `require'
from /usr/local/lib/ruby/gems/2.1.0/gems/uglifier-2.5.0/lib/uglifier.rb:3:in `'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /var/www/html/Tabetai/config/application.rb:7:in `'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `require'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `preload'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `'
from /usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `

'

therubyracerをコメントアウトして対応
# vim Gemfile
gem 'therubyracer', platforms: :ruby

rails環境でテーブルにカラム追加

sqliteで、ALTER TABLEを実行すればカラムは追加できますが、マイグレーションファイルを使った方法で追加。

sqlite> .schema programs
CREATE TABLE "programs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "created_at" datetime, "updated_at" datetime);

カラム追加のマイグレーションファイルを作成。
# rails g migration AddUidToPrograms uid:integer
invoke active_record
create db/migrate/20140605124613_add_uid_to_programs.rb

中身を確認
# cat db/migrate/20140605124613_add_uid_to_programs.rb
class AddUidToPrograms < ActiveRecord::Migration
def change
add_column :programs, :uid, :integer
end
end

# rake db:migrate
== 20140605124613 AddUidToPrograms: migrating =================================

    • add_column(:programs, :uid, :integer)

-> 0.0043s
== 20140605124613 AddUidToPrograms: migrated (0.0045s) ========================

sqlite> .schema programs
CREATE TABLE "programs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "created_at" datetime, "updated_at" datetime, "uid" integer);

whenever でcron設定

環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite/MySQL(予定))

classとして作成した機能を毎日定時に実行するため、wheneverを導入してcrontab を設定。

(参考URL)
なんちゃってGeek(仮): Rails4.0でcron(バッチ処理)を動かす設定

                                                                                                                    • -

実行するファイル
# vim lib/tasks/search_task.rb


config/application.rbファイルに以下を追加。
config.autoload_paths += %W(#{config.root}/lib)


実行テスト
rails runner Tasks::SearchTask.execute

# vim Gemfile
gem 'whenever', :require => false
# bundle install

# wheneverize .

# vim config/schedule.rb
set :output, 'log/cron.log'
set :environment, :production

every 1.day, :at => '8:00 am' do
runner 'Tasks::SearchTask.execute'
end


# bundle exec whenever
# bundle exec whenever --update-crontab

# crontab -l
⇒設定を/etc/crontabに移動

rails + Passenger + apacheでの本番サーバへの移行設定で大混乱

環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqliteMySQL(予定))


結果的にうまく動作したが、何が必要で何が必要でなかったのかが、わからなくなったので、後で再調査しないと。


# vim config/environments/production.rb
config.serve_static_assets = true

# rake environment RAILS_ENV=production

以下は不要?
# mkdir public/images/
# cp -a app/assets/images/logo.png public/images/

今度は以下のエラーがerror_logに出力されている。
stderr: [ 2014-05-25 19:00:51.4101 23379/0x007f22ebc2a5c8(Worker 1) utils.rb:68 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 23379, thread 0x007f22ebc2a5c8(Worker 1)):

シークレットキーの生成
# rake secret
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....

apache環境変数として設定
# cat /etc/sysconfig/httpd
export SECRET_KEY_BASE="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...."


# ll remindertv/db/production.sqlite3

  • rwxrwxrwx 1 root root 7168 6月 1 22:36 2014 remindertv/db/production.sqlite3

# vim config/secrets.yml
development:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....

test:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

DBはdevelopmentとproductionで異なるため、DBを変更した場合は以下が必要。
# rake db:migrate RAILS_ENV=production
== 20140601070725 CreatePrograms: migrating ===================================

    • create_table(:programs)

-> 0.0016s
== 20140601070725 CreatePrograms: migrated (0.0018s) ==========================

# rake assets:precompile
I, [2014-06-02T21:20:56.017327 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/logo-xxxxxxxxxxxxxxxxxxxxxxxxxx.....png
I, [2014-06-02T21:20:56.025700 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxx......js
I, [2014-06-02T21:20:56.103759 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxx......css

開発環境のSQLiteのファイルをコピー
# cp -a development.sqlite3 production.sqlite3
# ll
合計 28

  • rw-r--r-- 1 root root 7168 6月 1 22:36 2014 development.sqlite3

drwxr-xr-x 2 root root 4096 6月 1 16:07 2014 migrate

  • rw-r--r-- 1 root root 7168 6月 1 22:36 2014 production.sqlite3
  • rw-r--r-- 1 root root 934 6月 1 16:10 2014 schema.rb
  • rw-r--r-- 1 root root 343 6月 1 16:03 2014 seeds.rb

dbディレクトリの権限を777にしてみる。
# chmod 777 db

アクセスできたが。。。他のサイトを参照させていただき、再度やり直す予定。

参考させて頂く予定のサイト
http://www.ark-web.jp/sandbox/wiki/284.html
http://d.hatena.ne.jp/zariganitosh/touch/20070108/1168246932