;;;; vampire.lisp (in-package #:vampire) ;;; SYSTEM CONFIG COMPONENT (defvar *config* nil) (defclass/std config () ((datastore-directory :ir :std #P"/srv/vampire/store/") (static-directory :ir :std #P"/srv/vampire/static/") (swank-port :std nil :doc "If set, swank is started on this port.") (host :std "0.0.0.0") (port :ir :std 4919) (downloader-threads :ir :std 5))) (defun config-from-file (path) "PATH should be a path to a file containing a PLIST suitable for passing as the keyword arguments to (MAKE-INSTANCE 'CONFIG ...)" (apply #'make-instance 'config (read-from-file path))) ;;; MAIN (defun main (body) (if (session-user body) (setf (url (location body)) "/home") (setf (url (location body)) "/login"))) ;;; STARTUP (defun initialize-database (config) (ensure-directories-exist (datastore-directory config)) (make-instance 'bknr.datastore:mp-store :directory (datastore-directory config) :subsystems (list (make-instance 'bknr.datastore:store-object-subsystem)))) (defun redirect-to-root (body) (setf (url (location body)) "/")) (defun when-logged-in? (fn) ( 'session-user fn 'redirect-to-root)) (defvar *server*) (setf (documentation '*server* 'variable) "The hunchentoot acceptor instance") (defun start-vampire (config) (setf *config* config) (initialize-database config ) (start-downloader-service config) (setf *server* (make-instance 'hunchentoot:easy-acceptor :port (port config))) (hunchentoot:start *server*) (when (swank-port config) (swank:create-server :port (swank-port config) :dont-close t))) (defun hacking-start () (start-vampire (make-instance 'config :static-directory (merge-pathnames "vampire-static/" (user-homedir-pathname)) :datastore-directory (merge-pathnames "vampire-store/" (user-homedir-pathname)))))