From daa6f103c5fc5c473721a7b2bda16363ae39d391 Mon Sep 17 00:00:00 2001 From: Grant Shoshin Shangreaux Date: Tue, 14 Mar 2023 11:43:16 -0500 Subject: Add: configuration from file for datastore & lzb server This defaults to looking for a file called config.lisp within the dnd system's directory. If you copy the config.lisp.example included in this commit out to simply config.lisp, then you should be able to run the (start) defun to get things running with "sane" defaults. It should create a datastore directory within the same system directory, which is also ignored by git. --- src/init.lisp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/init.lisp') diff --git a/src/init.lisp b/src/init.lisp index 68b2a16..d7636a6 100644 --- a/src/init.lisp +++ b/src/init.lisp @@ -2,11 +2,28 @@ (in-package #:dnd) -(defun init-db (&optional config) +;;; CONFIGURATION + +(defvar *config* nil) + +(defclass/std config () + ((datastore-directory :ir :std #P"/srv/dnd/store/") + (swank-port :std nil :doc "If set, swank is started on this port.") + (host :std "0.0.0.0") + (port :ir :std 8888))) + +(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))) + +;;; DATASTORE + +(defun init-db (config) + "Initializes the data store with values from the CONFIG." + (ensure-directories-exist (datastore-directory config)) (unless (boundp 'db:*store*) - (unless config - nil ; TODO: handle the case where we have a config - (make-instance - 'db:mp-store - :directory (merge-pathnames "dnd-store/" (user-homedir-pathname)) - :subsystems (list (make-instance 'db:store-object-subsystem)))))) + (make-instance + 'db:mp-store + :directory (datastore-directory config) + :subsystems (list (make-instance 'db:store-object-subsystem))))) -- cgit v1.2.3