Author: lgiessmann Date: Mon Jul 18 04:07:59 2011 New Revision: 637
Log: fixed ticket #113 => hunchentoot defines a new admin interface that allows to sut down the server from a predefined ip address; each time a shut down is initiated a backup file in the working directory and the name of the form backup_dd.mm.yyyy:hh:mm:ss is created.
Added: trunk/src/rest_interface/admin-interface.lisp trunk/src/shell_scripts/ trunk/src/shell_scripts/shutdown-isidorus.sh (contents, props changed) Modified: trunk/src/isidorus.asd trunk/src/rest_interface/rest-interface.lisp
Modified: trunk/src/isidorus.asd ============================================================================== --- trunk/src/isidorus.asd Sun Jul 17 13:50:32 2011 (r636) +++ trunk/src/isidorus.asd Mon Jul 18 04:07:59 2011 (r637) @@ -111,6 +111,8 @@ :depends-on ("rest-interface")) (:file "set-up-json-interface" :depends-on ("rest-interface")) + (:file "admin-interface" + :depends-on ("rest-interface")) (:file "read" :depends-on ("rest-interface"))) :depends-on ("model" "atom" "xml" "TM-SPARQL"
Added: trunk/src/rest_interface/admin-interface.lisp ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/src/rest_interface/admin-interface.lisp Mon Jul 18 04:07:59 2011 (r637) @@ -0,0 +1,77 @@ +;;+----------------------------------------------------------------------------- +;;+ Isidorus +;;+ (c) 2008-2010 Marc Kuester, Christoph Ludwig, Lukas Georgieff +;;+ +;;+ Isidorus is freely distributable under the LLGPL license. +;;+ You can find a detailed description in trunk/docs/LLGPL-LICENSE.txt and +;;+ trunk/docs/LGPL-LICENSE.txt. +;;+----------------------------------------------------------------------------- + +(in-package :rest-interface) + +;;TODO: add functions to export statement + +;the prefix to get a fragment by the psi -> localhost:8000/json/get/<fragment-psi> +(defparameter *admin-backup* "/admin/backup") +;the prefix to get a fragment by the psi -> localhost:8000/json/rdf/get/<fragment-psi> +(defparameter *admin-shutdown* "/admin/shutdown") + + +(defun set-up-admin-interface () + (push + (create-regex-dispatcher *admin-backup* #'admin-backup) + hunchentoot:*dispatch-table*) + (push + (create-regex-dispatcher *admin-shutdown* #'admin-shutdown) + hunchentoot:*dispatch-table*)) + + + +(defun admin-shutdown() + (handler-case + (if (string= *admin-remote-name* (hunchentoot:remote-addr*)) + (progn + (when elephant:*store-controller* + (xtm-exporter:export-as-xtm + (concat "backup_" (make-date-string (get-universal-time)) ".xtm") + :tm-id "http://isidor.us/backup-tm" + :revision 0)) + (shutdown-json-engine) + (shutdown-atom-engine) + (shutdown-admin-server) + (close-tm-store)) ;in case the json and atom services are not running + (setf (hunchentoot:return-code*) hunchentoot:+http-forbidden+)) + (condition (err) + (progn + (tools:close-tm-store) + (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) + (setf (hunchentoot:content-type*) "text") + (format nil "closed the tm store, but:~%condition: "~a"" err))))) + + + + +(defun admin-backup() + (handler-case + (if (string= "127.0.0.1" (hunchentoot:remote-addr*)) + (let ((destination-path + (hunchentoot:url-decode (hunchentoot:get-parameter "path")))) + (xtm-exporter:export-as-xtm destination-path + :tm-id "http://isidor.us/backup-tm" + :revision 0)) + (setf (hunchentoot:return-code*) hunchentoot:+http-forbidden+)) + (condition (err) + (progn + (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) + (setf (hunchentoot:content-type*) "text") + (format nil "Condition: "~a"" err))))) + + +(defun make-date-string (universal-time) + (tools:concat + (write-to-string (nth-value 3 (decode-universal-time universal-time))) "." + (write-to-string (nth-value 4 (decode-universal-time universal-time))) "." + (write-to-string (nth-value 5 (decode-universal-time universal-time))) ":" + (write-to-string (nth-value 2 (decode-universal-time universal-time))) ":" + (write-to-string (nth-value 1 (decode-universal-time universal-time))) ":" + (write-to-string (nth-value 0 (decode-universal-time universal-time))))) \ No newline at end of file
Modified: trunk/src/rest_interface/rest-interface.lisp ============================================================================== --- trunk/src/rest_interface/rest-interface.lisp Sun Jul 17 13:50:32 2011 (r636) +++ trunk/src/rest_interface/rest-interface.lisp Mon Jul 18 04:07:59 2011 (r637) @@ -30,8 +30,13 @@ :read-fragment-feed :start-json-engine :start-atom-engine + :start-admin-server :shutdown-json-engine :shutdown-atom-engine + :shutdown-admin-server + :*admin-host-name* + :*admin-port* + :*admin-remote-name* :*json-get-prefix* :*get-rdf-prefix* :*json-commit-url* @@ -69,6 +74,31 @@
(defvar *json-server-acceptor* nil) (defvar *atom-server-acceptor* nil) +(defvar *admin-server-acceptor* nil) +(defvar *admin-host-name* "127.0.0.1") +(defvar *admin-port* 11008) +(defvar *admin-remote-name* "127.0.0.1") + + +(defun start-admin-server () + (when *admin-server-acceptor* + (error "The admin-server is already running")) + (set-up-admin-interface ) + (setf hunchentoot:*show-lisp-errors-p* t) + (setf hunchentoot:*hunchentoot-default-external-format* + (flex:make-external-format :utf-8 :eol-style :lf)) + (setf *admin-server-acceptor* + (make-instance 'hunchentoot:acceptor + :address *admin-host-name* + :port *admin-port*)) + (hunchentoot:start *admin-server-acceptor*)) + + +(defun shutdown-admin-server () + "Shut down the admin server." + (when *admin-server-acceptor* + (hunchentoot:stop *admin-server-acceptor*)) + (setf *admin-server-acceptor* nil))
(defun start-json-engine (repository-path &key @@ -93,7 +123,8 @@
(defun shutdown-json-engine () "Shut down the Topic Map Engine, only the json part." - (hunchentoot:stop *json-server-acceptor*) + (when *json-server-acceptor* + (hunchentoot:stop *json-server-acceptor*)) (setf *json-server-acceptor* nil) (close-tm-store))
@@ -122,6 +153,7 @@
(defun shutdown-atom-engine () "Shut down the Topic Map Engine, only the atom part." - (hunchentoot:stop *atom-server-acceptor*) + (when *atom-server-acceptor* + (hunchentoot:stop *atom-server-acceptor*)) (setf *atom-server-acceptor* nil) (close-tm-store)) \ No newline at end of file
Added: trunk/src/shell_scripts/shutdown-isidorus.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/src/shell_scripts/shutdown-isidorus.sh Mon Jul 18 04:07:59 2011 (r637) @@ -0,0 +1,62 @@ +#!/bin/bash +##+----------------------------------------------------------------------------- +##+ Isidorus +##+ (c) 2008-2010 Marc Kuester, Christoph Ludwig, Lukas Georgieff +##+ +##+ Isidorus is freely distributable under the LLGPL license. +##+ You can find a detailed description in trunk/docs/LLGPL-LICENSE.txt and +##+ trunk/docs/LGPL-LICENSE.txt. +##+----------------------------------------------------------------------------- + + +## This script can be used to invoke hunchentoot's admin interface and shut down +## the server. The default ip address is set to 127.0.0.1 and can be changed via +## the switch -host <ip-address>. The default url that determines the server's +## callback binding is set to /admin/shutdown, but this behavior can also be +## changed by using the switch -url <url-fragment>. +## a sample call would be ./shutdown-isidorus.sh -host 12.34.56.78 -url /admin/shutdown + +url="/admin/shutdown"; +host="127.0.0.1:11008"; + +if [ $# -eq 0 ]; then + : +elif [ $# -eq 1 -a $1 = "?" ]; then + echo "you can pass the arguments -host <host-url> and -url </url-fragment>, if no arguments are passed the default values 127.0.0.1 and 11008 are used"; + exit; +elif [ $# -eq 2 ]; then + if [ $1 = "-host" ]; then + host=$2; + elif [ $1 = "-url" ]; then + url=$2; + else + echo "only the arguments -host and -url are supported, use ? for more information"; + exit; + fi +elif [ $# -eq 4 ]; then + if [ $1 = "-host" ]; then + host=$2; + elif [ $1 = "-url" ]; then + url=$2; + else + echo "only the arguments -host and -url are supported, use ? for more information"; + exit; + fi + + if [ $3 = "-host" ]; then + host=$4; + elif [ $3 = "-url" ]; then + url=$4; + else + echo "only the arguments -host and -url are supported, use ? for more information"; + exit; + fi +else + echo "only the arguments -host and -url are supported, use ? for more information"; + exit; +fi + +curl $host$url + + +