前提

Scientifc Linux 6.1 + nginx / yum 起動スクリプトを流用する » # watch -d tail /var/log/ngsw.log

検証

# nginx -V 2>&1 |grep --color '\-\-pid-path.*.pid'
  (snip)
  --pid-path=/var/run/nginx/nginx.pid
  (snip)

# ls /var/run/nginx/nginx.pid
  ls: cannot access /var/run/nginx/nginx.pid: そのようなファイルやディレクトリはありません

# nginx -t
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful

# ls /var/run/nginx/nginx.pid
  /var/run/nginx/nginx.pid

# ?(´・ω・`)?

# /etc/init.d/nginx status
  nginx が停止していますが PID ファイルが残っています

# ?(´・ω・`)?

# /etc/init.d/nginx stop
  nginx を停止中: [失敗]

# ??(´・ω・`)??

# ls /var/run/nginx/nginx.pid
  ls: cannot access /var/run/nginx/nginx.pid: そのようなファイルやディレクトリはありません

# こういうものですか?
view raw nginx_t This Gist brought to you by GitHub.

ソースみてみなきゃな話だなー。

 

ようやくわかった

passenger_ruby /home/USER/.rbnev/versions/1.9.3-p0/bin/ruby;

passenger_ruby /home/USER/.rbnev/shims/ruby;
としていたため。とりあえずベタ書きで対応。

稼動しているサーバから持ってきた設定であったが、
おそらく以下のようなdot-file設定等々に影響してるのだろうな、と。
export PATH=”$HOME/.rbenv/bin:$PATH”
eval “$(rbenv init -)”
source ~/.rbenv/completions/rbenv.bash


今気がついて、まだ直せていない


/etc/init.d/nginx で起動すると
/home/USER/.rbenv/shims/ruby: line 4: exec: rbenv: not found
がnginxのerror_logに出続けるので修正する
例えば http://exmaple.com/ にアクセスするとして
Cannot spawn application ‘/path/to/rails_root’: Could not read from the spawn server: Connection reset by peer (104)
というエラーがでる
/usr/local/nginx/sbin/nginx も /etc/init.d.nginx start も
期待通りの挙動を示していないため、passengerとの連携に問題があると言えそう。
WEBRICK単独ではsinatraさんは期待通りに動いてくれている。

Continue reading »

 

WordPress に Gist コードを埋め込む Embed GitHub Gist

WordPressのコード埋め込みはGistでいいんじゃないかな
これいいと思った。
WordPress › Embed GitHub Gist « WordPress Plugins

手順レベルのものを gist にぺたぺたしてるし、
なによりシンタックスハイライト系がエンティティエンティティするからもういらついていらついて。

こんな感じで VMware せこせこ作ってる

yum install readline-devel.x86_64 libyaml.x86_64 tree nkf
yum install mysql mysql-server git
yum install readline-devel.x86_64 libyaml.x86_64 openssl-devel.x86_64 mysql-devel.x86_64
yum install gcc make zlib-devel gcc-c++

git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bashrc
echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc
echo "source ~/.rbenv/completions/rbenv.bash" >> $HOME/.bashrc
cd $HOME
git clone git://github.com/sstephenson/ruby-build.git
cd $HOME/ruby-build
sudo ./install.sh

rbenv-install 1.9.3-p0
rbenv global 1.9.3-p0
rbenv rehash
rbenv versions
rbenv exec gem install rails pry pry-doc

cd /path/to/railsdir/

cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails", '~>3.2.0.rc2'
EOS


bundle install --path vendor/bundle
bundle exec rails new railsapp -d mysql
 
rm -f Gemfile
rm -f Gemfile.lock
rm -rf .bundle

cd railsapp
 #Gemfile追記 gem 'therubyracer'
bundle install --path vendor/bundle
bundle exec rails g scaffold post title:string body:text


# sl は $releasever をベタ書き
cat > /etc/yum.repos.d/nginx.repo <<'nginxREPO'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/6/$basearch/
gpgcheck=0
enabled=1
nginxREPO

# ばっといれとく curl-devel は passenger あたりで言われる
yum install gcc pcre* zlib* openssl* gd* libpng* libjpeg* GeoIP* curl-devel

# /etc/init.d/nginx ファイルが欲しい
yum install nginx
cp -a /etc/init.d/nginx /root/
yum remove nginx

# rbenv 使ってるユーザで
$ rbenv exec gem install rake
$ rbenv exec gem install passenger

# nginx 入れる
export nginx_ver="1.1.14"
export nginx_configure_script="nginx_configure_`echo ${nginx_ver}|sed -e 's/\./_/g'`.sh"
mkdir /usr/local/src/NGINX/
cd /usr/local/src/NGINX
wget http://nginx.org/download/nginx-${nginx_ver}.tar.gz
tar zxvf nginx-${nginx_ver}.tar.gz

echo '#!/bin/sh

NGINX=nginx-NGINX_VER
SOURCE_DIR=/usr/local/src/NGINX
id nginx || sudo useradd -s /sbin/nologin -d /usr/local/nginx -M nginx
 
cd $SOURCE_DIR/$NGINX
[ -e "$SOURCE_DIR/$NGINX/Makefile" ] && 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" \
&& make
' | sed -e "s/NGINX_VER/${nginx_ver}/g" > /usr/local/src/${nginx_configure_script}

# でpassengerのコンパイルで使う rake を root が見つけられずで実行できないから、
# /home/USER/.rbenv/shims を PATHに追加しちまったよ
# このやり方賢くない……

sh /usr/local/src/${nginx_configure_script}
cd /usr/local/src/NGINX/${nginx_ver}
make install

# とりあえずここまで

 

前提手順

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;&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' \
&& 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 »

 
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%     (また止まっとる (´・ω・`) )

うえええ

 
文字列をコマンドにそのまま渡すスクリプトを書いていて、
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

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