pistolfly: 2012年1月アーカイブ

Capfileに
load 'deploy/assets'
を追加すると、デプロイ時にassets:precompileを実行できるが、assets:precompile実行時に、
/usr/bin/env:
ruby
: そのようなファイルやディレクトリはありません
というエラーになってしまった。 ssh経由でのshellの実行時にPATHが通っていないのが原因と思われる。

解決方法

CapistranoでPATH等の環境変数を設定するには、:default_environmentを使う。

	
set :default_environment, {
  'PATH' => "/opt/ruby-enterprise-1.8.7-2011.03/bin:$PATH"
}


Change PATH environment with Rails and Capistrano - pastbedti.me
How do I configure capistrano to use my rvm version of Ruby - Stack Overflow

プリコンパイルする場合、config/environments/production.rbで、
config.assets.compile = false
にするが、assetsにapplication.js, application.css以外のjs、cssを使う場合は、以下のようにconfig.assets.precompileに追加する必要がある。追加しないと、smart_phone.css isn't precompiled のようなエラーになる。

config/environments/production.rb
config.assets.compile = false
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( smart_phone.css web_app_theme.css )

カテゴリー:

以下のようにTERMを設定したら解消。

$ crontab -e
TERM=xterm

カテゴリー:

カテゴリー:

mod_proxyでバックエンドのサーバがいったんダウンすると、復旧しても一定時間(デフォルトでは60秒)は 503 Service Temporarily Unavailable になってしまう。

リトライするまでの時間は、ProxyPassディレクティブ の retry パラメータで指定することができる。
(ProxyPass ディレクティブのスキームが balancer:// で始まる場合は、対応する <Proxy> セクション中の BalancerMember ディレクティブに retry パラメータを指定できる。)

ProxyPass / http://localhost:3000/ retry=5
ProxyPassReverse / http://localhost:3000/
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
<Proxy balancer://mycluster/>
  BalancerMember http://localhost:9001 loadfactor=10 retry=5
  BalancerMember http://localhost:9002 loadfactor=10 retry=5
  BalancerMember http://localhost:9003 loadfactor=10 retry=5
</Proxy>

mod_proxy - Apache HTTP サーバ
ProxyPass には retry=?? を指定しておく - daily dayflower
BalancerMemberにはretry=??を指定しておく - cys b

カテゴリー:

カテゴリー:

カテゴリー:

マルチユーザ用にRVMをインストール

マルチユーザ用にRVMをインストールするには、sudo でインストールする。

RVM: Ruby Version Manager - Installing RVM

$ sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
Downloading RVM from wayneeseguin branch stable

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). The default
 bundle is named curl-ca-bundle.crt; you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

Could not download 'https://github.com/wayneeseguin/rvm/tarball/stable'.
  Make sure your certificates are up to date as described above.
  To continue in insecure mode run 'echo insecure >> ~/.curlrc'.

curlのSSL証明書の検証でエラーになった。
CA証明書が古いらしい。
新しいCA証明書を取得する。

CA証明書のアップデート

$ sudo mv /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-bundle.crt.bak # バックアップ
$ sudo curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt

curlでまたSSLのエラーが出たので対処 - kanonjiの日記
cURL - Details on Server SSL Certificates
cURL - Extract CA Certs from Mozilla

再度sudoでRVMをインストール。

$ sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  796k  100  796k    0     0   170k      0  0:00:04  0:00:04 --:--:--  340k

Installing RVM to /usr/local/rvm/
installing - /usr/local/rvm/man/man1/rvm.1 -
installing - /usr/local/rvm/man/man1/rvm.1.gz -
    Creating RVM system user group 'rvm'

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.beginrescueend.com/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Installation of RVM in /usr/local/rvm/ is complete.

# XXXXXXXXX,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne

sudoでマルチユーザ用にインストールすると、RVMは /usr/local/rvm にインストールされる。

sudoを使うのは、RVM自体のインストール時のみ。

以降の操作は、sudoを使わない。rvm installやgem install など、/usr/local/rvm 下に書き込む操作は、rvmグループに所属しているユーザで行う。(/usr/local/rvmのグループがrvmになっている。)

RVM: Ruby Version Manager - Troubleshooting RVM
RVM をマルチユーザー用にセットアップする: ひ日記

ユーザのグループにrvmを追加。

# usermod -a -G rvm <ユーザ名>

ユーザをrvmグループに追加したら、いったんログアウトしてから、rubyやgemをインストール。
sudo しない。

$ rvm install 1.9.3
$ rvm use 1.9.3
$ gem install rails

RVMのアップデートも、sudoを使わず、rvmsudoを使う。

$ rvmsudo rvm get latest

カテゴリー:

Subversion 1.5 以降では、Merge Tracking 機能により、マージが楽になった。
フィーチャーブランチの典型的なマージ手順をメモしておく。

※以下の例で使用している、作業コピーのリポジトリーのルートディレクトリーのURLを表すキャレット (^) 記法は、Subversion 1.6 以降で可能です。

ブランチ作成

$ cd <いずれかの作業コピーのパス> # キャレット記法を使うために作業コピーに移動。フルでURL指定するなら不要。
$ svn cp ^/trunk ^/branches/br1

ブランチとtrunkの差分表示

$ cd <いずれかの作業コピーのパス> # キャレット記法を使うために作業コピーに移動。フルでURL指定するなら不要。
$ svn diff ^/trunk ^/branches/br1

trunkの最新をブランチにマージ

branchでの作業期間中、これを定期的に行う。

$ cd <ブランチの作業コピーのパス>
$ svn up # 作業コピーを最新にしておく
$ svn st # 作業コピーがクリーンであることを確認しておく
$ svn merge ^/trunk # ブランチの作業コピーにtrunkの最新をマージ
$ svn commit

ブランチをtrunkにマージ

branchでの修正が完了したら、最後にbranchをtrunkにマージする。
--reintegrate オプションが必要。

$ cd <trunkの作業コピーのパス>
$ svn up # 作業コピーを最新にしておく
$ svn merge --reintegrate ^/branches/br1
$ svn commit

いったん --reintegrate でマージされたブランチはもう使えない。

いったん削除する必要がある。
$ svn delete ^/branches/br1
ブランチでの作業を再開したい場合は、一度削除してから、ブランチを再作成する。
$ svn cp ^/trunk ^/branches/br1

削除したブランチのログを見たい

ブランチを削除しても、全てのリビジョンは残っているので、レポジトリのルートURLやブランチのルートURLなどに対して svn log すればよい。

$ cd <いずれかの作業コピーのパス> # キャレット記法を使うために作業コピーに移動。フルでURL指定するなら不要。
$ svn log ^/
$ svn log ^/branches


Basic Merging

カテゴリー:

my.cnf
[mysqld]
# ログの出力先
log_slow_queries = /var/log/mysql-slow.log
# これより実行に時間がかかる SQL ステートメントをロギング(秒)
long_query_time = 2

空のログファイルを作成し、パーミッションを設定後、mysqldを再起動する。

# touch /var/log/mysql-slow.log
# chown mysql:mysql /var/log/mysql-slow.log
# /etc/init.d/mysqld restart

ログをクリアする場合は、

# :> /var/log/mysql-slow.log

カテゴリー: