<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GeneralThreat.com &#187; Koha</title>
	<atom:link href="http://www.generalthreat.com/tag/koha/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.generalthreat.com</link>
	<description>Dangerously different projects and code</description>
	<lastBuildDate>Sun, 19 Jan 2014 20:00:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Serving koha-common with Plack</title>
		<link>http://www.generalthreat.com/2013/04/serving-koha-common-with-plack/</link>
		<comments>http://www.generalthreat.com/2013/04/serving-koha-common-with-plack/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 01:21:59 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[Koha]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=98</guid>
		<description><![CDATA[An update to my post on running the koha-common OPAC on Plack. With Koha 3.10 both the OPAC and Intranet can take advantage of the speed and efficiency of the Plack server. Follow these simple steps to get your catalog running better than ever, or follow the link to github for a script to handle the setup for you!]]></description>
				<content:encoded><![CDATA[<p>This post builds on my <a href="http://www.generalthreat.com/2012/09/serving-the-koha-common-opac-with-plack/">last Koha post about running the OPAC on Plack</a> and will modify some of the files from that post. If you haven&#8217;t read it, it is a good background post but the snippets are no longer up-to-date.</p>
<p>Except where noted, I put these files in a new <code>/usr/share/koha/misc/plack</code> folder. This guide and these code samples assume you will too.</p>
<p><strong>Hey!</strong> Do you want the speed of Plack but don&#8217;t want to deal with all of these files? Check out <a href="https://github.com/JerseyConnect/Plackify-koha-common">Plackify koha-common</a> on github! This post will eventually go out of date, but the github project will always have the latest scripts and a painless installer.</p>
<p>Let&#8217;s begin!</p>
<h2>1. Create the PSGI application file</h2>
<h3><code>koha.psgi:</code></h3>
<p>This is the file that will do the heavy lifting for your Koha install. It is used to run both Intranet and OPAC front-end sites.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">Builder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">CGIBin</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">Directory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> lib<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/usr/share/koha/lib&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Languages</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Members</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Dates</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Boolean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Letters</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Koha</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">XSLT</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Branch</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Category</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$root</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>INTRANETDIR<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span>
                <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>INTRANETDIR<span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/cgi-bin'</span> <span style="color: #339933;">:</span>
                <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>OPACDIR<span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/cgi-bin/opac'</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$app</span><span style="color: #339933;">=</span>Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">CGIBin</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$root</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
builder <span style="color: #009900;">&#123;</span>
&nbsp;
        mount <span style="color: #ff0000;">&quot;/opac-tmpl&quot;</span> <span style="color: #339933;">=&gt;</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/usr/share/koha/opac/htdocs/opac-tmpl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mount <span style="color: #ff0000;">&quot;/intranet-tmpl&quot;</span> <span style="color: #339933;">=&gt;</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/usr/share/koha/intranet/htdocs/intranet-tmpl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        mount <span style="color: #ff0000;">&quot;/cgi-bin/koha&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$app</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>2. Create startup scripts for both the intranet and OPAC</h2>
<p>These scripts will handle starting your Plack OPAC and Intranet (respectively) in a way that can be controlled by `koha-common` style start and stop commands.</p>
<p><strong>Note:</strong> These scripts assume that you installed Starman from CPAN. If you used your distro&#8217;s package manager, you should check your starman path and update these scripts if needed.</p>
<h3><code>opac-plack.sh:</code></h3>
<p>Make sure this script is executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># --max-requests = decreased from 1000 to 50 to keep memory usage sane</span>
<span style="color: #666666; font-style: italic;"># --workers = number of cores on machine</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #007800;">site</span>=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #007800;">dir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KOHA_CONF</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>sites<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>koha-conf.xml
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">OPACDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/opacdir' $KOHA_CONF | sed 's,/cgi-bin/opac,,' )</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LOGDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/logdir' $KOHA_CONF )</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_SERVERS</span>=localhost:<span style="color: #000000;">11211</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_NAMESPACE</span>=<span style="color: #007800;">$site</span>
&nbsp;
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>opac-plack.pid
&nbsp;
<span style="color: #007800;">SOCKET</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>opac-plack.sock
<span style="color: #666666; font-style: italic;">#PORT=5000</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># uncomment to enable logging</span>
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --access-log <span style="color: #007800;">$LOGDIR</span>/opac-access.log --error-log <span style="color: #007800;">$LOGDIR</span>/opac-error.log&quot;</span>
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> -M FindBin --max-requests 50 --workers 2 -E deployment&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SOCKET</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --listen <span style="color: #007800;">$SOCKET</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$PORT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --port <span style="color: #007800;">$PORT</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>starman <span style="color: #007800;">$opt</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span>koha.psgi</pre></td></tr></table></div>

<h3><code>intranet-plack.sh:</code></h3>
<p>Make sure this script is executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># --max-requests = decreased from 1000 to 50 to keep memory usage sane</span>
<span style="color: #666666; font-style: italic;"># --workers = number of cores on machine</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #007800;">site</span>=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #007800;">dir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KOHA_CONF</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>sites<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>koha-conf.xml
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">INTRANETDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/intranetdir' $KOHA_CONF | sed 's,/cgi-bin,,' )</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LOGDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/logdir' $KOHA_CONF )</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_SERVERS</span>=localhost:<span style="color: #000000;">11211</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_NAMESPACE</span>=<span style="color: #007800;">$site</span>
&nbsp;
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>intranet-plack.pid
&nbsp;
<span style="color: #007800;">SOCKET</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>intranet-plack.sock
<span style="color: #666666; font-style: italic;">#PORT=5000</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># uncomment to enable logging</span>
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --access-log <span style="color: #007800;">$LOGDIR</span>/intranet-access.log --error-log <span style="color: #007800;">$LOGDIR</span>/intranet-error.log&quot;</span>
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> -M FindBin --max-requests 50 --workers 2 -E deployment&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SOCKET</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --listen <span style="color: #007800;">$SOCKET</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$PORT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --port <span style="color: #007800;">$PORT</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>starman <span style="color: #007800;">$opt</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span>koha.psgi</pre></td></tr></table></div>

<h2>2a. Scripts for opening access to socket files</h2>
<p><strong>Note:</strong> If you&#8217;re using sockets instead of TCP ports on Linux, you&#8217;ll need to make sure they are world-writable. The following two scripts can be run by <code>koha-start-plack</code> to make sure the sockets are available to any application.</p>
<h3><code>unlock-opac-plack.sh:</code></h3>
<p>Make sure this script is executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #007800;">site</span>=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">shift</span>
&nbsp;
<span style="color: #007800;">timeout</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Waiting for OPAC Plack socket for <span style="color: #007800;">$site</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-S</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>opac-plack.sock <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$timeout</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">10</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #007800;">timeout</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$timeout</span> + <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">777</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>opac-plack.sock
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OPAC Plack socket open for <span style="color: #007800;">$site</span>&quot;</span></pre></td></tr></table></div>

<h3><code>unlock-intranet-plack.sh:</code></h3>
<p>Make sure this script is executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #007800;">site</span>=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">shift</span>
&nbsp;
<span style="color: #007800;">timeout</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Waiting for Intranet Plack socket for <span style="color: #007800;">$site</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-S</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>intranet-plack.sock <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$timeout</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">10</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #007800;">timeout</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$timeout</span> + <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">777</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>intranet-plack.sock
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Intranet Plack socket open for <span style="color: #007800;">$site</span>&quot;</span></pre></td></tr></table></div>

<h2>3. Create control scripts for startup and shutdown</h2>
<p>Finally, create the koha-common style start and stop scripts to control your Plack processes.</p>
<h3><code>/usr/sbin/koha-start-plack:</code></h3>
<p>This script will start Plack processes for both the Intranet and the OPAC. Like other koha-common scripts, it takes the name of the instance as a parameter. Make sure it&#8217;s executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># koha-start-plack -- Start plack processes for named Koha instances</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> name <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting OPAC Plack server for <span style="color: #007800;">$name</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--start</span> \
        <span style="color: #660033;">--chuid</span> <span style="color: #007800;">$name</span>-koha \
        <span style="color: #660033;">--exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>plack<span style="color: #000000; font-weight: bold;">/</span>opac-plack.sh <span style="color: #660033;">--</span> <span style="color: #007800;">$name</span> \
        <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>plack<span style="color: #000000; font-weight: bold;">/</span>unlock-opac-plack.sh <span style="color: #007800;">$name</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Intranet Plack server for <span style="color: #007800;">$name</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--start</span> \
        <span style="color: #660033;">--chuid</span> <span style="color: #007800;">$name</span>-koha \
        <span style="color: #660033;">--exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>plack<span style="color: #000000; font-weight: bold;">/</span>intranet-plack.sh <span style="color: #660033;">--</span> <span style="color: #007800;">$name</span> \
        <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>plack<span style="color: #000000; font-weight: bold;">/</span>unlock-intranet-plack.sh <span style="color: #007800;">$name</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<h3><code>/usr/sbin/koha-stop-plack:</code></h3>
<p>This script will stop Plack processes for both the Intranet and the OPAC. It also takes the name of the instance as a parameter. Make sure it&#8217;s executable!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># koha-stop-plack -- Stop plack processes for named Koha instances</span>
&nbsp;
stopopac<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--stop</span> \
        <span style="color: #660033;">--quiet</span> \
        <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$name</span><span style="color: #000000; font-weight: bold;">/</span>opac-plack.pid
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
stopstaff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--stop</span> \
        <span style="color: #660033;">--quiet</span> \
        <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$name</span><span style="color: #000000; font-weight: bold;">/</span>intranet-plack.pid
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> name <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Plack servers for <span style="color: #007800;">$name</span>&quot;</span>
    stopopac <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> stopstaff <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Servers stopped&quot;</span></pre></td></tr></table></div>

<h2>4. Prepare Koha to launch Plack</h2>
<h3><code>/etc/init.d/koha-common:</code></h3>
<p>There are two final changes needed to make Plack a first class part of your koha-common install. Both are made to your <code>/etc/init.d/koha-common</code> file, but they&#8217;re both really simple.</p>
<p>First, add the new koha-start-plack script to the <code>do_start()</code> function, just after the <code>koha-start-zebra</code> line.</p>
<pre>
     koha-start-plack $(koha-list --enabled)
</pre>
<p>Then add the new koha-stop-plack script to the <code>do_stop()</code> function, just after the <code>koha-stop-zebra</code> line.</p>
<pre>
    koha-stop-plack $(koha-list) || true
</pre>
<p>That&#8217;s it! Stop and start your koha-common service to enjoy your new Plack infrastructure.</p>
<h2>Problems? &mdash; Check:</h2>
<ul>
<li>log directory is writable by your *-koha user</li>
<li>tmp directory for compiled templates is writable by your *-koha user</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2013/04/serving-koha-common-with-plack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Serving the koha-common OPAC with Plack</title>
		<link>http://www.generalthreat.com/2012/09/serving-the-koha-common-opac-with-plack/</link>
		<comments>http://www.generalthreat.com/2012/09/serving-the-koha-common-opac-with-plack/#comments</comments>
		<pubDate>Tue, 25 Sep 2012 18:58:06 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[Koha]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=93</guid>
		<description><![CDATA[If you&#8217;ve set up a Koha instance and been less than impressed with the responsiveness of the OPAC, this post is for you. Thanks to the hard work of the Koha Debian package team,&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve set up a Koha instance and been less than impressed with the responsiveness of the OPAC, this post is for you.</p>
<p>Thanks to the hard work of the Koha Debian package team, it&#8217;s easier than ever to get a functional Koha install up and running. But once you&#8217;ve set up your new instance, you may find the catalog a little sluggish. If you&#8217;ve followed the steps on the <a href="http://wiki.koha-community.org/wiki/Plack">Koha Plack wiki page</a> but found they don&#8217;t work for the koha-common package, here are a few changes that will set things right.</p>
<p>Before we begin, make sure you are running at least Koha 3.8. Earlier versions are not compatible with Plack, so results may be unpredictable.<br />
Also make sure you have installed all Plack dependencies as listed in the Koha wiki.<br />
Finally, it helps to have already created your Koha instance (with <code>koha-create</code>). Whew!</p>
<p>Except where noted, I put these files in a new <code>/usr/share/koha/misc/plack</code> folder. This guide and these code samples assume you will too.</p>
<h2>1. Creating the Koha PSGI wrapper</h2>
<h3>Create <code>koha.psgi</code></h3>
<p>This file is adapted from the example found on the <a href="http://wiki.koha-community.org/wiki/Plack">Koha Plack wiki page</a>. The <code>lib</code> and <code>$root</code> variables have been fixed for koha-common, and a lot of debugging hooks have been removed. The static file paths are correct, but those files should really be served by something leaner like nginx.</p>
<p><ins datetime="2013-01-07T14:17:35+00:00"><strong>Update (1/7/2013):</strong> I&#8217;ve tweaked this file to allow it to be used for serving the Koha staff site as well, since that is supported with Plack as of 3.10. A more complete guide for that is coming soon, so stay tuned!</ins></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">Builder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">CGIBin</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">Directory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> lib<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/usr/share/koha/lib&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Languages</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Members</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Dates</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Boolean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Letters</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Koha</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">XSLT</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Branch</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> C4<span style="color: #339933;">::</span><span style="color: #006600;">Category</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$root</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>INTRANETDIR<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span>
                <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>INTRANETDIR<span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/cgi-bin'</span> <span style="color: #339933;">:</span>
                <span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>OPACDIR<span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/cgi-bin/opac'</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$app</span><span style="color: #339933;">=</span>Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">CGIBin</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$root</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
builder <span style="color: #009900;">&#123;</span>
&nbsp;
        mount <span style="color: #ff0000;">&quot;/opac-tmpl&quot;</span>     <span style="color: #339933;">=&gt;</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/usr/share/koha/opac/htdocs/opac-tmpl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mount <span style="color: #ff0000;">&quot;/intranet-tmpl&quot;</span> <span style="color: #339933;">=&gt;</span> Plack<span style="color: #339933;">::</span><span style="color: #006600;">App</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>root <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/usr/share/koha/intranet/htdocs/intranet-tmpl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mount <span style="color: #ff0000;">&quot;/cgi-bin/koha&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$app</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As the docs say, at this point you can test the OPAC with plackup. Just replace <code>[YOUR INSTANCE NAME]</code> with your instance name in the following and give it a shot.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OPACDIR=/usr/share/koha/opac/ <span style="color: #000099; font-weight: bold;">\
</span>	KOHA_CONF=/etc/koha/sites/SITE/koha-conf.xml <span style="color: #000099; font-weight: bold;">\
</span>	sudo -u SITE-koha -E plackup --reload /usr/share/koha/misc/plack/koha.psgi&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> \
	<span style="color: #c20cb9; font-weight: bold;">sed</span> s<span style="color: #000000; font-weight: bold;">/</span>SITE<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>YOUR INSTANCE NAME<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>g <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></pre></td></tr></table></div>

<p>Open your web browser of choice and visit <code>http://[YOUR SERVER IP]:5000/cgi-bin/koha/opac-main.pl</code>.</p>
<p><strong>Congratulations!</strong> You have a working OPAC running over twice as fast as it was just moments ago.</p>
<p>For production use, you&#8217;ll want to set up a more stable application server. The rest of this article will guide you through making your new OPAC a permanent part of your Koha install by setting up a Starman server and running it through koha-common&#8217;s control systems. </p>
<p>To continue, press <code>Ctrl + C</code> to break out of plackup.</p>
<h2>2. Serving the OPAC with Starman</h2>
<h3>Create <code>opac-plack.sh</code></h3>
<p>This was adapted from the <code>opac-plack.sh</code> example posted <a href="http://lists.koha-community.org/pipermail/koha-patches/2012-March/016881.html">on the patches mailing list</a>. Create it in your <code>/usr/share/koha/misc/plack</code> directory.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh -xe</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">site</span>=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #007800;">dir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KOHA_CONF</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>sites<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>koha-conf.xml
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">OPACDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/opacdir' $KOHA_CONF | sed 's,/cgi-bin/opac,,' )</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LOGDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$( xmlstarlet sel -t -v 'yazgfs/config/logdir' $KOHA_CONF )</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_SERVERS</span>=localhost:<span style="color: #000000;">11211</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MEMCACHED_NAMESPACE</span>=<span style="color: #007800;">$site</span>
&nbsp;
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$site</span><span style="color: #000000; font-weight: bold;">/</span>plack.pid
&nbsp;
<span style="color: #666666; font-style: italic;"># Use one of these lines to choose between TCP port and UNIX socket listeners</span>
<span style="color: #666666; font-style: italic;">#SOCKET=/var/run/koha/$site/plack.sock</span>
<span style="color: #007800;">PORT</span>=<span style="color: #000000;">5000</span>
&nbsp;
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --access-log <span style="color: #007800;">$LOGDIR</span>/opac-access.log --error-log <span style="color: #007800;">$LOGDIR</span>/opac-error.log&quot;</span>
<span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> -M FindBin --max-requests 50 --workers 2 -E deployment&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SOCKET</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --listen <span style="color: #007800;">$SOCKET</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$PORT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">opt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opt</span> --port <span style="color: #007800;">$PORT</span> -D --pid <span style="color: #007800;">$PIDFILE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>starman <span style="color: #007800;">$opt</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span>koha.psgi</pre></td></tr></table></div>

<p>Make the script executable with: <code>chmod +x opac-plack.sh</code></p>
<p>Also be sure to make note of the port (or socket file path) in this file, since that&#8217;s how you&#8217;ll access the OPAC.</p>
<p>You may have noticed that the <code>opac-plack.sh</code> file takes an argument not present in the original. That&#8217;s because we&#8217;re going to control it with koha-common&#8217;s startup infrastructure.</p>
<h2>3. Controlling the OPAC server</h2>
<p>First we need to create startup and shutdown scripts for Plack.</p>
<h3>Create <code>/usr/sbin/koha-start-plack</code></h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># koha-start-plack -- Start Plack processes for named Koha instances</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> name <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Plack server for <span style="color: #007800;">$name</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--start</span> \
        <span style="color: #660033;">--chuid</span> <span style="color: #007800;">$name</span>-koha \
        <span style="color: #660033;">--exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span>misc<span style="color: #000000; font-weight: bold;">/</span>plack<span style="color: #000000; font-weight: bold;">/</span>opac-plack.sh <span style="color: #660033;">--</span> <span style="color: #007800;">$name</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<h3>Create <code>/usr/sbin/koha-stop-plack</code></h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># koha-stop-plack -- Stop Plack processes for named Koha instances</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> name <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Plack server for <span style="color: #007800;">$name</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exec</span> start-stop-daemon \
        <span style="color: #660033;">--stop</span> \
        <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>koha<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$name</span><span style="color: #000000; font-weight: bold;">/</span>plack.pid
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Servers stopped&quot;</span></pre></td></tr></table></div>

<p>Be sure to make these scripts executable when you&#8217;re finished!</p>
<h2>4. Preparing for lanch</h2>
<p>Now we update the koha-common init script to start and stop the Plack servers along with the rest of our Koha infrastructure.</p>
<h3>Edit <code>/etc/init.d/koha-common</code></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="diff" style="font-family:monospace;">do_start<span style="">&#40;</span><span style="">&#41;</span>
<span style="">&#123;</span>
    # We insure all required directories exist, including disabled ones.
    koha-create-dirs $<span style="">&#40;</span>koha-list<span style="">&#41;</span>
    koha-start-zebra $<span style="">&#40;</span>koha-list --enabled<span style="">&#41;</span>
<span style="color: #00b000;">+    koha-start-plack $<span style="">&#40;</span>koha-list --enabled<span style="">&#41;</span></span>
<span style="">&#125;</span>
&nbsp;
#
# Function that stops the daemon/service
#
do_stop<span style="">&#40;</span><span style="">&#41;</span>
<span style="">&#123;</span>
    # We stop everything, including disabled ones.
    koha-stop-zebra $<span style="">&#40;</span>koha-list<span style="">&#41;</span> || true
<span style="color: #00b000;">+    koha-stop-plack $<span style="">&#40;</span>koha-list<span style="">&#41;</span> || true</span>
<span style="">&#125;</span></pre></td></tr></table></div>

<h3>Restart koha-common</h3>
<p>Now you are ready to put your OPAC into service. Restart your koha-common services with:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">service koha-common stop
service koha-common start</pre></td></tr></table></div>

<p><strong>That&#8217;s it!</strong> Your Plack OPAC will now start with your server each time it is restarted, or each time you start and stop the koha-common services. You can also use the <code>koha-[start|stop]-plack</code> scripts to control your OPAC manually, if needed.</p>
<p>Drop me a line in the comments if you have questions or suggestions, or if this article has helped you get the most from your Koha install!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2012/09/serving-the-koha-common-opac-with-plack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

 Served from: www.generalthreat.com @ 2026-06-15 16:44:56 by W3 Total Cache -->