From fadb32fb46abe917ec5f3db7f13d803b128a6e34 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 11 Jun 2015 17:36:14 +0300 Subject: [PATCH] Bug 13799 - Adding the REST API as a Hypnotoad service, koha-api-daemon. After running make, the koha-api-daemon.sh -script should be in ../koha-dev/bin/koha-api-daemon.sh Link it to the init-directory and set up upstart triggers: ..$ ln -s /home/koha/koha-dev/bin/koha-api-daemon.sh /etc/init.d/koha-api-daemon ..$ update-rc.d koha-api-daemon defaults Start hypnotoad: ..$ service koha-api-daemon start Hypnotoad is now listening in 127.0.0.1:8080 and is preconfigured to be production ready. Hypnotoad config is in $KOHA_PATH/api/v1/hypnotoad.conf For more info, read the koha-api-daemon.sh -service --- api/v1/hypnotoad.conf | 33 ++++++++++++++++++ misc/bin/koha-api-daemon.sh | 78 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 api/v1/hypnotoad.conf create mode 100755 misc/bin/koha-api-daemon.sh diff --git a/api/v1/hypnotoad.conf b/api/v1/hypnotoad.conf new file mode 100644 index 0000000..7cdfcd1 --- /dev/null +++ b/api/v1/hypnotoad.conf @@ -0,0 +1,33 @@ +### Configuration options for the hypnotoad server +## See. https://metacpan.org/pod/Mojo::Server::Hypnotoad +# +# Setting timeouts to rather large values since some requests, like show all borrowers (120 000 here) +# take a LOT of time. +{ + hypnotoad => { + proxy => 1, + + #Number of worker processes + workers => 1, + + #Maximum number of connections a worker is allowed to accept before stopping + #gracefully and then getting replaced with a newly started worker + accepts => 100, + + #Maximum number of concurrent connections each worker process is allowed to + #handle before stopping to accept new incoming connections + clients => 5, + + #Number of keep-alive requests per connection + requests => 50, + + #Maximum amount of time in seconds a connection can be inactive before getting closed. + inactivity_timeout => 120, + + #Heartbeat interval in seconds + heartbeat_interval => 10, + + #Maximum amount of time in seconds before a worker without a heartbeat will be stopped gracefully + heartbeat_timeout => 120, + } +}; diff --git a/misc/bin/koha-api-daemon.sh b/misc/bin/koha-api-daemon.sh new file mode 100755 index 0000000..acbc08e --- /dev/null +++ b/misc/bin/koha-api-daemon.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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 Koha; if not, see . + +### BEGIN INIT INFO +# Provides: koha-api-daemon +# Required-Start: $syslog $remote_fs +# Required-Stop: $syslog $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Hypnotoad Mojolicious Server for handling Koha API requests +### END INIT INFO + +USER=kivilahtio +loggedInUser=`whoami` +NAME=koha-api-daemon +KOHA_PATH=/home/koha/kohaclone/ + +## See Koha/REST/V1.pm for more info about the environmental variables. +export MOJO_CONFIG=$KOHA_PATH/api/v1/hypnotoad.conf +export MOJO_LOGFILE=/home/koha/koha-dev/var/log/kohaapi.mojo.log +export MOJO_LOGLEVEL=debug + +##ABOUT CHANGING THE process name/command visible by programs like 'top' and 'ps'. +# +# You can make a small incision to /usr/local/share/perl/5.14.2/Mojo/Server.pm or wherever your +# Mojo::Server is located at. +# Go to load_app(), and after perl code line +# 60: FindBin->again; +# add +# $0 = 'koha-api-daemon'; +# This renames all hypnotoad processes as koha-api-daemon. +# No side-effects encoutered so far but minimal testing here! + +if [[ $EUID -ne 0 && $loggedInUser -ne $USER ]]; then + echo "You must run this script as 'root' or as '$USER'"; + exit 1; +fi + +function start { + echo "Starting Hypnotoad" + su -c "hypnotoad $KOHA_PATH/api/v1/script.cgi" $USER + echo "ALL GLORY TO THE HYPNOTOAD." +} +function stop { + su -c "hypnotoad $KOHA_PATH/api/v1/script.cgi -s" $USER +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + echo "Restarting Hypnotoad" + stop + start + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|restart}" + exit 1 + ;; +esac -- 1.7.9.5