2015年4月14日 星期二

Appfog 雲端開發環境新作法

今天心血來潮檢查了佈署在 a000z.biz 的股市機器人, 發現竟然掛點了, 原因是我的定時抓取與分析資料的程式流量太大, 超出免費的配額, 必須升級為付費用戶才能繼續使用. 後台還是可以登入的, 但是裡面的操作功能被拿掉了.

這 a000z.biz 算是好的, 讓我的系統重載跑了一季左右. 之前就不斷寄信來說, 恭喜我的網站流量宏大, 生意興隆 (天知道那全是 GAE 機器人製造出來的), 希望我能付費升級, 以免超過免費額度, 果不其然真的被停了.

它的付費制最低是每月 3.99 美金, 估量目前還不是付費的時候, 所以腦筋就動到以前申請的免費 Appfog 雲端主機了. Appfog 自 2014/3/20 起已經取消免費帳戶了, 但之前已申請並在截止日前有登入確認的, 還是能保留免費帳戶, 只是配額縮水了. 現在 Appfog 新用戶最低消費額是每個月 20 元美金 (Basic 方案), 折合台幣約 600 元, 比起一般主機來說是貴了點.

Appfog 雲端虛擬主機
AppFog 新用戶要收費了

Appfog 後台管理必須用到 Ruby, 參考了之前寫的文章, 下載了 Ruby 1.9.3 版 (建議暫時不要用 2.x 版) :

# Appfog 要用 Ruby 1.9.3
http://rubyinstaller.org/downloads/

但完成後下 gem install af 卻發現無法安裝 Appfog 管理程式 :

E:\>cd mysnowball

E:\mysnowball>gem install af
Fetching: eventmachine-1.0.7.gem (100%)
ERROR:  Error installing af:
        The 'eventmachine' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

經查下列網頁才知, 光是 Ruby 不夠, 還必須先再安裝 Devkit 這個擴展工具 :

# Installing the AF CLI Tool on Windows
# Install Ruby and the Ruby DevKit

DevKit 下載位址與 Ruby 同一網頁 :


我下載的是搭配 Ruby 1.9.3 的 Devkit, 是個 7z 壓縮檔. 先在 C 碟下建立一個 Devkit 資料夾, 然後將此 7z 檔解壓縮在此資料夾下面. 完成後打開命令提示字元視窗, 切換至 Devkit, 執行初始化指令 :

c:\Devkit>ruby dk.rb init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

此初始化指令會在 Devkit 下產生一個 config.yaml 檔, 用來指定要搭配的 Ruby 版本, 用記事本開啟內容如下 :

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
- C:/Ruby193

其實就是指定我們之前已安裝的 Ruby 1.9.3 版的安裝路徑而已, 以便下一步安裝開發工具時找到複製檔案的目的地. 接著就下達安裝指令如下 :

c:\Devkit>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

這樣就安裝好 Ruby 開發工具了. 接著來安裝 JSON 藉以測試看看開發工具是否能用 :

c:\Devkit>gem install json --platform=ruby
Fetching: json-1.8.2.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed json-1.8.2
1 gem installed
Installing ri documentation for json-1.8.2...
Installing RDoc documentation for json-1.8.2...

回應訊息有 "native extension" 表示開發工具運作 OK. 這樣就可以安裝 Appfog 的開發工具了, 但是卻出現 Error :

c:\Devkit>gem install af
Fetching: rb-readline-0.4.2.gem (100%)
Successfully installed rb-readline-0.4.2
Fetching: uuidtools-2.1.5.gem (100%)
Successfully installed uuidtools-2.1.5
Fetching: addressable-2.2.8.gem (100%)
Successfully installed addressable-2.2.8
Fetching: interact-0.4.8.gem (100%)
Successfully installed interact-0.4.8
Fetching: terminal-table-1.4.5.gem (100%)
Successfully installed terminal-table-1.4.5
Fetching: mime-types-1.25.1.gem (100%)
Successfully installed mime-types-1.25.1
Fetching: rest-client-1.6.8.gem (100%)
Successfully installed rest-client-1.6.8
Fetching: rubyzip-0.9.9.gem (100%)
Successfully installed rubyzip-0.9.9
Fetching: json_pure-1.6.8.gem (100%)
Successfully installed json_pure-1.6.8
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing af:
        ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe -r ./siteconf20150415-2772-wnxdxi.rb extconf.rb
checking for main() in -lssl... no
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for ruby/thread.h... no
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... no
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... yes
checking for rb_time_new()... yes
checking for windows.h... yes
checking for winsock.h... yes
checking for main() in -lkernel32... yes
checking for main() in -lrpcrt4... yes
checking for main() in -lgdi32... yes
checking for clock_gettime()... no
checking for gethrtime()... no
creating Makefile

make  clean
Makefile:165: *** target pattern contains no `%'.  Stop.

make
Makefile:165: *** target pattern contains no `%'.  Stop.

make failed, exit code 2

Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/eventmach
ine-1.0.7 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/ev
entmachine-1.0.7/gem_make.out

看起來是無法建立 Native exteion 問題, 不知原因為何, 我以為是版本問題, 試著移除 Ruby 1.9.3, 改安裝 2.1 版還是一樣, 殘念 ~~~

試過公司的 Windows 7 安裝的 Ruby 1.9.3 沒問題 (本周末回鄉下時再用 Win7 系統的 AOD255 小筆電驗證看看), 以前在 XP 安裝 1.9.3 版也都 OK, 我懷疑跟 Win8 有關, 所以我看不要讓費時間在這上面, 反正程式要更新時再用 XP 或 Win7 系統即可. 或許過一陣子 Appfog 就解決此問題了.

# RubyGem 2.4.x and ruby 1.9.3 在DevKit時不合
# Installing the AF CLI Tool on Windows
# Installing AppFog client on Windows x64 with Ruby 2.0.0
https://bintray.com/oneclick/rubyinstaller/rubyinstaller/1.9.3-p545/view

2015-04-20 補充 :

昨晚在鄉下用 ACER XP 筆電與 D255 Win7 小筆電安裝 Ruby 1.9.3 版都失敗, 同樣是 extension 問題. 用 XP 桌電以前安裝的 Ruby 1.9.3 p545 可正常登入, 於是去找了 p545 來安裝還是不行. 可見不是作業系統問題, 也不是 Ruby 版本問題, 應該是 Appfog 的 af 安裝時程序跟以前不同造成的. 我想不用再花時間去研究了.



沒有留言 :