Browse Source

Add Makefile & command-line config, so the app can run standalone

- You can now actually compile the whole thing into a standalone
  binary, which gets configured through command-line options.
- If the thing encounters an unexpected error, it prints a nice
  backtrace and exits with an error code (instead of dropping t
  the debugger).
master
eta 2 years ago
parent
commit
aa970e5006
  1. 3
      .gitignore
  2. 7
      Makefile
  3. 58
      ircd-config.lisp
  4. 2
      ircd-db.lisp
  5. 62
      ircd.lisp
  6. 6
      nea.asd
  7. 3
      packages.lisp

3
.gitignore

@ -1,2 +1,3 @@
*.fasl
*.sqlite3
*.sqlite3
nea-ircd

7
Makefile

@ -0,0 +1,7 @@
LISP ?= sbcl
all:
$(LISP) \
--eval '(ql:quickload :nea)' \
--eval '(asdf:make :nea)' \
--eval '(quit)'

58
ircd-config.lisp

@ -0,0 +1,58 @@
;;; Command line configuration
(in-package :nea/ircd)
(opts:define-opts
(:name :help
:description "Print this help text."
:short #\h
:long "help")
(:name :server-name
:description "Set the name of the local server."
:short #\n
:required t
:meta-var "NAME"
:arg-parser #'identity
:long "server-name")
(:name :listen-host
:description "The hostname to listen on. Default: localhost"
:short #\l
:meta-var "HOST"
:arg-parser #'identity
:long "listen-host")
(:name :listen-port
:description "The port to listen on. Default: 6667"
:short #\p
:meta-var "PORT"
:arg-parser #'parse-integer
:long "listen-port")
(:name :db-host
:description "The hostname of the PostgreSQL database server. Default: localhost"
:short #\H
:meta-var "HOST"
:arg-parser #'identity
:long "db-host")
(:name :db-port
:description "The port of the PostgreSQL database server. Default: 5432"
:short #\P
:meta-var "PORT"
:arg-parser #'parse-integer
:long "db-port")
(:name :db-username
:description "The username to use for the PostgreSQL database server. Default: nea"
:short #\U
:meta-var "USERNAME"
:arg-parser #'identity
:long "db-username")
(:name :db-password
:description "The password to use for the PostgreSQL database server. Default: none"
:short #\W
:meta-var "USERNAME"
:arg-parser #'identity
:long "db-password")
(:name :db-database
:description "The database to access on the PostgreSQL database server. Default: nea"
:short #\D
:meta-var "USERNAME"
:arg-parser #'identity
:long "db-database"))

2
ircd-db.lisp

@ -4,7 +4,7 @@
(defparameter *local-server-id* 1
"Server ID of the local server.")
(defparameter *default-database-args* '("nea" "eeeeeta" "" "localhost")
(defparameter *default-database-args* '("nea" "nea" "" "localhost" :port 5432)
"Default arguments to pass to POSTMODERN:CONNECT.")
(defmacro execute-one (&rest args)

62
ircd.lisp

@ -466,3 +466,65 @@ When they arrive, it delivers them to connected clients."
(format t "Starting server on ~A, port ~A...~%" host port)
(start-message-delivery-thread)
(irc-listen host port))
(defmacro setf-not-nil (place value)
"Sets PLACE to VALUE (using SETF), but only if VALUE isn't NIL."
(let ((val-sym (gensym)))
`(let ((,val-sym ,value))
(when ,val-sym
(setf ,place ,val-sym)))))
(defun handle-toplevel-error (e)
(format *error-output* "fatal: ~A~%" e)
(format *error-output* "backtrace:~%")
(trivial-backtrace:print-backtrace e
:output *error-output*)
(opts:exit 1))
(defun print-help-text ()
(opts:describe
:prefix "NEA IRCd project"
:usage-of "nea-ircd")
(opts:exit 2))
(defun handle-interrupt ()
(format t "Quitting after user interrupt.~%")
(opts:exit 0))
(defun main-inner (argv)
(let ((opts (opts:get-opts argv)))
(when (getf opts :help)
(print-help-text))
(setf *listen-host* (getf opts :listen-host))
(setf-not-nil *listen-port* (getf opts :listen-port))
(setf-not-nil *server-name* (getf opts :server-name))
(setf-not-nil (first *default-database-args*) (getf opts :db-database))
(setf-not-nil (second *default-database-args*) (getf opts :db-username))
(setf-not-nil (third *default-database-args*) (getf opts :db-password))
(setf-not-nil (fourth *default-database-args*) (getf opts :db-host))
(setf-not-nil (sixth *default-database-args*) (getf opts :db-port))
(format t "Running NEA IRCd with server name '~A'.~%" *server-name*)
(format t "Connecting to database using: ~A~%" *default-database-args*)
(initialize-database)
(start-ircd)))
(defun main ()
(let ((argv (opts:argv)))
(handler-case
(main-inner argv)
(sb-sys:interactive-interrupt ()
(handle-interrupt))
(usocket:unknown-error (e)
(if (typep (usocket::usocket-real-error e) 'sb-sys:interactive-interrupt)
(handle-interrupt)
(handle-toplevel-error e)))
(opts::troublesome-option (e)
(progn
(when (or (member "-h" argv :test #'equal)
(member "--help" argv :test #'equal))
(print-help-text))
(format *error-output* "fatal: ~A~%" e)
(format *error-output* "hint: try the --help argument for usage instructions~%")
(opts:exit 2)))
(error (e)
(handle-toplevel-error e)))))

6
nea.asd

@ -2,8 +2,11 @@
:depends-on ("usocket" "bordeaux-threads" "uiop" "cl-ppcre" "qbase64"
"babel" "postmodern" "ironclad" "cl-postgres-plus-uuid"
"simple-date" "simple-date/postgres-glue"
"local-time" "closer-mop")
"local-time" "closer-mop" "unix-opts" "trivial-backtrace")
:serial t
:build-operation "program-op"
:build-pathname "nea-ircd"
:entry-point "nea/ircd:main"
:components
((:file "packages")
(:file "paxos")
@ -20,4 +23,5 @@
(:file "sasl")
(:file "ircd-errors")
(:file "ircd-registration")
(:file "ircd-config")
(:file "ircd")))

3
packages.lisp

@ -51,6 +51,7 @@
:nea/utils
:usocket
:cl-ppcre
:bordeaux-threads))
:bordeaux-threads)
(:export :main))
Loading…
Cancel
Save