Bug 9250 - [SIGNED-OFF] provide commands to manage the SIP server
authorRobin Sheat <robin@catalyst.net.nz>
Mon, 10 Dec 2012 05:57:04 +0000 (18:57 +1300)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Thu, 2 May 2013 02:03:13 +0000 (22:03 -0400)
This adds commands required to control the SIP server. These commands
are:
* koha-enable-sip - copies the SIP config to the sites directory
* koha-start-sip - starts the SIP server processes
* koha-stop-sip - stops the SIP server processes

It also calls these as appropriate from the koha-common init script.

To use:
1) sudo koha-enable-sip instancename
2) sudo vim /etc/koha/sites/instancename/SIPconfig.xml
   Do whatever is needed for your site's SIP configuration
3) sudo koha-start-sip instancename

To test:
1) Build packages with this patch
2) Ensure that sudo koha-start-sip instancename doesn't do anything
3) Run sudo koha-enable-sip instancename
4) Edit /etc/koha/sites/instancename/SIPconfig.xml if needed (probably
   not required for testing)
5) Run sudo koha-start-sip instancename
6) Note that the sip processes are now running
7) Run sudo koha-stop-sip instancename
8) Note that the sip processes have gone
9) Reboot your Koha server
10) Note that the sip processes are back

Sponsored-By: Waitaki District Council Libraries
Sponsored-By: South Taranaki District Council Libraries
Sponsored-By: Horowhenua District Council Libraries
Sponsored-By: Rangitikei District Council Libraries
Signed-off-by: Magnus Enger <magnus@enger.priv.no>
Works as advertised. koha-start-sip without a prior koha-enable-sip
does nothing. koha-enable-sip copies the SIP config file to the
instance directory. After koha-enable-sip, koha-start-sip and
koha-stop-sip works as expected. After a reboot, the SIP processes are
still running. I have not actually tested the SIP servers after they
have been started, but assume they work the same as always.
The man pages look good.

The new commands should also have been added to the man page for
koha-common. I'll do a followup for that.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
debian/docs/koha-enable-sip.xml [new file with mode: 0644]
debian/docs/koha-start-sip.xml [new file with mode: 0644]
debian/docs/koha-stop-sip.xml [new file with mode: 0644]
debian/koha-common.init
debian/koha-common.install
debian/scripts/koha-enable-sip [new file with mode: 0755]
debian/scripts/koha-start-sip [new file with mode: 0755]
debian/scripts/koha-stop-sip [new file with mode: 0755]

diff --git a/debian/docs/koha-enable-sip.xml b/debian/docs/koha-enable-sip.xml
new file mode 100644 (file)
index 0000000..3ce3b09
--- /dev/null
@@ -0,0 +1,57 @@
+<article xmlns='http://docbook.org/ns/docbook'>
+<title>koha-enable-sip</title>
+<info>
+    <productname>Koha</productname> is the first free software library automation package.
+    <author>
+        <personname>
+            <firstname>Robin</firstname>
+            <surname>Sheat</surname>
+        </personname>
+        <affiliation>
+            <orgname>Catalyst IT</orgname>
+            <uri>http://www.catalyst.net.nz</uri>
+        </affiliation>
+        <contrib>Author</contrib>
+    </author>
+</info>
+
+<refentry xml:id="koha-enable-sip">
+
+    <refmeta>
+        <refentrytitle>koha-enable-sip</refentrytitle>
+        <manvolnum>8</manvolnum>
+    </refmeta>
+
+    <refnamediv>
+        <refname>koha-enable-sip</refname>
+        <refpurpose>Copies the SIP configuration file to allow SIP to be controlled by init scripts.</refpurpose>
+        <refclass>UNIX/Linux</refclass>
+    </refnamediv>
+
+    <refsynopsisdiv>
+        <cmdsynopsis>
+            <command>koha-enable-sip</command>
+            <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
+        </cmdsynopsis>
+    </refsynopsisdiv>
+
+    <refsect1><title>Description</title>
+        <para>This copies the default SIP configuration file /etc/koha/SIPconfig.xml to the
+            /etc/koha/sites/instancename directory. This allows it to be started by
+            <command>koha-start-sip(8)</command>, and <command>koha-stop-sip</command>. In turn,
+            this means that it will be started on boot and stopped on shutdown.</para>
+        <para>After running this, you will need to edit the newly created file to configure it
+            for your site.</para>
+        <para>To disable SIP again, delete or rename the configuration file.</para>
+    </refsect1>
+
+  <refsect1><title>See also</title>
+  <simplelist type="inline">
+    <member><command>koha-start-sip(8)</command></member>
+    <member><command>koha-stop-sip(8)</command></member>
+  </simplelist>
+  </refsect1>
+
+</refentry>
+
+</article>
diff --git a/debian/docs/koha-start-sip.xml b/debian/docs/koha-start-sip.xml
new file mode 100644 (file)
index 0000000..b6a18dd
--- /dev/null
@@ -0,0 +1,53 @@
+<article xmlns='http://docbook.org/ns/docbook'>
+<title>koha-start-sip</title>
+<info>
+    <productname>Koha</productname> is the first free software library automation package.
+    <author>
+        <personname>
+            <firstname>Robin</firstname>
+            <surname>Sheat</surname>
+        </personname>
+        <affiliation>
+            <orgname>Catalyst IT</orgname>
+            <uri>http://www.catalyst.net.nz</uri>
+        </affiliation>
+        <contrib>Author</contrib>
+    </author>
+</info>
+
+<refentry xml:id="koha-start-sip">
+
+    <refmeta>
+        <refentrytitle>koha-start-sip</refentrytitle>
+        <manvolnum>8</manvolnum>
+    </refmeta>
+
+    <refnamediv>
+        <refname>koha-start-sip</refname>
+        <refpurpose>Starts the SIP daemon for the specified Koha instances.</refpurpose>
+        <refclass>UNIX/Linux</refclass>
+    </refnamediv>
+
+    <refsynopsisdiv>
+        <cmdsynopsis>
+            <command>koha-start-sip</command>
+            <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
+        </cmdsynopsis>
+    </refsynopsisdiv>
+
+    <refsect1><title>Description</title>
+        <para>This will start the SIP daemon for the Koha instance specified by <arg>instancename</arg>.</para>
+        <para>If the SIP configuration is not present for the supplied instance, it will be silently skipped.</para>
+        <para>To enable SIP support for an instance, refer to <command>koha-enable-sip(8)</command>.</para>
+    </refsect1>
+
+  <refsect1><title>See also</title>
+  <simplelist type="inline">
+    <member><command>koha-stop-sip(8)</command></member>
+    <member><command>koha-enable-sip(8)</command></member>
+  </simplelist>
+  </refsect1>
+
+</refentry>
+
+</article>
diff --git a/debian/docs/koha-stop-sip.xml b/debian/docs/koha-stop-sip.xml
new file mode 100644 (file)
index 0000000..3e5a179
--- /dev/null
@@ -0,0 +1,52 @@
+<article xmlns='http://docbook.org/ns/docbook'>
+<title>koha-stop-sip</title>
+<info>
+    <productname>Koha</productname> is the first free software library automation package.
+    <author>
+        <personname>
+            <firstname>Robin</firstname>
+            <surname>Sheat</surname>
+        </personname>
+        <affiliation>
+            <orgname>Catalyst IT</orgname>
+            <uri>http://www.catalyst.net.nz</uri>
+        </affiliation>
+        <contrib>Author</contrib>
+    </author>
+</info>
+
+<refentry xml:id="koha-stop-sip">
+
+    <refmeta>
+        <refentrytitle>koha-stop-sip</refentrytitle>
+        <manvolnum>8</manvolnum>
+    </refmeta>
+
+    <refnamediv>
+        <refname>koha-stop-sip</refname>
+        <refpurpose>Stops the SIP daemon for the specified Koha instances.</refpurpose>
+        <refclass>UNIX/Linux</refclass>
+    </refnamediv>
+
+    <refsynopsisdiv>
+        <cmdsynopsis>
+            <command>koha-stop-sip</command>
+            <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
+        </cmdsynopsis>
+    </refsynopsisdiv>
+
+    <refsect1><title>Description</title>
+        <para>This will stop the SIP daemon for the Koha instance specified by <arg>instancename</arg>.</para>
+        <para>If it's not running, an note will be displayed.</para>
+    </refsect1>
+
+  <refsect1><title>See also</title>
+  <simplelist type="inline">
+    <member><command>koha-start-sip(8)</command></member>
+    <member><command>koha-enable-sip(8)</command></member>
+  </simplelist>
+  </refsect1>
+
+</refentry>
+
+</article>
index 5be77d3..9a285a3 100755 (executable)
@@ -45,6 +45,7 @@ do_start()
     # We insure all required directories exist, including disabled ones.
     koha-create-dirs $(koha-list)
     koha-start-zebra $(koha-list --enabled)
+    koha-start-sip $(koha-list --enabled)
 }
 
 #
@@ -54,6 +55,7 @@ do_stop()
 {
     # We stop everything, including disabled ones.
     koha-stop-zebra $(koha-list) || true
+    koha-stop-sip $(koha-list) || true
 }
 
 #
@@ -61,6 +63,8 @@ do_stop()
 #
 do_reload() {
     koha-restart-zebra $(koha-list --enabled)
+    koha-stop-sip $(koha-list) || true
+    koha-start-sip $(koha-list --enabled)
 }
 
 case "$1" in
index 0e542bb..810aadc 100644 (file)
@@ -31,4 +31,7 @@ debian/scripts/koha-stop-zebra              usr/sbin
 debian/scripts/koha-translate               usr/sbin
 debian/scripts/koha-upgrade-schema          usr/sbin
 debian/scripts/koha-upgrade-to-3.4          usr/sbin
+debian/scripts/koha-start-sip               usr/sbin
+debian/scripts/koha-stop-sip                usr/sbin
+debian/scripts/koha-enable-sip              usr/sbin
 debian/tmp_docbook/*.8                      usr/share/man/man8
diff --git a/debian/scripts/koha-enable-sip b/debian/scripts/koha-enable-sip
new file mode 100755 (executable)
index 0000000..1bcdd97
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# koha-enable-sip -- Set up the config files to allow SIP to run
+# Copyright 2012  Catalyst IT, Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    if [ ! -e /etc/koha/sites/${name}/koha-conf.xml ] ;
+    then
+        echo "No such instance: ${name}" > /dev/stderr
+        continue;
+    fi
+    sipfile=/etc/koha/sites/${name}/SIPconfig.xml
+    if [ -e ${sipfile} ]
+    then
+        echo "SIP already enabled for $name"
+    else
+        echo "Enabling SIP for $name - edit ${sipfile} to configure"
+        cp -v /etc/koha/SIPconfig.xml ${sipfile}
+        chown ${name}-koha:${name}-koha ${sipfile}
+        chmod 600 ${sipfile}
+    fi
+done
diff --git a/debian/scripts/koha-start-sip b/debian/scripts/koha-start-sip
new file mode 100755 (executable)
index 0000000..791c6d3
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# koha-start-sip -- Start SIP server for named Koha instance
+# Copyright 2012  Catalyst IT, Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    if [ ! -e /etc/koha/sites/${name}/koha-conf.xml ] ;
+    then
+        echo "No such instance: ${name}" > /dev/stderr
+        continue;
+    fi
+    [ -e /etc/koha/sites/${name}/SIPconfig.xml ] || continue
+    echo "Starting SIP server for $name"
+    mkdir -p /var/run/koha/${name}
+    chown "${name}-koha:${name}-koha" /var/run/koha/${name}
+    export KOHA_CONF PERL5LIB
+    KOHA_CONF=/etc/koha/sites/${name}/koha-conf.xml
+    PERL5LIB="/usr/share/koha/lib:/usr/share/koha/lib/C4/SIP"
+    daemon \
+        --name="$name-koha-sip" \
+        --errlog="/var/log/koha/$name/sip-error.log" \
+        --stdout="/var/log/koha/$name/sip.log" \
+        --output="/var/log/koha/$name/sip-output.log" \
+        --verbose=1 \
+        --respawn \
+        --delay=30 \
+        --pidfiles="/var/run/koha/${name}" \
+        --user="$name-koha.$name-koha" \
+        -- \
+        perl \
+        "/usr/share/koha/lib/C4/SIP/SIPServer.pm" \
+        "/etc/koha/sites/${name}/SIPconfig.xml"
+done
diff --git a/debian/scripts/koha-stop-sip b/debian/scripts/koha-stop-sip
new file mode 100755 (executable)
index 0000000..b0cbbe9
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# koha-stop-sip -- Stop SIP server for named Koha instance
+# Copyright 2012  Catalyst IT, Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+for name in "$@"
+do
+    if [ ! -e /etc/koha/sites/${name}/koha-conf.xml ] ;
+    then
+        echo "No such instance: ${name}" > /dev/stderr
+        continue;
+    fi
+    if [ ! -e /var/run/koha/${name}/${name}-koha-sip.pid ] ;
+    then
+        echo "SIP server for ${name} not running."
+        continue;
+    fi
+    echo "Stopping SIP server for $name"
+    KOHA_CONF=/etc/koha/sites/${name}/koha-conf.xml
+    PERL5LIB=/usr/share/koha/lib
+    export KOHA_CONF PERL5LIB
+    daemon \
+        --name="$name-koha-sip" \
+        --errlog="/var/log/koha/$name/sip-error.log" \
+        --stdout="/var/log/koha/$name/sip.log" \
+        --output="/var/log/koha/$name/sip-output.log" \
+        --verbose=1 \
+        --respawn \
+        --delay=30 \
+        --pidfiles="/var/run/koha/${name}" \
+        --user="$name-koha.$name-koha" \
+        --stop \
+        -- \
+        perl \
+        "/usr/share/koha/lib/C4/SIP/SIPServer.pm" \
+        "/etc/koha/sites/${name}/SIPconfig.xml"
+done