さくらVPSでサイト運用を手っ取り早くやってみた
さくらVPSのリニューアルプランに乗り換えたついでに、サイト作り直した上で、今まで放置してた運用環境の整理にも手をつけることにした。
以下の組み合わせを使った上で、git pushにてhookさせてdaemonの再起動とかも目論む。
- nginx
- supervisor
daemontoolsを使おうと試してたけど、色々面倒になってsupervisorにした。
gitのリモートリポジトリ設置
内容としては以前書いたこの記事と殆ど変わらない。
#git user 追加 adduser git passwd git su - git #リモートのリポジトリ設置 mkdir -p repos/WebSite.git cd repos/WebSite.git git init --bare
ローカルからサイト用のデータをpush
軽めでいいのでAmon2::Liteに。
amon2-setup.pl WebSite --flavor=Lite cd WebSite git commit -v git remote add origin git@xxx.xxx.xxx:repos/WebSite.git git push origin master
nginxをいれる
aptitude install nginx vim /etc/nginx/nginx.conf
nginx内の設定は、静的ファイルについてはそのまま渡す形にした。
http { server { server_name xxx.xxx.xxx; location / { proxy_pass http://127.0.0.1:9002; } location ~ .*\.(jpg|JPG|gif|GIF|png|PNG|swf|SWF|css|CSS|js|JS|inc|INC|ico|ICO) { root /home/git/www/WebSite/; index index.html; ssi on; break; } }
supervisorを導入する
supervisorのcommandから呼び出すスクリプト。git pushで更新するため、リポジトリの中に含めておく。
#!/bin/sh exec 2>&1 exec /home/git/perl5/perlbrew/perls/perl-5.12.4/bin/start_server --port=9002 -- \ /home/git/perl5/perlbrew/perls/perl-5.12.4/bin/plackup -s Starlet \ --max-workers=10 \ --max-keepalive-reqs=1 \ --max-reqs-per-child=10000 \ -a /home/git/www/WebSite/app.psgi
supervisorの導入。
su - aptitude install supervisor vim /etc/supervisord.conf ;[unix_http_server] ;file=/tmp/supervisor.sock ; (the path to the socket file) [inet_http_server] ; inet (TCP) server disabled by default port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
supervisorの設定ファイル。
- /etc/supervisord.d/webroot.ini
[program:webroot] user=git command=/home/git/www/WebSite/webroot/run redirect_stderr=true stdout_logfile=/var/log/supervisor/webroot.log stdout_logfile_maxbytes = 10MB stdout_logfile_backups = 5 autostart = true autorestart = true startsecs = 5
サービス化させる。
supervisorctl reread supervisorctl add webroot
一通りここまでやってbind時にAddress already useと出てた。ぐぐってみたところipv6周りが原因らしい。無効にしてみたところ正常動作。
supervisorctl status
webroot RUNNING
hook用スクリプトを更新
とりあえずこんなものでいいかな、という具合に。
- hook/post-receive
cd /home/git/www/WebSite;git --git-dir=.git pull; /bin/chown git:git /home/git/www/WebSite/webroot/run; /usr/local/bin/supervisorctl stop webroot; /usr/local/bin/supervisorctl start webroot;
監視もいれたいなーと思いつつも、とりあえずはこれでいいかという気分になったのでこのくらいで。
参考URL