-
Notifications
You must be signed in to change notification settings - Fork 0
/
shout.lisp
43 lines (37 loc) · 1.9 KB
/
shout.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(in-package :shout)
(defvar *default-daemon-mode* t)
(defvar *default-pidfile* #p"/var/run/shout.pid")
(defvar *default-port* "7109")
(defvar *default-database-file* #p"/var/db/shout.db")
(defvar *default-credentials* "shout:shout")
(defun env (name &optional default)
(or (sb-posix:getenv name)
default))
(defun parse-creds (creds)
(let ((idx (position #\: creds)))
(if (null idx)
(error "Invalid authentication string")
(cons (subseq creds 0 idx)
(subseq creds (+ idx 1))))))
(defun shout (&key (daemonize (env "SHOUT_IT_OUT_LOUD" *default-daemon-mode*))
(pidfile (env "SHOUT_PIDFILE" *default-pidfile*))
(port (env "SHOUT_PORT" *default-port*))
(database-file (env "SHOUT_DATABASE" *default-database-file*))
(ops-credentials (env "SHOUT_OPS_CREDS" (env "SHOUT_CREDS" *default-credentials*)))
(admin-credentials (env "SHOUT_ADMIN_CREDS" (env "SHOUT_CREDS" *default-credentials*))))
(if (eq daemonize t)
(daemon:daemonize :exit-parent t
:pidfile pidfile)
(progn
(format t " ###### ## ## ####### ## ## ######## #### ~%")
(format t "## ## ## ## ## ## ## ## ## #### ~%")
(format t "## ## ## ## ## ## ## ## #### ~%")
(format t " ###### ######### ## ## ## ## ## ## ~%")
(format t " ## ## ## ## ## ## ## ## ~%")
(format t "## ## ## ## ## ## ## ## ## #### ~%")
(format t " ###### ## ## ####### ####### ## #### ~%")
(format t "starting up...~%")))
(api:run :port port
:dbfile database-file
:ops-auth (parse-creds ops-credentials)
:admin-auth (parse-creds admin-credentials)))