detect journald, parse some env options
This commit is contained in:
parent
e333bc121b
commit
704afb4409
60
bin/main.ml
60
bin/main.ml
|
@ -1,12 +1,50 @@
|
||||||
Logging.init_pretty_writer stderr
|
let min_level =
|
||||||
~min_level:TRACE;
|
match Sys.getenv_opt "LOG_LEVEL" |> Option.map String.uppercase_ascii with
|
||||||
|
| Some "TRACE" -> Logging.TRACE
|
||||||
|
| Some "DEBUG" -> Logging.TRACE
|
||||||
|
| Some "INFO" -> Logging.TRACE
|
||||||
|
| Some ("WARN" | "WARNING") -> Logging.TRACE
|
||||||
|
| Some ("ERR" | "ERROR") -> Logging.TRACE
|
||||||
|
| _ -> Logging.INFO
|
||||||
|
|
||||||
Lwt_main.run
|
let no_color = Option.is_some (Sys.getenv_opt "LOG_NO_COLOR")
|
||||||
(Server.run {
|
let no_timestamp = Option.is_some (Sys.getenv_opt "LOG_NO_TIMESTAMP")
|
||||||
port = 6667;
|
let no_namespace = Option.is_some (Sys.getenv_opt "LOG_NO_NAMESPACE")
|
||||||
listen_backlog = 8;
|
|
||||||
ping_interval = 60;
|
let () =
|
||||||
whowas_history_len = 1000;
|
match Sys.getenv_opt "JOURNAL_STREAM" with
|
||||||
hostname = "irc.tali.software";
|
| Some _ ->
|
||||||
(* TODO: motd *)
|
Logging.init_journald_writer ()
|
||||||
})
|
~min_level
|
||||||
|
| None ->
|
||||||
|
Logging.init_pretty_writer stderr
|
||||||
|
~min_level
|
||||||
|
~color:(not no_color)
|
||||||
|
~timestamp:(not no_timestamp)
|
||||||
|
~namespace:(not no_namespace)
|
||||||
|
|
||||||
|
let port =
|
||||||
|
try
|
||||||
|
let port = int_of_string (Sys.getenv "IRC_PORT") in
|
||||||
|
if port <= 0 || port > 65535 then failwith "invalid port";
|
||||||
|
port
|
||||||
|
with _ ->
|
||||||
|
6667
|
||||||
|
|
||||||
|
let hostname =
|
||||||
|
match Sys.getenv_opt "IRC_HOSTNAME" with
|
||||||
|
| Some x -> x
|
||||||
|
| None -> "irc.tali.software"
|
||||||
|
|
||||||
|
let config : Server.config = {
|
||||||
|
port;
|
||||||
|
hostname;
|
||||||
|
listen_backlog = 8;
|
||||||
|
ping_interval = 60;
|
||||||
|
whowas_history_len = 1000;
|
||||||
|
|
||||||
|
(* TODO: motd *)
|
||||||
|
}
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Lwt_main.run @@ Server.run config
|
||||||
|
|
Loading…
Reference in New Issue