about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-12-26T12·48+0100
committerVincent Ambo <tazjin@gmail.com>2017-12-26T12·48+0100
commit5579ca7d6c620c5dd874ed0654d9a03a73fbf6d6 (patch)
tree73580db0255e6c695298b9f517f6fcf0ce52f970
parentabe8419b034600b8cea37a17407ed933766cfbf5 (diff)
feat(build): Configure ASDF program-op with entrypoint
-rw-r--r--gemma.asd2
-rw-r--r--src/gemma.lisp18
2 files changed, 18 insertions, 2 deletions
diff --git a/gemma.asd b/gemma.asd
index a2472a4f14d9..1da8aa0b20c2 100644
--- a/gemma.asd
+++ b/gemma.asd
@@ -20,6 +20,8 @@
   :components ((:module "src"
                 :components
                 ((:file "gemma"))))
+  :build-operation program-op
+  :entry-point "gemma::entrypoint"
   :description "Gemma is a household task management system"
   :long-description
   #.(read-file-string
diff --git a/src/gemma.lisp b/src/gemma.lisp
index a925e65a73aa..526eb0453549 100644
--- a/src/gemma.lisp
+++ b/src/gemma.lisp
@@ -12,7 +12,8 @@
         :local-time
         :cl-json)
   (:import-from :sb-posix :getenv)
-  (:shadowing-import-from :sb-posix :getcwd))
+  (:shadowing-import-from :sb-posix :getcwd)
+  (:export :start-gemma :config :entrypoint))
 (in-package :gemma)
 
 ;; TODO: Store an average of how many days it was between task
@@ -121,6 +122,8 @@ maximum interval."
     (:remaining . ,(days-remaining task))))
 
 (defun start-gemma ()
+  (in-package :gemma)
+
   ;; Load configuration
   (load (pathname (or (getenv "GEMMA_CONFIG")
                       "/etc/gemma/config.lisp")))
@@ -149,6 +152,18 @@ maximum interval."
      (complete-task key)
      (encode-json-to-string (response-for (get-task key))))))
 
+(defun entrypoint ()
+  "This function serves as the entrypoint for ASDF-built executables.
+  It joins the Hunchentoot server thread to keep the process running
+  for as long as the server is alive."
+
+  (start-gemma)
+  (sb-thread:join-thread
+   (find-if (lambda (th)
+              (string= (sb-thread:thread-name th)
+                       (format nil "hunchentoot-listener-*:~A" *gemma-port*)))
+            (sb-thread:list-all-threads))))
+
 ;; Experimentation / testing stuff
 
 (defun randomise-completion-times ()
@@ -166,4 +181,3 @@ maximum interval."
           (cl-prevalence:find-all-objects *p-tasks* 'task)))
 
 ;; (randomise-completion-times)
-