前提手順

rbenv – rails 環境作成 » # watch -d tail /var/log/ngsw.log

参考URL

nginxとPassengerでRailsアプリを動かしたよ – Umeyashikiの日記

手順

nginx Configuration options

# nginx -V

nginx: nginx version: nginx/1.1.7
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
nginx: TLS SNI support disabled
nginx: configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/

gem install passenger (rbenv)

$ gem install passenger

$ cd ~/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/

$ tree -a ~/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/bin

/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/bin
|-- passenger
|-- passenger-config
|-- passenger-install-apache2-module
|-- passenger-install-nginx-module
|-- passenger-make-enterprisey
|-- passenger-memory-stats
`-- passenger-status

0 directories, 7 files

install nginx module

$ ./passenger-install-nginx-module

1st

curl-devel が足りませんでした
Welcome to the Phusion Passenger Nginx module installer, v3.0.11.

This installer will guide you through the entire installation process. It
shouldn't take more than 5 minutes in total.

Here's what you can expect from the installation process:

 1. This installer will compile and install Nginx with Passenger support.
 2. You'll learn how to configure Passenger in Nginx.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.

 --------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * The 'make' tool... found at /usr/bin/make
 * A download tool like 'wget' or 'curl'... found at /usr/bin/wget
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /home/USER/.rbenv/versions/1.9.3-p0/bin/rake
 * rack... found
 * Curl development headers with SSL support... not found  #curl-devel がない
 * OpenSSL development headers... found
 * Zlib development headers... found

Some required software is not installed.
But don't worry, this installer will tell you how to install them.

Press Enter to continue, or Ctrl-C to abort.
<br />

<ul>
<li></li>
</ul>

Installation instructions for required software

 * To install Curl development headers with SSL support:
   Please run yum install curl-devel as root.             #curl-devel をインストールしなさいね

If the aforementioned instructions didn't solve your problem, then please take
a look at the Users Guide:

  /home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/doc/Users guide Nginx.html
yum install curl-devel.x86_64
Installed:
  curl-devel.x86_64 0:7.15.5-9.el5_7.4                                                              

Dependency Installed:
  libidn-devel.x86_64 0:0.6.5-1.1                                                                   

Complete!

2nd

nginx re-install

# diff -U0 ../nginx117/nginx_configure117.sh nginx_configure1112.sh

  --- ../nginx117/nginx_configure117.sh   2011-11-12 11:07:47.000000000 +0900
  +++ nginx_configure1112.sh      2012-01-08 00:26:47.000000000 +0900
  @@ -3,2 +3,2 @@
  -NGINX=nginx-1.1.7
  -SOURCE_DIR=/usr/local/src/NGINX/nginx117
  +NGINX=nginx-1.1.12
  +SOURCE_DIR=/usr/local/src/NGINX/nginx1112
  @@ -9,0 +10 @@
  +  --prefix='/usr/local/nginx' \
  @@ -23,0 +25,2 @@
  +  --with-cc-opt='-Wno-error' \
  +  --add-module='/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx' \
/usr/local/src/NGINX/nginx1112/nginx_configure1112.sh
  • ./configure ごにょごにょ && make
#!/bin/sh

NGINX=nginx-1.1.12
SOURCE_DIR=/usr/local/src/NGINX/nginx1112
id nginx || sudo useradd -s /sbin/nologin -d /usr/local/nginx -M nginx

cd $SOURCE_DIR/$NGINX
[ -e "$SOURCE_DIR/$NGINX/Makefile" ] &amp;&amp; make clean
./configure \
  --prefix='/usr/local/nginx' \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-http_realip_module \
  --http-log-path=/var/log/nginx/access.log \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --with-cc-opt='-Wno-error' \
  --add-module='/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx' \
&amp;&amp; make

# /usr/local/nginx/sbin/nginx -s stop

# cd /usr/local/src/NGINX/nginx1112/nginx-1.1.12
# make install

# /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.1.12
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
TLS SNI support disabled
configure arguments: --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-cc-opt=-Wno-error --add-module=/home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/nginx

ここまではあんま関係ないですね。

さて rails が以下のように配置されていたとして

/path/to/rails_root
|-- Gemfile
|-- Gemfile.lock
|-- README
|-- Rakefile
|-- app
|-- config
|-- config.ru
|-- db
|-- doc
|-- lib
|-- log
|-- public
|-- script
|-- test
|-- tmp
`-- vendor

nginx の設定ファイルは以下のようにした。

/etc/nginx/conf.d/rails.conf

#rails.conf
    server {
        listen       80;
        server_name  aaa.to;
        access_log  /var/log/nginx/aaa.to/access.log  main;
        error_log  /var/log/nginx/aaa.to/error.log;

        location / {
          root /path/to/rails_root/public;
          passenger_enabled on;
          index index.html index.htm;
          rails_env development;
        }
    }

/etc/nginx/nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

   #passenger
   passenger_root /home/USER/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11;
   passenger_ruby /home/USER/.rbenv/shims/ruby;
   #passenger

  #access_log  logs/access.log  main;

  sendfile        on;
  #tcp_nopush     on;

  #keepalive_timeout  0;
  keepalive_timeout  65;

  #gzip  on;

  server {
                listen       80;
    server_name  __default;
  }

  #include_zone
  include /etc/nginx/conf.d/rails.conf;
  #include_zone
}

うごいた!!

 
rbenvでrailsの動作環境を構築 – 吾輩のメモである
上記手順のほぼ引き写し。
rbenv以降から。

rbenv exec gem install bundler
cd /path/to/railsdir/

cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails", "3.1.3"
EOS

bundle install --path vendor/bundle
bundle exec rails new blog -d mysql

rm -f Gemfile
rm -f Gemfile.lock
rm -rf .bundle

cd blog
bundle install --path vendor/bundle
bundle exec rails g scaffold post title:string body:text

なんだけど、coffee-rails のところでエラーが出てしまったのでひとまず。

課題は Bundler と Gemfile の理解

Continue reading »

 
 rvm implode
 yum install readline-devel.x86_64 libyaml.x86_64
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
echo 'eval "$(rbenv init -)"' >> .bash_profile

rbenv-install 1.9.3-p0
rbenv global 1.9.3-p0
rbenv versions

gem install readline
gem update
gem update --system
gem install rails pry pry-doc
 
virt-clone \
  --connect=qemu:///system \
  -o ${sourcehost} \
  -n ${clonehost} \
  -f /var/lib/libvirt/images/${clonehost}.img
 
genkernel –menuconfig all だろうが、
genkernel all だろうが起動しない。

CDboot時には /dev/sda なのに、
カーネルコンパイル終えて起動すると /dev/hda としないと、
grub がきょとんとして実行されない。

genkernel.log を涙ながらに朗読をすることで、
カーネルのご機嫌を伺おうと考えたり、
クラシック音楽をかけながら優しい言葉をかけてコンパイルしてみたりと、
ほんとうに忙しい。

grubの設定は間違ってないと思うんだ
/dev/sda3 として設定した real_root を読み込めてないのが問題くさい
そこまではわかるんだけどね
rootfstype=ext3 って grub に書きやがれってことか
書いたよ書いてみたよ祈りながらexitしてumountしてrebootかますよ

キドウシナイ

(略)
∗ Starting udevd …         [ok]
∗ Populating /dev with existing devices through uevents … [ok]
∗ Waiting for uevents to be processed …       (ここで完全に停止する)

泣ける……。

udev をちょっと調べてみることにする。

2011/12/20 03:47 追記
って記事を涙ながらに書いてたら起動しそうになって嬉しい。
“Waiting for uevents to be processed” は本当に文字通りなんか頑張っていたようだ。
プログレスバーないんだもん。

(略)
∗ Waiting for uevents to be processed …  [ok]     (ここで停止してから15分くらいか)
∗ Mounting /dev/shm ...                  [ok]
∗ Setting system clock using the hardware clock [UTC]     [ok] (あとで直さないと)
∗ Loading module pci_hotplug ...         [ok]
∗ Autoloaded 1 module(s)
∗ Checking local filesystems ...
/dev/hda3: clean, 254460/3523856 files, 907507/14093968 blocks
/dev/hda1 was not cleanly unmounted, check forced.
/dev/hda1: |===============================                        \ 70.0%     (また止まっとる (´・ω・`) )

うえええ

 
CloudCloudCloudってのを作ってまして。
Facebook上で zonoise さんにいろいろ教えてもらってて。
で指摘受けたところをなおそうとしてたらハマったわけです、setIntervalの挙動に。

<script type="text/javascript">
var interval = 1000
for( var num = 0 ; num < 12 ; num ++ ){
    alert("1:" + num);      // 1
    setInterval(function(){
        alert("2:" + num);  // 2
    },interval);
    alert("3:" + num);      // 3
}
</script>

でbashでいうところの

interval=1
fuction setInterval()
{
  sleep $1
}
for num in `seq 0 11`
do
  echo "1:${num}"
  echo "2:${num}"
  setInterval ${interval}
  echo "3:${num}"
done

みたいなのを想像してた。
1 → 2 → setInterval(つまりsleep) → 3 → 1 → 2 → setInterval(つまりsleep) → 3 …
と実行されるだろう、という期待をしてたので、
1 → 3 → setInterval(つまりsleep) → 1 → 3 → setInterval(つまりsleep) → 1 → 3 → setInterval(つまりsleep) … → 2 → 2 → 2 → …
みたいな挙動に面食らったわけです。
で、Twitter上でotherworldyさんにもアドバイス受けたりしてようやく理解したわけですねー。

for(i=0;i<10;i++){
  setInterval(function(){ action(i);  },INTERVAL);}
}
action2;

ってのは、
INTERVALが過ぎないとsetIntervalで括ったfunction(){ action(i) }は、
全く実行されないんですね。
でその外側においておいた for の i++ がどんどん実行されるがために、
action の引数として利用しようと考えていたfor文由来の変数iが、
forの想定した最大値まで達しちゃうわけですねー。

「じゃあお前は結局どうしたのか?」っていうと
for文を使うのをやめました。
そもそもsetIntervalがループの役目果たしてたので、

var i=0
setInterval(function(){
  action(i);
    if( i >= 10 ){ action2;}
    i++;
  },INTERVAL);}
}

としました。すげーすっきりした。
※ちなみに action2 には “window.location.reload();” を想定していた。

 
文字列をコマンドにそのまま渡すスクリプトを書いていて、
MrMEEE / bumblebee – GitHub
の例とかもあるし、明日は我が身だしちょっくら気になったので。

#!/bin/sh
function atat()
{
  echo atat
  for i in $@
  do
    echo $i
  done
}
function dat()
{
  echo dat
  for i in "$@"
  do
    echo $i
  done
}
function ast()
{
  echo ast
  for i in $*
  do
    echo $i
  done
}
function dast()
{
  echo dast
  for i in "$*"
  do
    echo $i
  done
}

atat  1 2 3 "4 5 6" 7 8 9 10
echo ""
dat  1 2 3 "4 5 6" 7 8 9 10
echo ""
ast  1 2 3 "4 5 6" 7 8 9 10
echo ""
dast  1 2 3 "4 5 6" 7 8 9 10

$ sh test.sh

atat
1
2
3
4
5
6
7
8
9
10

dat
1
2
3
4 5 6
7
8
9
10

ast
1
2
3
4
5
6
7
8
9
10

dast
1 2 3 4 5 6 7 8 9 10

個人的には $”@” が意図しているものに近いかな。

 

typecheck.sh

githubにおいてます。

で source やらで読み込んでもらえましたら、

typecheck 10
result=$?
if [ ${result} = "0" ];then
  echo "run"
else
  echo "no run"
fi

と言うような使い方を想定してる。

なんで作成したか

職場において

  • 手順書の代わりになるスクリプトが必要だった
    • しかし手順書だとスピード遅い
    • かと言ってスクリプトを手拍子で実行されても困る

ので

  1. 実行するコマンドと関連ファイルを出力する
  2. 作業者は目視で確認する
  3. もちろん確認すべき内容はスクリプト側でも確認している
  4. 内容確認後 typecheck のコード入力
  5. コマンドが実行される

という流れ。車輪の再発明臭いですが。

 
com 920
net 920
info 180 / 920
org 380 / 920
biz 380 / 920
me 580 / 2290

so 1950
in 660 / 1950
mobi 920
us 580
ws 1470
be 1830

jp 2980
bz 2880
co 2880
cc 2880
tv 3480

vc 4180
cx 4800

sc 9800
ac 7920
cm 11960
am 9330
mu 8480
tw 3920
hn 8480
fm 9330
la 4180
ms 4040
mx 6140
cz 3480
vg 4040
gs 4040
mn 5400

 
[接続方法/iPhone 3G の場合 :: WIRELESS GATE](http://www.tripletgate.com/wirelessgate/use/iphone.html “接続方法/iPhone 3G の場合 :: WIRELESS GATE”)
無線LANネットワーク接続情報

ネットワーク名:mobilepoint
パスワード:696177616b (WEP)

ネットワーク名:livedoor-web
パスワード:656c626a3633706f327077396a (WEP)

ネットワーク名:NRT-AIRPORT
パスワード:なし

ネットワーク名:UQ_Wi-Fi
パスワード:2u2w6 (WEP)

© 2011 # watch -d tail /var/log/ngsw.log Suffusion theme by Sayontan Sinha