summaryrefslogtreecommitdiff
path: root/src/init.lisp
diff options
context:
space:
mode:
authorGrant Shoshin Shangreaux <shoshin@cicadas.surf>2023-03-14 11:43:16 -0500
committerGrant Shoshin Shangreaux <shoshin@cicadas.surf>2023-03-14 11:43:16 -0500
commitdaa6f103c5fc5c473721a7b2bda16363ae39d391 (patch)
tree454413946bf7055d1906ca2061ed143ba36a0f7c /src/init.lisp
parent12662d6a0fceb0c2adfdc4d0947800994bc85718 (diff)
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.
Diffstat (limited to 'src/init.lisp')
-rw-r--r--src/init.lisp31
1 files changed, 24 insertions, 7 deletions
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)))))