feat(web/panettone): Read config from env
Read the port and data directory from environment variables, in preparation for deploying as a systemd unit to Whitby Change-Id: I066dced7b7926b6bdc77132d13a4da6c886b20e8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1338 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
9a85694b86
commit
974c2e05af
3 changed files with 31 additions and 12 deletions
|
@ -88,3 +88,9 @@ separated by SEP."
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(format-dottime (local-time:now)))
|
(format-dottime (local-time:now)))
|
||||||
|
|
||||||
|
(defun try-parse-integer (str)
|
||||||
|
"Attempt to parse STR as an integer, returning nil if it is invalid."
|
||||||
|
(check-type str string)
|
||||||
|
(handler-case (parse-integer str)
|
||||||
|
(sb-int:simple-parse-error (_) nil)))
|
||||||
|
|
|
@ -9,4 +9,5 @@
|
||||||
#:chunk-list #:mapconcat
|
#:chunk-list #:mapconcat
|
||||||
|
|
||||||
;; String handling
|
;; String handling
|
||||||
#:+dottime-format+ #:format-dottime))
|
#:+dottime-format+ #:format-dottime
|
||||||
|
#:try-parse-integer))
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(:use :cl :klatre :easy-routes)
|
(:use :cl :klatre :easy-routes)
|
||||||
(:import-from :defclass-std :defclass/std)
|
(:import-from :defclass-std :defclass/std)
|
||||||
(:import-from :alexandria :if-let)
|
(:import-from :alexandria :if-let)
|
||||||
|
(:shadowing-import-from :alexandria :when-let)
|
||||||
(:export :start-panettone :main))
|
(:export :start-panettone :main))
|
||||||
(in-package :panettone)
|
(in-package :panettone)
|
||||||
|
|
||||||
|
@ -32,10 +33,10 @@
|
||||||
(defvar *ldap* nil
|
(defvar *ldap* nil
|
||||||
"The ldap connection")
|
"The ldap connection")
|
||||||
|
|
||||||
(defun connect-ldap ()
|
(defun connect-ldap (&key
|
||||||
;; TODO(grfn): make this configurable
|
(host "localhost")
|
||||||
(setq *ldap* (ldap:new-ldap :host "localhost"
|
(port 389))
|
||||||
:port 3899)))
|
(setq *ldap* (ldap:new-ldap :host host :port port)))
|
||||||
|
|
||||||
(defun ldap-entry->user (entry)
|
(defun ldap-entry->user (entry)
|
||||||
(apply
|
(apply
|
||||||
|
@ -269,20 +270,30 @@ updated issue"
|
||||||
(defvar *acceptor* nil
|
(defvar *acceptor* nil
|
||||||
"Hunchentoot acceptor for Panettone's web server.")
|
"Hunchentoot acceptor for Panettone's web server.")
|
||||||
|
|
||||||
(defun start-panettone (&key port data-dir)
|
(defun start-panettone (&key port data-dir
|
||||||
(connect-ldap)
|
(ldap-host "localhost")
|
||||||
|
(ldap-port 389))
|
||||||
|
(connect-ldap :host ldap-host
|
||||||
|
:port ldap-port)
|
||||||
(initialize-persistence data-dir)
|
(initialize-persistence data-dir)
|
||||||
|
|
||||||
(setq *acceptor*
|
(setq *acceptor*
|
||||||
(make-instance 'easy-routes:routes-acceptor :port port))
|
(make-instance 'easy-routes:routes-acceptor :port port))
|
||||||
(hunchentoot:start *acceptor*))
|
(hunchentoot:start *acceptor*))
|
||||||
|
|
||||||
|
(defun integer-env (var &key default)
|
||||||
|
(or
|
||||||
|
(when-let ((str (uiop:getenvp var)))
|
||||||
|
(try-parse-integer str))
|
||||||
|
default))
|
||||||
|
|
||||||
(defun main ()
|
(defun main ()
|
||||||
;; TODO(grfn): Read config from env
|
(let ((port (integer-env "PANETTONE_PORT" :default 6161))
|
||||||
(let ((port 6161)
|
(ldap-port (integer-env "LDAP_PORT" :default 389))
|
||||||
(data-dir "/tmp/panettone"))
|
(data-dir (or (uiop:getenvp "PANETTONE_DATA_DIR") "/var/lib/panettone")))
|
||||||
(start-panettone :port port
|
(start-panettone :port port
|
||||||
:data-dir data-dir)
|
:data-dir data-dir
|
||||||
|
:ldap-port ldap-port)
|
||||||
(sb-thread:join-thread
|
(sb-thread:join-thread
|
||||||
(find-if (lambda (th)
|
(find-if (lambda (th)
|
||||||
(string= (sb-thread:thread-name th)
|
(string= (sb-thread:thread-name th)
|
||||||
|
@ -291,5 +302,6 @@ updated issue"
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(start-panettone :port 6161
|
(start-panettone :port 6161
|
||||||
:data-dir "/tmp/panettone")
|
:data-dir "/tmp/panettone"
|
||||||
|
:ldap-port 3899)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue