<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>FastCGIでBazaarを提供する — Bazaar v2.2.4 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.2.4', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <link rel="shortcut icon" href="../_static/bzr.ico"/> <link rel="top" title="Bazaar v2.2.4 documentation" href="../index.html" /> <link rel="up" title="Bazaarユーザーガイド" href="index.html" /> <link rel="next" title="プラグインを書く" href="writing_a_plugin.html" /> <link rel="prev" title="Eメールを設定する" href="setting_up_email.html" /> </head> <body> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="writing_a_plugin.html" title="プラグインを書く" accesskey="N">次へ</a></li> <li class="right" > <a href="setting_up_email.html" title="Eメールを設定する" accesskey="P">前へ</a> |</li> <li><a href="../index.html">目次 (2.2.4)</a> »</li> <li><a href="index.html" accesskey="U">Bazaarユーザーガイド</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="fastcgibazaar"> <h1>FastCGIでBazaarを提供する<a class="headerlink" href="#fastcgibazaar" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>このドキュメントでは、Apache 2.0とFastCGIもしくはmod_pythonを利用して Bazaar HTTPスマートサーバーをセットアップする1つの方法を説明します。</p> <p>スマートサーバーに関する詳細な情報とそれを設定する他の方法に関しては、 メインのスマートサーバーのドキュメントを参照してください。</p> <div class="section" id="id1"> <h2>例<a class="headerlink" href="#id1" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>プレーンなHTTPで <cite>/srv/example.com/www/code</cite> を <cite>http://example.com/code/...</cite> として すでに公開しているとします。これはbzrのブランチと <cite>/srv/example.com/www/code/branch-one</cite> と <cite>/srv/example.com/www/code/my-repo/branch-two</cite> のようなディレクトリを含みます。 既存のHTTP形式のアクセス権限に加えてリードオンリーのスマートサーバーのアクセス権限を これらのディレクトリに提供したい場合を考えます。</p> </div> <div class="section" id="apache-2-0"> <h2>Apache 2.0を設定する<a class="headerlink" href="#apache-2-0" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="fastcgi"> <h3>FastCGI<a class="headerlink" href="#fastcgi" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>最初に、mod_fastcgiを設定します。たとえば次の行をhttpd.confに追加します:</p> <div class="highlight-python"><pre>LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so FastCgiIpcDir /var/lib/apache2/fastcgi</pre> </div> <p>我々の例では、`http://example.com/code` で <cite>/srv/example.com/www/code</cite> をすでに提供しているので 既存のApacheの設定は次のようになります:</p> <div class="highlight-python"><pre>Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes # ... </Directory></pre> </div> <p>.bzr/smartの形式で終わるURLに対するすべてのリクエストを扱うために 次のように変更する必要があります:</p> <div class="highlight-python"><pre>Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes FollowSymLinks RewriteEngine On RewriteBase /code RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi </Directory> # bzr-smart.fcgiはDocumentRootの元に存在しないので、実行されるように # AliasはこれをURLの名前空間のエイリアスにする。 Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi <Directory /srv/example.com/scripts> Options ExecCGI <Files bzr-smart.fcgi> SetHandler fastcgi-script </Files> </Directory></pre> </div> <p>この設定はFastCGIを通して <cite>/code</cite> 内部の <cite>/.bzr/smart</cite> で終わるURLに対する Bazaarのスマートサーバーへのリクエストを扱うようにApacheに指示します。</p> <p>詳細な情報は <a class="reference external" href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a> と <a class="reference external" href="http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html">mod_fastcgi</a> のドキュメントを参照してください。</p> </div> <div class="section" id="mod-python"> <h3>mod_python<a class="headerlink" href="#mod-python" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>最初に、次のようなコードをhttpd.confに追加してmod_pythonを設定します:</p> <div class="highlight-python"><pre>LoadModule python_module /usr/lib/apache2/modules/mod_python.so</pre> </div> <p>FastCGIと同じ方法でmod_rewriteを用いて書き換えルールを定義します:</p> <div class="highlight-python"><pre>RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi</pre> </div> <p>変更は次のようになります:</p> <div class="highlight-python"><pre>RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py</pre> </div> <p>mod_fastcgiのように、スクリプトがどのように扱われるのかも定義します:</p> <div class="highlight-python"><pre>Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py <Directory /srv/example.com/scripts> <Files bzr-smart.py> PythonPath "sys.path+['/srv/example.com/scripts']" AddHandler python-program .py PythonHandler bzr-smart::handler </Files> </Directory></pre> </div> <p>この設定はmod_pythonを通して <cite>/code</cite> 内部の <cite>/.bzr/smart</cite> で終わるURLに対するリクエストを Bazaarのスマートサーバーに渡すように指示します。</p> <p>注: bzrlibがPATHの中に存在しない場合、次の行を変更する必要があります:</p> <div class="highlight-python"><pre>PythonPath "sys.path+['/srv/example.com/scripts']"</pre> </div> <p>変更後は次のようになります:</p> <div class="highlight-python"><pre>PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']"</pre> </div> <p>詳細な情報は <a class="reference external" href="http://www.modpython.org/">mod_python</a> のドキュメントを参照してください。</p> </div> </div> <div class="section" id="bazaar"> <h2>Bazaarを設定する<a class="headerlink" href="#bazaar" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="id3"> <h3>FastCGI<a class="headerlink" href="#id3" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><cite>/srv/example.com/scripts/bzr-smart.fcgi</cite> でスマートサーバーを実行するためにApacheを設定しました。 これはスマートサーバーを設定するために書く必要のある単なるシンプルなスクリプトで サーバーをFastCGIのゲートウェイに結びつけます。次のようになります:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">fcgi</span> <span class="kn">from</span> <span class="nn">bzrlib.transport.http</span> <span class="kn">import</span> <span class="n">wsgi</span> <span class="n">smart_server_app</span> <span class="o">=</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">make_app</span><span class="p">(</span> <span class="n">root</span><span class="o">=</span><span class="s">'/srv/example.com/www/code'</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">'/code/'</span><span class="p">,</span> <span class="n">path_var</span><span class="o">=</span><span class="s">'REQUEST_URI'</span><span class="p">,</span> <span class="n">readonly</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">load_plugins</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">enable_logging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="n">fcgi</span><span class="o">.</span><span class="n">WSGIServer</span><span class="p">(</span><span class="n">smart_server_app</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> </pre></div> </div> <p> `fcgi`のモジュールはhttp://svn.saddi.com/py-lib/trunk/fcgi.pyで見つかります。 これは <a class="reference external" href="http://www.saddi.com/software/flup/">flup</a> の一部です。</p> </div> <div class="section" id="id4"> <h3>mod_python<a class="headerlink" href="#id4" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><cite>/srv/example.com/scripts/bzr-smart.py</cite> でスマートサーバーを実行するためにApacheを設定しました。 これはスマートサーバーを設定するために書く必要のあるシンプルなスクリプトでサーバーをmod_pythonの ゲートウェイに結びつけます。次のようになります:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">modpywsgi</span> <span class="kn">from</span> <span class="nn">bzrlib.transport.http</span> <span class="kn">import</span> <span class="n">wsgi</span> <span class="n">smart_server_app</span> <span class="o">=</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">make_app</span><span class="p">(</span> <span class="n">root</span><span class="o">=</span><span class="s">'/srv/example.com/www/code'</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">'/code/'</span><span class="p">,</span> <span class="n">path_var</span><span class="o">=</span><span class="s">'REQUEST_URI'</span><span class="p">,</span> <span class="n">readonly</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">load_plugins</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">enable_logging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="k">def</span> <span class="nf">handler</span><span class="p">(</span><span class="n">request</span><span class="p">):</span> <span class="sd">"""Handle a single request."""</span> <span class="n">wsgi_server</span> <span class="o">=</span> <span class="n">modpywsgi</span><span class="o">.</span><span class="n">WSGIServer</span><span class="p">(</span><span class="n">smart_server_app</span><span class="p">)</span> <span class="k">return</span> <span class="n">wsgi_server</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> </pre></div> </div> <p><cite>modpywsgi</cite> モジュールは <cite>http://dev.pocoo.org/projects/pocoo/browser/pocoo/wrappers/modpy.py</cite> で見つかります。 これは <a class="reference external" href="http://dev.pocoo.org/projects/pocoo/">pocoo</a> の一部です。modpywsgi.pyをbzr-smart.pyと同じディレクトリ (すなわち/srv/example.com/scripts/)に設置していることを確認してください。</p> </div> </div> <div class="section" id="id5"> <h2>クライアント<a class="headerlink" href="#id5" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>これで <cite>bzr+http://</cite> 形式のURLを利用できます:</p> <div class="highlight-python"><pre>bzr log bzr+http://example.com/code/my-branch</pre> </div> <p>プレーンなHTTP形式のアクセスも持続します:</p> <div class="highlight-python"><pre>bzr log http://example.com/code/my-branch</pre> </div> </div> <div class="section" id="id6"> <h2>高度な設定<a class="headerlink" href="#id6" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>BazaarのHTTPスマートサーバーはWSGIアプリケーションなので、 WSGI標準に準拠するサードパーティのWSGIのミドルウェアもしくはサーバーで利用できます。 唯一の要件は以下のとおりです:</p> <blockquote> <div><ul class="simple"> <li> `SmartWSGIApp` をコンストラクトするためには、それが提供する <strong>root transport</strong> を指定する必要があります。</li> <li>それぞれのリクエストの <cite>environ</cite> dict は <strong>‘bzrlib.relpath’</strong> 変数の設定を持たなければなりません。</li> </ul> </div></blockquote> <p>この例で使われている <cite>make_app</cite> ヘルパーは それに渡される <cite>root</cite> パスに基づいたトランスポートを伴う <cite>SmartWSGIApp</cite> をコンストラクトし、引数 <cite>prefix</cite> と`path_var` に基づくそれぞれのリクエストに対する `bzrlib.relpath` を算出します。 上記の例において、これは (Apacheによって設定される)’REQUEST_URI’ を取り、接頭辞の ‘/code/’ と接尾辞の ‘/.bzr/smart’ をはぎ取り、それを ‘bzrlib.relpath’ として設定するので、 ‘/code/foo/bar/.bzr/smart’ に対するリクエストは ‘foo/bzr’ の ‘bzrlib.relpath’ になります。</p> <p><cite>SmartWSGIApp</cite> を直接コンストラクトすることで、ローカルではないトランスポートに対して スマートサーバーを設定するもしくは任意任意のパスの変換を行うことは可能です。 詳細な情報に関しては <cite>bzrlib.transport.http.wsgi</cite> のdocstringsと <a class="reference external" href="http://www.python.org/dev/peps/pep-0333/">WSGI標準</a> を参照してください。</p> <div class="section" id="bzr-http-push"> <h3><tt class="docutils literal"><span class="pre">bzr+http://</span></tt> を通してpushする<a class="headerlink" href="#bzr-http-push" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>httpスマートサーバーを通してデータをプッシュすることは可能です。 これを行うための最も簡単な方法は、 <tt class="docutils literal"><span class="pre">wsgi.make_app()</span></tt> コールに <tt class="docutils literal"><span class="pre">readonly=False</span></tt> を 提供するだけです。ただし、スマートプロトコルは認証機能が含まれないので注意してください。 書き込みのサポートを有効にする場合、 実際にシステム上のデータを書き込みできる人を制限するために、 <tt class="docutils literal"><span class="pre">.bzr/smart</span></tt> URLへの権限を制限するとよいでしょう。</p> <p>現時点では、同じURLに対して読み込み限定の人と読み込みと書き込みの人を分けることはできません。 (認証を行う)HTTPレイヤーにおいて、すべては単なるPOSTリクエストだからです。 しかしながら、HTTPSアクセスの場合に認証が必要な書き込みサーバーを使い、 プレーンなHTTPは読み込み限定のアクセスを許可することは確実にできます。</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">FastCGIでBazaarを提供する</a><ul> <li><a class="reference internal" href="#id1">例</a></li> <li><a class="reference internal" href="#apache-2-0">Apache 2.0を設定する</a><ul> <li><a class="reference internal" href="#fastcgi">FastCGI</a></li> <li><a class="reference internal" href="#mod-python">mod_python</a></li> </ul> </li> <li><a class="reference internal" href="#bazaar">Bazaarを設定する</a><ul> <li><a class="reference internal" href="#id3">FastCGI</a></li> <li><a class="reference internal" href="#id4">mod_python</a></li> </ul> </li> <li><a class="reference internal" href="#id5">クライアント</a></li> <li><a class="reference internal" href="#id6">高度な設定</a><ul> <li><a class="reference internal" href="#bzr-http-push"><tt class="docutils literal"><span class="pre">bzr+http://</span></tt> を通してpushする</a></li> </ul> </li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="setting_up_email.html" title="前の章へ">Eメールを設定する</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="writing_a_plugin.html" title="次の章へ">プラグインを書く</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/user-guide/http_smart_server.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="writing_a_plugin.html" title="プラグインを書く" >次へ</a></li> <li class="right" > <a href="setting_up_email.html" title="Eメールを設定する" >前へ</a> |</li> <li><a href="../index.html">目次 (2.2.4)</a> »</li> <li><a href="index.html" >Bazaarユーザーガイド</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009, Canonical Ltd. このドキュメントは <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7 で生成しました。 </div> </body> </html>