2015年4月12日日曜日

そろそろ sysctl


そろそろ sysctl

https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-proc-sysctl.html

sysctlによるカーネルのチューニング
http://sourceforge.jp/magazine/08/09/12/0134255

sysctl でカーネルパラメータを変更する
http://www.usupi.org/sysad/240.html


ansible
Manage entries in sysctl.conf
http://docs.ansible.com/sysctl_module.html

Mac OS X
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/sysctl.8.html

VPC(AWS)でsysctl にはまった話
http://techblog.clara.jp/2015/01/aws-nat-instance-boot/

web でmarkdown のプレビュー


markdown のプレビュー
https://tibastral.github.io/markdownify/


2015年4月7日火曜日

link_to のラッパー


link_to の拡張

# app/helpers/application_helper.rb
def link_to(text, path, options = {}, &block)
  # do someting
  super
  # do someting
end


To extend rails' `link_to`, should I use `alias_method_chain` or mixins + inheritance?
http://stackoverflow.com/a/13566131

オリジナルのlink_to はactionview の
lib/action_view/helpers/url_helper.rb
に定義されてる。

2015年4月4日土曜日

最近のWeb Framwork @ Python

Django1.8 がリリースされた。

でなぜか、久しぶりにPython のWebフレームワークをいくつか検索してみた。
フルスタックはDjangoだけど、 相変わらず lightweight界隈は活発。

wheezy.web
https://pythonhosted.org/wheezy.web/

Falcon
http://falconframework.org/

Guava
https://github.com/StarfruitStack/guava
内部はCで書かれている

Werkzeug からの移行を考える。
Morepath: from Werkzeug to WebOb
http://blog.startifact.com/posts/morepath-from-werkzeug-to-webob.html
Werkzeug よりもWebOb, wheezy.http の方がパフォーマンスは上。
ベースとして使っているライブラリでこんなに差があると、werkzeug 使うのやめようかなと思ってしまう。


CMS だけど、これも今度使ってみる。
(DjangoをベースにしたCMS)
https://wagtail.io/

2015年2月26日木曜日

ドワンゴの開発


Developers Summit 2014 「Play2/Scalaでドメイン駆動設計を利用した大規模Webアプリケーションのスクラム開発の勘所」



2015年2月25日水曜日

turbolinks で jquery.ready が動かない


var ready = function() {
  ...your javascript goes here...
};

$(document).ready(ready);
$(document).on('page:load', ready);  // turbolinks対応


http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links


page:load, ready 以外にも
https://github.com/rails/turbolinks/

2015年2月21日土曜日

Passenger 5


passenger が刷新されてる?

https://www.phusionpassenger.com/
https://github.com/phusion/passenger


Passenger 5 (コードネームはラプター)

「RaptorはどのようにしてUnicornの4倍、Puma, Torqueboxの2倍の速度を達成したのか」を読んでまとめてみた


とりあえず、standalone で動かしてみた。
(nginx は yum でインストールしたものなので、standalone しか道はない)
環境は centos7, rbenv
nginx --- passenger5 --- rails


インストール
rails のGemfile に追加# Gemfile
gem passenger, '5.0.5'

$ bundle install --path vendor/bundle

# rails のbin にpassenger コマンドを追加
# bin/passenger が作成される
bundle install --binstubs
(bin/passenger でなく、bundle exec passenger でもたぶんOKだと思う)

# 確認
$ bin/passenger start
 (デフォルトでは http://0.0.0.0:3000/ )

# nginx 経由でアクセスする。
# ドメインは raptor.local として、hosts に登録しておく。

$ vi /etc/nginx/conf.d/raptor.local.conf
server {
    listen 80;
    server_name raptor.local;

    location / {
        proxy_pass http://0.0.0.0:3000;
    }
}

# 変更を反映させる
$ systemctl reload nginx

これで、http://raptor.local/ でアクセスできる。
次に、systemd に登録してデーモン化する。

# サービス名を raptor.service としておく。
vi /etc/systemd/system/raptor.service

[Unit]
Description=Raptor (passenger5 standalone) with rails
After=syslog.target network.target nss-lookup.target

[Service]
Type=forking
User=hoge
Group=hoge
WorkingDirectory=/public/raptor
PIDFile=/public/raptor/tmp/pids/passenger.3000.pid

ExecStart=/public/raptor/bin/passenger start --daemonize
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable raptor
systemctl start raptor

# /etc/systemd/system/raptor.service を変更したら
$ systemctl daemon-reload


メモ、注意点、TODO
 - bin/passenger start --help でオプションの確認ができる
 -  --deamonize は必須
 - Unix domain の利用を考える (--socket オプション)
 - プロセス数の指定
 - この設定だと development でrails が動いているので変更も即座に反映してくれる。
(production 指定も調べる)



最後にrbenv について
rbenv はユーザーhoge だけに有効なので
(/home/hoge/.rbenv にインストールした)
bin/passenger の先頭を以下のように変更した。
#!/usr/bin/env ruby
  ↓
#!/home/hoge/.rbenv/versions/2.2.1/bin/ruby

/usr/local にインストールしたり、他の方法もあるのかもしれないけど、わからないので、自分(作業ユーザー) のrbenv を直接指定して動かした。