なんかすかっつるを入れてみようと思い立って入れてみたら
さびしい感じだったので、はてなみたいなスクリーンショットを
付けてみようと探してみました。

HP: http://mozshot.nemui.org/

SimpleAPIとかmozshotとか色々ある中で、ソース配布していたので
mozshotを採用します。

fcgi関連でhttpdが重くなったので現在停止中です。

事前準備

Xvfbと言うのを入れて仮想Xみたいな環境からブラウザを立ち上げて
スクリーンショットを取るという感じです?
うちではFirefoxを使うとおかしくなったのでxulrunnerを使用してやっています。

yum install ruby-gnome2 ruby-gtkmozembed Xvfb xulrunner

/etc/init.d/Xvfb

#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops XVfb. \
# used to provide virtual frame buffer.

# Source function library.
. /etc/init.d/functions

prog=$"Xvfb"

# Xvfb program
XVFB=/usr/bin/Xvfb

start() {
echo -n $"Starting $prog: "
daemon /usr/bin/Xvfb :1 -screen 0 1600x1200x24 &
echo
}

stop() {
echo -n $"Shutting down $prog: "
killproc Xvfb
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

起動

chmod 755 /etc/init.d/Xvfb
chkconfig --add Xvfb
chkconfig --level 2345 Xvfb on
/etc/init.d/Xvfb start

インストール

cd /usr/local/src
git clone git://github.com/sugi/mozshot.git
cp -r mozshot /usr/local/apache2/htdocs/mozshot

設定

/usr/local/apache2/htdocs/mozshot/mozshot.rb
34行目付近のwinsizeとかをお好みのサイズに変更

:winsize => [1600, 1200], :imgsize => [],

~/.bash_profile

export MOZILLA_FIVE_HOME="/usr/lib/xulrunner-1.9/"
export DISPLAY=:1.0
64bitの場合は以下
export MOZILLA_FIVE_HOME="/usr/lib64/xulrunner-1.9/"
export DISPLAY=:1.0

サンプルスクリプトに記述されてるlib/timestamp.rbの場所が違うので
ルートにコピーしておきます。

cp /usr/local/apache2/htdocs/mozshot/lib/timestamp.rb /usr/local/apache2/htdocs/mozshot

/usr/local/apache2/htdocs/mozshot/start.sh

DIR=/usr/local/apache2/htdocs/mozshot
cd $DIR
./ts.rb &
export MOZILLA_FIVE_HOME="/usr/lib64/xulrunner-1.9/"
export DISPLAY=:1.0
$DIR/examples/run-mozshot

cronに以下を追加

DIR=/usr/local/apache2/htdocs/mozshot
# mozshot
@reboot cd $DIR && ./start.sh >/dev/null 2>&1
*/2 * * * * cd $DIR/web-ui && nice -19 ruby -r ../timestamp.rb ../utils/flush-result.rb >> $DIR/log/mozshot-result.log

/usr/local/apache2/conf/httpd.conf

LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiIpcDir /tmp/fcgi
AddHandler fastcgi-script .fcg .fcgi
< VirtualHost *:80>
ServerName shot.momo-i.org
ServerAdmin webmaster@momo-i.org
DocumentRoot /usr/local/apache2/htdocs/mozshot/web-ui
KeepAliveTimeout 1

DefaultLanguage en
ForceLanguagePriority Prefer Fallback

CustomLog logs/access_log_shot combined

Alias /shot /usr/local/apache2/htdocs/mozshot/web-ui/shot.fcgi
Alias /shot.fcgi /usr/local/apache2/htdocs/mozshot/web-ui/shot.fcgi
Alias /shot.cgi /usr/local/apache2/htdocs/mozshot/web-ui/shot.cgi
Alias /cache /usr/local/apache2/htdocs/mozshot/web-ui/cache

RewriteEngine on

<Directory /usr/local/apache2/htdocs/mozshot>
AllowOverride None
Options ExecCGI MultiViews SymLinksIfOwnerMatch IncludesNoExec
AddDefaultCharset UTF-8
</Directory>

<Directory /usr/local/apache2/htdocs/mozshot/cache>
Options None
ExpiresActive On
ExpiresDefault "modification plus 6 hours"
</Directory>

RewriteRule ^/$ /usr/local/apache2/htdocs/mozshot/rails-ui/public/dispatch.fcgi
RewriteCond %{REQUEST_URI} !^/(cache|shot|error)
RewriteRule ^(.*)$ /usr/local/apache2/htdocs/mozshot/rails-ui/public$1 [C]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule . /usr/local/apache2/htdocs/mozshot/rails-ui/public/dispatch.fcgi%1 [QSA,L]
< /VirtualHost>

起動

cd /usr/local/apache2/htdocs/mozshot
mkdir log
chown -R apache. /usr/local/apache2/htdocs/mozshot
export MOZILLA_FIVE_HOME="/usr/lib64/xulrunner-1.9/"
export DISPLAY=:1.0
./ts.rb &
examples/run-mozshot &

Apacheの再起動をしてhttp://shot.momo-i.org/shot?http://www.google.com/
などのようにアクセスをすると最初はNowPrintingと表示されていますが
2分間隔でスクリーンショットを取りに行ってGoogleのトップ画面が表示されるようになります。

コメントを追加

制限付き HTML

  • 使用できるHTMLタグ: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 行と段落は自動的に折り返されます。
  • ウェブページのアドレスとメールアドレスは自動的にリンクに変換されます。
CAPTCHA
半角で
この質問はあなたが人間の訪問者であるかどうかをテストし、自動化されたスパム送信を防ぐためのものです。
ももーい に投稿