From: Frank Duncan Date: Fri, 10 Dec 2021 13:04:39 +0000 (-0600) Subject: Add *candle-dir* X-Git-Url: https://code.consxy.com/gitweb/?a=commitdiff_plain;h=307e1cc54944d45d9cc258539b98ab1b8fed5523;p=candle Add *candle-dir* --- diff --git a/bin/candle-server b/bin/candle-server index 3013ade..5422abe 100755 --- a/bin/candle-server +++ b/bin/candle-server @@ -15,7 +15,9 @@ (defvar *options* '((:name :help :short "h" :long "help" :description "Print this usage.") (:name :port :short "p" :long "port" :takes-argument t :variable-name "PORT" - :description "Port on which to listen for commands. Defaults to 25004"))) + :description "Port on which to listen for commands. Defaults to 25004") + (:name :port :long "candle-dir" :takes-argument t :variable-name "DIR" + :description "Directory for candle related data. Will be created if does not exist. Defaults to /opt/candle/"))) (defun usage () (format t "~A" @@ -38,6 +40,10 @@ (opera:option-present :port options) (parse-integer (opera:option-argument :port options) :junk-allowed t)) 25004))) + (setf candle:*candle-dir* + (if (opera:option-present :port options) + (opera:option-argument :port options) + "/opt/candle/")) (format t "Starting server on port ~A~%" port) (candle:server port nil))))) diff --git a/src/main/base.lisp b/src/main/base.lisp index f06371b..133e515 100644 --- a/src/main/base.lisp +++ b/src/main/base.lisp @@ -1,4 +1,6 @@ (in-package #:candle) +(defvar *candle-dir*) + (lame-db:defdbstruct project name src) (lame-db:defdbstruct job status sha when-run (project :join project)) diff --git a/src/main/package.lisp b/src/main/package.lisp index 2eca806..cf9cf1e 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -1,4 +1,4 @@ (defpackage #:candle (:use :cl) - (:export #:server #:add-project #:add-job #:run)) + (:export #:server #:add-project #:add-job #:run #:*candle-dir*)) (defpackage #:candle-cli (:use :cl) (:export :run)) diff --git a/src/main/server.lisp b/src/main/server.lisp index 6202cd0..d393fee 100644 --- a/src/main/server.lisp +++ b/src/main/server.lisp @@ -1,15 +1,20 @@ (in-package #:candle) (defun server (port &optional (background t)) - (lame-db:load-known-dbs "/home/herbie/.lame-db/data") - (sb-thread:make-thread - (lambda () - (do () (nil) - (progn - (sleep (* 5 60)) - (lame-db:save-known-dbs "/home/herbie/.lame-db/data")))) - :name "Save Thread") - (communication:start-listener port background)) + (when (not *candle-dir*) (error "Need a candle dir")) + (let + ((data-dir (format nil "~Adata" *candle-dir*))) + (ensure-directories-exist *candle-dir*) + (ensure-directories-exist data-dir) + (lame-db:load-known-dbs data-dir) + (sb-thread:make-thread + (lambda () + (do () (nil) + (progn + (sleep (* 5 60)) + (lame-db:save-known-dbs data-dir)))) + :name "Save Thread") + (communication:start-listener port background))) (defun add-project (name src) (when