Rails を 4.1.4 から 4.2.8(4.2 系の最新版)にアップデートしたら、rails s
で起動したサーバに外部(ほかの PC)からアクセスできなくなっていた。4.2 で挙動が変わったらしい。
cf. rails sで起動したサーバにブラウザからアクセスできない – Qiita
上の参考ページにあるように、-b オプションをつければいい。
takatoh@envelopes $ bundle exec rails s -b 0.0.0.0
takatoh's blog – Learning programming languages.
Rails を 4.1.4 から 4.2.8(4.2 系の最新版)にアップデートしたら、rails s
で起動したサーバに外部(ほかの PC)からアクセスできなくなっていた。4.2 で挙動が変わったらしい。
cf. rails sで起動したサーバにブラウザからアクセスできない – Qiita
上の参考ページにあるように、-b オプションをつければいい。
takatoh@envelopes $ bundle exec rails s -b 0.0.0.0
先週のさらに続き。先週は、球面上の点を平面上に投影するのに X, Y 座標をそのまま使って水平投影したけど、今度はステレオ投影というのをやってみる。
ステレオ投影は Wikipedia に詳しく載っている。
先週と同じように、下半球の点 300 個を XY 平面(赤道面)上に投影する。やってみたのが下の図。
コードは次の通り。
#!/usr/bin/env ruby
# encoding: utf-8 require 'csv' def sp(x, y, z)
[x / (1.0 - z), y / (1.0 - z)]
end csv = File.open(ARGV.shift, "r") csv.each_line do |line|
x, y, z = line.parse_csv.map{|v| v.to_f }
r = Math.sqrt(x * x + y * y + z * z)
print sp(x, y, z).map{|v| v * r }.to_csv
end
やっつけ仕事なので、ヘルプもないけど、先週の gss_gen
コマンド(--cartesian
オプション付き)の結果を入力として、投影点の座標を CSV で出力する。
一昨日の続き。最初と最後の点を極から移動(位置調整)するのを実装した。ついでに、gem 化して RubyGems.org にアップしておいた。gem install gss_generator
でインストールできる。
使い方は次の通り。
^o^ > gss_gen --cartesian --relocate 1.0 600 > c600r.csv
--cartesian
はデカルト座標系で出力、--relocate
は位置調整のオプション。結果は CSV 形式で標準出力に出力するので c600r.csv ファイルにリダイレクトしている。
ちょっと面白いものを見つけた。
cf. LEDドームのLEDの並びを決めるのに使用した計算式 – jakaladaのブログ
球面上に任意個の点を一様分布させる、座標を求めるもの。一般化螺旋集合(generalized spiral set)というものを使っている。元の資料(論文)はここ。
cf. 多数の点を球面上に一様分布させるソフトウェアGSS Generator
上のリンク先のブログでは Python を使っているので、Ruby でやってみた。
#!/usr/bin/env ruby # encoding: utf-8 require 'gss' require 'optparse' require 'csv' options = {} opts = OptionParser.new opts.banner = "Generate points with uniform distribution on the sphere." opts.on("-c", "--cartesian", "Cartesian coordinate."){|v| options[:cartesian] = true } opts.on_tail("-h", "--help", "Show this message."){|v| print opts.help exit } opts.on_tail("-v", "--version", "Show version."){|v| puts "v#{GSS::VERSION}" exit } opts.parse! r = ARGV.shift.to_f n = ARGV.shift.to_i gss = GSS::GSS.new points = gss.generate(r, n) points.each do |p| if options[:cartesian] coord = p.to_cartesian print coord.to_csv else print [p.r, p.theta, p.phi].to_csv end end
# encoding: utf-8 require "gss/polar_point" module GSS class GSS def generate(r, n) theta_1 = Math::PI phi_1 = 0.0 points = [] points << PolarPoint.new(r, theta_1, phi_1) 2.upto(n) do |k| h_k = -1.0 + 2.0 * (k - 1) / (n - 1) theta_k = Math.acos(h_k) phi_k = points.last.phi + 3.6 / Math.sqrt(n) * 1 / Math.sqrt(1 - h_k ** 2) phi_k = phi_k.infinite? ? 0.0 : phi_k % (Math::PI * 2.0) points << PolarPoint.new(r, theta_k, phi_k) end points end end # of class GSS end # of module GSS
# encoding: utf-8 module GSS class PolarPoint attr_reader :r, :theta, :phi def initialize(r, theta, phi) @r = r @theta = theta @phi = phi end def to_cartesian x = @r * Math.sin(@theta) * Math.cos(@phi) y = @r * Math.sin(@theta) * Math.sin(@phi) z = @r * Math.cos(@theta) [x, y, z] end end # of class PolarPoint end # of module GSS
最初のがコマンドで、あとの2つがライブラリ。引数に球の半径と配置したい点の個数を指定すると、各点の極座標を CSV 形式で出力する。
^o^ > ruby -Ilib exe/gss_gen 1.0 600
極座標じゃなく、デカルト座標(XYZ座標)がほしい時には --cartesian
オプション。
^o^ > ruby -Ilib exe/gss_gen --cartesian 1.0 600
下の図は、発生させた600個の点のうち下半分の300個を XY 平面上に投影した図。
各点を順に線でつないでみると、螺旋になっているのがよくわかる。
……なんか螺旋が逆になってるな。元論文じゃ球面を下から見たと書いてあるからそのせいか?
ともあれ、それらしいのはできた。ただし、最初と最後の点の座標を調整するのはやってない。時間があったらやってみよう。
Sinatra でアプリを作ってるんだけど、セッションを利用するとタイトルのようなワーニングが出た。もっと詳しく書くと次のとおり。
SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack, and future versions will even invalidate your existing user cookies.
ググってみても見つかるのは、Rails のバージョンを上げろとか、Rack のバージョンを 1.4.1 にしろとかいうのばっかり。Rails は使ってないし、Rack は 1.6.5 なんだけどなあ。そんな中で見つけたのが↓このページ。
cf. SECURITY WARNING: No secret option provided to Rack::Session::Cookie
config.ru で :session_secret に値を設定すればいいらしい。
具体的には次のようにした。
enable :sessions set :session_secret, 'somethingverysecret1234'
これでめでたくワーニングが出なくなった。
rubygems の Nokogiri のインストールで躓いた。環境は:
いろいろ試した結果、次のパッケージを sudo apt install
したらインストールできた。
これらをインストールしたうえで、Nokogiri をインストール。
takatoh@apostrophe $ sudo gem install nokogiri Building native extensions. This could take a while... Successfully installed nokogiri-1.7.0.1 Parsing documentation for nokogiri-1.7.0.1 Installing ri documentation for nokogiri-1.7.0.1 Done installing documentation for nokogiri after 8 seconds 1 gem installed
起動スクリプトを、これも apostrophe からコピー。
tonzlr@wplj:/etc/init.d$ cd tonzlr@wplj:~$ cd /etc/init.d tonzlr@wplj:/etc/init.d$ sudo scp tonzlr@apostrophe:/etc/init.d/tonzlr . sudo tonzlr のパスワード: tonzlr@apostrophe's password: tonzlr 100% 455 0.4KB/s 00:00
これも変更しないでいいんじゃないかな。
#!/bin/bash PATH=/usr/local/bin:/usr/bin:/bin:/sbin:PATH TONZLR_ROOT=/home/tonzlr/tonzlr case "$1" in start) echo "Starting Tonzlr" cd ${TONZLR_ROOT} export SECRET_KEY_BASE=`rake secret` bundle exec unicorn_rails -c unicorn.conf -E production -D ;; stop) echo "Stoping Tonzlr" PID=`cat ${TONZLR_ROOT}/unicorn.pid` kill -QUIT ${PID} ;; *) echo "Usage: tonzlr {start|stop}" >&2 exit 1 ;; esac exit 0
起動確認。
tonzlr@wplj:~/tonzlr$ sudo /etc/init.d/tonzlr start Starting Tonzlr
OK。
Unit ファイルを書く。
[Unit] Description=Tonzlr service After=network.target [Service] ExecStart=/etc/init.d/tonzlr start ExecStop=/etc/init.d/tonzlr stop Restart=always Type=forking PIDFile=/home/tonzlr/tonzlr/unicorn.pid [Install] WantedBy=multi-user.target
そして、/etc/systemd/system/tonzlr.service にリンクを張る。
tonzlr@wplj:~/tonzlr$ sudo ln -s /lib/systemd/system/tonzlr.service /etc/systemd/system/tonzlr.service
起動確認。
tonzlr@wplj:~/tonzlr$ sudo systemctl start tonzlr
OK。start したり stop したりして確認できた。
Ubuntu の起動時に自動起動するようにする。
tonzlr@wplj:~/tonzlr$ sudo systemctl enable tonzlr Synchronizing state of tonzlr.service with SysV init with /lib/systemd/systemd-sysv-install... Executing /lib/systemd/systemd-sysv-install enable tonzlr insserv: warning: script 'K01bruschetta' missing LSB tags and overrides insserv: warning: script 'tonzlr' missing LSB tags and overrides insserv: warning: script 'bruschetta' missing LSB tags and overrides update-rc.d: error: tonzlr Default-Start contains no runlevels, aborting.
むぅ、またエラーが出てる。だけど、この間の Flask アプリではこれでもちゃんと自動起動できるようになっていたので、今回もそれを期待してリブートしてみる。
tonzlr@wplj:~/tonzlr$ sudo reboot
……はたしてリブートした結果……おお、ちゃんと自動起動されている!
よし、最後に、Nginx のヴァーチャルホスト tonzlr を設定する。
upstream unicorn-tonzlr { server 127.0.0.1:9009; } server { # port listen 80; # server name server_name tonzlr; # document root root /home/tonzlr/tonzlr; # index #index index.php index.html index.htm; # log files access_log /var/log/nginx/tonzlr/access.log combined; error_log /var/log/nginx/tonzlr/error.log warn; keepalive_timeout 60; proxy_connect_timeout 60; proxy_read_timeout 60; proxy_send_timeout 60; location / { #root /home/tonzlr/tonzlr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://unicorn-tonzlr; } }
sites-enabled/tonzlr にリンクを張って:
tonzlr@wplj:/etc/nginx$ sudo ln -s /etc/nginx/sites-available/tonzlr /etc/nginx/sites-enabled/tonzlr
ログファイル用のディレクトリを作る。
tonzlr@wplj:/etc/nginx$ sudo mkdir /var/log/nginx/tonzlr
Nginx をリロード。
tonzlr@wplj:/etc/nginx$ sudo systemctl reload nginx
hosts ファイルに tonzlr を追加して、http://tonzlr/ にブラウザでアクセスしてみる。
OK!!!!!!!!!
あとは、他のマシンの hosts ファイルを書き換えるだけだ。
Unicorn のインストール。
tonzlr@wplj:~/tonzlr$ sudo apt install unicorn [sudo] tonzlr のパスワード: パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下のパッケージが自動でインストールされましたが、もう必要とされていません: libpango1.0-0 libpangox-1.0-0 ubuntu-core-launcher これを削除するには 'sudo apt autoremove' を利用してください。 以下の追加パッケージがインストールされます: ruby-kgio ruby-rack ruby-raindrops 以下のパッケージが新たにインストールされます: ruby-kgio ruby-rack ruby-raindrops unicorn アップグレード: 0 個、新規インストール: 4 個、削除: 0 個、保留: 8 個。 269 kB のアーカイブを取得する必要があります。 この操作後に追加で 898 kB のディスク容量が消費されます。 続行しますか? [Y/n] Y 取得:1 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 ruby-kgio amd64 2.10.0-1build1 [27.7 kB] 取得:2 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 ruby-rack all 1.6.4-3 [81.3 kB] 取得:3 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 ruby-raindrops amd64 0.16.0-1build1 [33.0 kB] 取得:4 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 unicorn amd64 4.9.0-2build2 [127 kB] 269 kB を 0秒 で取得しました (1,720 kB/s) 以前に未選択のパッケージ ruby-kgio を選択しています。 (データベースを読み込んでいます ... 現在 216599 個のファイルとディレクトリがインストールされています。) .../ruby-kgio_2.10.0-1build1_amd64.deb を展開する準備をしています ... ruby-kgio (2.10.0-1build1) を展開しています... 以前に未選択のパッケージ ruby-rack を選択しています。 .../ruby-rack_1.6.4-3_all.deb を展開する準備をしています ... ruby-rack (1.6.4-3) を展開しています... 以前に未選択のパッケージ ruby-raindrops を選択しています。 .../ruby-raindrops_0.16.0-1build1_amd64.deb を展開する準備をしています ... ruby-raindrops (0.16.0-1build1) を展開しています... 以前に未選択のパッケージ unicorn を選択しています。 .../unicorn_4.9.0-2build2_amd64.deb を展開する準備をしています ... unicorn (4.9.0-2build2) を展開しています... man-db (2.7.5-1) のトリガを処理しています ... systemd (229-4ubuntu16) のトリガを処理しています ... ureadahead (0.100.0-19) のトリガを処理しています ... ureadahead will be reprofiled on next reboot ruby-kgio (2.10.0-1build1) を設定しています ... ruby-rack (1.6.4-3) を設定しています ... ruby-raindrops (0.16.0-1build1) を設定しています ... unicorn (4.9.0-2build2) を設定しています ... insserv: warning: script 'K01bruschetta' missing LSB tags and overrides insserv: warning: script 'bruschetta' missing LSB tags and overrides insserv: warning: script 'K01bruschetta' missing LSB tags and overrides insserv: warning: current start runlevel(s) (empty) of script `unicorn' overrides LSB defaults (2 3 4 5). insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `unicorn' overrides LSB defaults (0 1 6). insserv: warning: script 'bruschetta' missing LSB tags and overrides systemd (229-4ubuntu16) のトリガを処理しています ... ureadahead (0.100.0-19) のトリガを処理しています ...
apostrophe から設定ファイル unicorn.conf をコピー。
tonzlr@wplj:~/tonzlr$ scp tonzlr@apostrophe:tonzlr/unicorn.conf . tonzlr@apostrophe's password: unicorn.conf 100% 166 0.2KB/s 00:00
たぶん、変更しないでいいはず。
tonzlr@wplj:~/tonzlr$ cat unicorn.conf
listen "9009"
worker_processes 1
working_directory "/home/tonzlr/tonzlr"
pid "./unicorn.pid"
stdout_path "./unicorn.log"
stderr_path "./unicorn.log"
preload_app true
tonzlr@wplj:~/tonzlr$ bundle exec unicorn_rails -c unicorn.conf -E production
OK。ブラウザで http://localhost:9009/ にアクセスして確認できた。
前回のエントリのあとごちょごちょやってたらとりあえず動くようになったので、書いておく。
まず、依存しているらしいパッケージを apt install
でインストール。
専用ユーザの作りなおし。
takatoh@wplj $ sudo adduser tonzlr takatoh@wplj $ sudo gpasswd -a tonzlr sudo
作ったユーザでログインして、GitHub からクローン。
tonzlr@wplj:~$ git clone https://github.com/takatoh/Tonzlr.git tonzlr
bundle install
。
tonzlr@wplj:~$ cd tonzlr tonzlr@wplj:~/tonzlr$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Installing rake 10.4.2 Installing i18n 0.7.0 Installing json 1.8.1 with native extensions Installing minitest 5.5.0 Installing thread_safe 0.3.4 Installing builder 3.2.2 Installing erubis 2.7.0 Installing rack 1.5.2 Installing mime-types 1.25.1 Installing polyglot 0.3.5 Installing arel 5.0.1.20140414130214 Installing coffee-script-source 1.8.0 Installing execjs 2.2.2 Installing thor 0.19.1 Installing hike 1.2.3 Installing multi_json 1.10.1 Installing libv8 3.16.14.3 (x86_64-linux) Using bundler 1.14.6 Installing tilt 1.4.1 Installing ref 1.0.5 Installing sass 3.2.19 Installing spring 1.2.0 Installing sqlite3 1.3.10 with native extensions Installing will_paginate 3.0.7 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator /usr/bin/ruby2.3 -r ./siteconf20170304-6634-1swo6wh.rb extconf.rb creating Makefile current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" clean current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’: ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion] VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:239: ターゲット 'generator.o' のレシピで失敗しました make: *** [generator.o] エラー 1 make failed, exit code 2 Gem files will remain installed in /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1 for inspection. Results logged to /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.1/gem_make.out An error occurred while installing json (1.8.1), and Bundler cannot continue. Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
やっぱりエラーになったけど、めげずに bundle update
。
tonzlr@wplj:~/tonzlr$ bundle update Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Resolving dependencies... Installing rake 12.0.0 (was 10.4.2) Installing i18n 0.8.1 (was 0.7.0) Installing json 1.8.6 (was 1.8.1) with native extensions Installing minitest 5.10.1 (was 5.5.0) Installing thread_safe 0.3.6 (was 0.3.4) Installing builder 3.2.3 (was 3.2.2) Using erubis 2.7.0 Installing rack 1.5.5 (was 1.5.2) Using mime-types 1.25.1 Using polyglot 0.3.5 Using arel 5.0.1.20140414130214 Using bundler 1.14.6 Installing coffee-script-source 1.12.2 (was 1.8.0) Installing execjs 2.7.0 (was 2.2.2) Installing thor 0.19.4 (was 0.19.1) Using hike 1.2.3 Installing multi_json 1.12.1 (was 1.10.1) Installing libv8 3.16.14.17 (x86_64-linux) (was 3.16.14.3) Using tilt 1.4.1 Installing rdoc 4.3.0 (was 4.2.0) Installing ref 2.0.0 (was 1.0.5) Using sass 3.2.19 Installing spring 1.7.2 (was 1.2.0) Installing sqlite3 1.3.13 (was 1.3.10) with native extensions Installing turbolinks-source 5.0.0 Installing will_paginate 3.1.5 (was 3.0.7) Installing tzinfo 1.2.2 Installing rack-test 0.6.3 (was 0.6.2) Installing treetop 1.4.15 Installing coffee-script 2.4.1 (was 2.3.0) Installing uglifier 3.1.3 (was 2.6.0) Installing sprockets 2.12.4 (was 2.12.3) Installing sdoc 0.4.2 (was 0.4.1) Installing therubyracer 0.12.3 (was 0.12.1) with native extensions Installing turbolinks 5.0.1 (was 2.5.3) Installing activesupport 4.1.4 Installing mail 2.5.4 Installing actionview 4.1.4 Installing activemodel 4.1.4 Installing jbuilder 2.6.3 (was 2.2.6) Installing actionpack 4.1.4 Installing activerecord 4.1.4 Installing actionmailer 4.1.4 Installing railties 4.1.4 Installing sprockets-rails 2.3.3 (was 2.2.2) Installing coffee-rails 4.0.1 Installing jquery-rails 3.1.4 (was 3.1.2) Installing rails 4.1.4 Installing sass-rails 4.0.5 Bundle updated!
今度は成功。
設定ファイルの編集。
tonzlr@wplj:~/tonzlr$ cd config tonzlr@wplj:~/tonzlr/config$ cp site_config.yml.example site_config.yml tonzlr@wplj:~/tonzlr/config$ vi site_config.yml
--- development: storage_dir: ./storage-devel test: storage_dir: ./storage-test production: storage_dir: /media/aysheaia/wallpapers
データベースのマイグレーション。
tonzlr@wplj:~/tonzlr$ rake db:migrate RAILS_ENV=production == 20141229035713 CreateWallpapers: migrating ================================= -- create_table(:wallpapers) -> 0.0021s == 20141229035713 CreateWallpapers: migrated (0.0023s) ======================== == 20141229040752 CreateImages: migrating ===================================== -- create_table(:images) -> 0.0009s == 20141229040752 CreateImages: migrated (0.0010s) ============================ == 20141230093231 AddImagesCountToWallpapers: migrating ======================= -- add_column(:wallpapers, :images_count, :integer, {:default=>0}) -> 0.0038s == 20141230093231 AddImagesCountToWallpapers: migrated (0.0039s) ============== == 20141230233607 CreateTags: migrating ======================================= -- create_table(:tags) -> 0.0010s == 20141230233607 CreateTags: migrated (0.0011s) ============================== == 20141230234524 CreateTaggings: migrating =================================== -- create_table(:taggings) -> 0.0010s -- add_index(:taggings, :tag_id) -> 0.0007s -- add_index(:taggings, [:taggable_id, :taggable_type]) -> 0.0012s == 20141230234524 CreateTaggings: migrated (0.0031s) ========================== == 20141231051856 CreatePools: migrating ====================================== -- create_table(:pools) -> 0.0011s == 20141231051856 CreatePools: migrated (0.0012s) ============================= == 20141231052318 CreatePoolings: migrating =================================== -- create_table(:poolings) -> 0.0009s == 20141231052318 CreatePoolings: migrated (0.0010s) ==========================
apostrophe からデータベースを持ってきて上書き。
tonzlr@wplj:~/tonzlr$ cd db tonzlr@wplj:~/tonzlr/db$ scp tonzlr@apostrophe:tonzlr/db/production.sqlite3 . tonzlr@apostrophe's password: production.sqlite3 100% 6721KB 6.6MB/s 00:00 tonzlr@wplj:~/tonzlr/db$ cd ..
assets のプリコンパイル。
tonzlr@wplj:~/tonzlr$ rake assets:precompile I, [2017-03-04T14:51:43.129624 #7460] INFO -- : Writing /home/tonzlr/tonzlr/public/assets/application-542d4bf5c7f8bc802982fa7761156fb8.js I, [2017-03-04T14:51:43.184646 #7460] INFO -- : Writing /home/tonzlr/tonzlr/public/assets/application-9084123bb8f8533cdd8e6f85fc1b536c.css
Rails 自身で配信するように、config/environments/production.rb を編集。
# Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = true
そして起動。SECRET_KEY_BASE 環境変数を設定するのを忘れないように。
tonzlr@wplj:~/tonzlr$ export SECRET_KEY_BASE=`rake secret` tonzlr@wplj:~/tonzlr$ bundle exec rails s -e production => Booting WEBrick => Rails 4.1.4 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server [2017-03-04 14:55:12] INFO WEBrick 1.3.1 [2017-03-04 14:55:12] INFO ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu] [2017-03-04 14:55:12] INFO WEBrick::HTTPServer#start: pid=7479 port=3000
これで、ブラウザでアクセスすると、動いているのが確認できた。
Flask アプリの引っ越しが完了したので、apostrophe (Ubuntu 14.04 LTS) で動いているもうひとつの WEB アプリ(Rails 製)を wplj (Ubuntu 16.04 LTS) に引っ越す。
このアプリはファイルを貯めこむタイプなので、事前に tar
コマンドと scp
コマンドを使って /media/aysheaia/wallpapers 以下にファイルを配置しておいた。
takatoh@wplj $ sudo adduser tonzlr [sudo] takatoh のパスワード: ユーザー `tonzlr' を追加しています... 新しいグループ `tonzlr' (1002) を追加しています... 新しいユーザー `tonzlr' (1002) をグループ `tonzlr' に追加しています... ホームディレクトリ `/home/tonzlr' を作成しています... `/etc/skel' からファイルをコピーしています... 新しい UNIX パスワードを入力してください: 新しい UNIX パスワードを再入力してください: passwd: パスワードは正しく更新されました tonzlr のユーザ情報を変更中 新しい値を入力してください。標準設定値を使うならリターンを押してください フルネーム []: 部屋番号 []: 職場電話番号 []: 自宅電話番号 []: その他 []: 以上で正しいですか? [Y/n] Y takatoh@wplj $ sudo gpasswd -a tonzlr sudo ユーザ tonzlr をグループ sudo に追加
ここからは上で作ったユーザで作業。
GitHub からクローンする。
tonzlr@wplj:~$ git clone https://github.com/takatoh/Tonzlr.git tonzlr
ディレクトリを移動して、依存パッケージをインストール。
tonzlr@wplj:~$ cd tonzlr tonzlr@wplj:~/tonzlr$ bundle install プログラム 'bundle' はまだインストールされていません。 'bundle' を利用するために、コンピュータの管理者に 'ruby-bundler' をインストールすることを相談してください
bundler がインストールされてなかった。インストール。
tonzlr@wplj:~/tonzlr$ sudo gem install bundler [sudo] tonzlr のパスワード: tonzlr は sudoers ファイル内にありません。この事象は記録・報告されます。
あれ?なんでだ?
仕方がないので、takatoh ユーザに戻ってインストール。
takatoh@wplj $ sudo gem install bundler
もう一度 tonzlr ユーザで。
tonzlr@wplj:~/tonzlr$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Installing rake 10.4.2 Installing i18n 0.7.0 Installing json 1.8.1 with native extensions Installing minitest 5.5.0 Installing thread_safe 0.3.4 Installing builder 3.2.2 Installing erubis 2.7.0 Installing rack 1.5.2 Installing mime-types 1.25.1 Installing polyglot 0.3.5 Installing arel 5.0.1.20140414130214 Installing coffee-script-source 1.8.0 Installing execjs 2.2.2 Installing thor 0.19.1 Installing hike 1.2.3 Installing multi_json 1.10.1 Installing libv8 3.16.14.3 (x86_64-linux) Using bundler 1.14.6 Installing tilt 1.4.1 Installing ref 1.0.5 Installing sass 3.2.19 Installing spring 1.2.0 Installing sqlite3 1.3.10 with native extensions Installing will_paginate 3.0.7 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator /usr/bin/ruby2.3 -r ./siteconf20170304-4815-1cena5t.rb 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 /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1 for inspection. Results logged to /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.1/gem_make.out An error occurred while installing json (1.8.1), and Bundler cannot continue. Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
む、なんかエラーが。ヘッダファイル ruby.h が見つからないのか?
再び takatho ユーザで。ああもう、いちいちめんどくさいな。
takatoh@wplj $ sudo apt install ruby-dev
tonzlr に戻ってもう一度。今度はどうだ。
tonzlr@wplj:~/tonzlr$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Using rake 10.4.2 Using i18n 0.7.0 Installing json 1.8.1 with native extensions Using minitest 5.5.0 Using thread_safe 0.3.4 Using builder 3.2.2 Using erubis 2.7.0 Using rack 1.5.2 Using mime-types 1.25.1 Using polyglot 0.3.5 Using arel 5.0.1.20140414130214 Using coffee-script-source 1.8.0 Using execjs 2.2.2 Using thor 0.19.1 Using hike 1.2.3 Using multi_json 1.10.1 Using libv8 3.16.14.3 (x86_64-linux) Using bundler 1.14.6 Using tilt 1.4.1 Using ref 1.0.5 Using sass 3.2.19 Using spring 1.2.0 Installing sqlite3 1.3.10 with native extensions Using will_paginate 3.0.7 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator /usr/bin/ruby2.3 -r ./siteconf20170304-5824-26t94o.rb extconf.rb creating Makefile current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" clean current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’: ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion] VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:239: ターゲット 'generator.o' のレシピで失敗しました make: *** [generator.o] エラー 1 make failed, exit code 2 Gem files will remain installed in /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1 for inspection. Results logged to /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.1/gem_make.out An error occurred while installing json (1.8.1), and Bundler cannot continue. Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
まだエラーが!
ググってみるとこのページに
cf. https://github.com/flori/json/issues/253
libgmp3-dev をインストールすればいい、みたいに書いてある。
takatoh@wplj $ sudo apt install libgmp3-dev
tonzlr@wplj:~/tonzlr$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/.......... Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Using rake 10.4.2 Using i18n 0.7.0 Installing json 1.8.1 with native extensions Using minitest 5.5.0 Using thread_safe 0.3.4 Using builder 3.2.2 Using erubis 2.7.0 Using rack 1.5.2 Using mime-types 1.25.1 Using polyglot 0.3.5 Using arel 5.0.1.20140414130214 Using coffee-script-source 1.8.0 Using execjs 2.2.2 Using thor 0.19.1 Using hike 1.2.3 Using multi_json 1.10.1 Using libv8 3.16.14.3 (x86_64-linux) Using bundler 1.14.6 Using tilt 1.4.1 Using ref 1.0.5 Using sass 3.2.19 Using spring 1.2.0 Installing sqlite3 1.3.10 with native extensions Using will_paginate 3.0.7 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator /usr/bin/ruby2.3 -r ./siteconf20170304-7573-1jyzrko.rb extconf.rb creating Makefile current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" clean current directory: /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’: ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion] VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:239: ターゲット 'generator.o' のレシピで失敗しました make: *** [generator.o] エラー 1 make failed, exit code 2 Gem files will remain installed in /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/gems/json-1.8.1 for inspection. Results logged to /home/tonzlr/tonzlr/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.1/gem_make.out An error occurred while installing json (1.8.1), and Bundler cannot continue. Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
まだダメだ。最後のメッセージのように json をインストールしてみる。
takatoh@wplj $ sudo gem install json -v '1.8.1' Fetching: json-1.8.1.gem (100%) Building native extensions. This could take a while... ERROR: Error installing json: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.3.0/gems/json-1.8.1/ext/json/ext/generator /usr/bin/ruby2.3 -r ./siteconf20170304-7998-r1om93.rb extconf.rb creating Makefile current directory: /var/lib/gems/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" clean current directory: /var/lib/gems/2.3.0/gems/json-1.8.1/ext/json/ext/generator make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’: ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast [-Wint-conversion] VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:239: ターゲット 'generator.o' のレシピで失敗しました make: *** [generator.o] エラー 1 make failed, exit code 2 Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.1 for inspection. Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.1/gem_make.out
ダメだな。詰んだか?
……というところで時間切れ。今日はここまで。