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
|
||||
~min_level:TRACE;
|
||||
let min_level =
|
||||
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
|
||||
(Server.run {
|
||||
port = 6667;
|
||||
listen_backlog = 8;
|
||||
ping_interval = 60;
|
||||
whowas_history_len = 1000;
|
||||
hostname = "irc.tali.software";
|
||||
(* TODO: motd *)
|
||||
})
|
||||
let no_color = Option.is_some (Sys.getenv_opt "LOG_NO_COLOR")
|
||||
let no_timestamp = Option.is_some (Sys.getenv_opt "LOG_NO_TIMESTAMP")
|
||||
let no_namespace = Option.is_some (Sys.getenv_opt "LOG_NO_NAMESPACE")
|
||||
|
||||
let () =
|
||||
match Sys.getenv_opt "JOURNAL_STREAM" with
|
||||
| Some _ ->
|
||||
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