-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.ml
98 lines (87 loc) · 3.09 KB
/
config.ml
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(* mirage >= 4.8.0 & < 4.9.0 *)
(* (c) 2017, 2018 Hannes Mehnert, all rights reserved *)
open Mirage
let dns_handler =
let packages = [
package "logs";
package ~min:"6.2.2" ~sublibs:["mirage"; "zone"] "dns-server";
package "dns-tsig";
package ~min:"0.0.3" "git-kv";
package ~min:"4.3.1" "mirage-runtime";
] in
main
~packages
~pos:__POS__ "Unikernel.Main"
(random @-> pclock @-> mclock @-> time @-> stackv4v6 @-> git_client @-> job)
let stack = generic_stackv4v6 default_network
let git =
let he = generic_happy_eyeballs stack in
let dns = generic_dns_client stack he in
let tcp = tcpv4v6_of_stackv4v6 stack in
let git = mimic_happy_eyeballs stack he dns in
merge_git_clients (git_tcp tcp git)
(merge_git_clients (git_ssh tcp git) (git_http tcp git))
let enable_monitoring =
let doc = Key.Arg.info
~doc:"Enable monitoring (syslog, metrics to influx, log level, statmemprof tracing)"
[ "enable-monitoring" ]
in
Key.(create "enable-monitoring" Arg.(flag doc))
let management_stack =
if_impl
(Key.value enable_monitoring)
(generic_stackv4v6 ~group:"management" (netif ~group:"management" "management"))
stack
let name =
runtime_arg ~pos:__POS__
{|let doc = Cmdliner.Arg.info ~doc:"Name of the unikernel"
~docs:Mirage_runtime.s_log [ "name" ]
in
Cmdliner.Arg.(value & opt string "ns.robur.coop" doc)|}
let monitoring =
let monitor = Runtime_arg.(v (monitor None)) in
let connect _ modname = function
| [ _ ; _ ; stack ; name ; monitor ] ->
code ~pos:__POS__
"Lwt.return (match %s with\
| None -> Logs.warn (fun m -> m \"no monitor specified, not outputting statistics\")\
| Some ip -> %s.create ip ~hostname:%s %s)"
monitor modname name stack
| _ -> assert false
in
impl
~packages:[ package "mirage-monitoring" ]
~runtime_args:[ name ; monitor ]
~connect "Mirage_monitoring.Make"
(time @-> pclock @-> stackv4v6 @-> job)
let syslog =
let syslog = Runtime_arg.(v (syslog None)) in
let connect _ modname = function
| [ _ ; stack ; name ; syslog ] ->
code ~pos:__POS__
"Lwt.return (match %s with\
| None -> Logs.warn (fun m -> m \"no syslog specified, dumping on stdout\")\
| Some ip -> Logs.set_reporter (%s.create %s ip ~hostname:%s ()))"
syslog modname stack name
| _ -> assert false
in
impl
~packages:[ package ~sublibs:["mirage"] ~min:"0.4.0" "logs-syslog" ]
~runtime_args:[ name ; syslog ]
~connect "Logs_syslog_mirage.Udp"
(pclock @-> stackv4v6 @-> job)
let optional_monitoring time pclock stack =
if_impl (Key.value enable_monitoring)
(monitoring $ time $ pclock $ stack)
noop
let optional_syslog pclock stack =
if_impl (Key.value enable_monitoring)
(syslog $ pclock $ stack)
noop
let () =
register "primary-git"
[
optional_syslog default_posix_clock management_stack ;
optional_monitoring default_time default_posix_clock management_stack ;
dns_handler $ default_random $ default_posix_clock $ default_monotonic_clock $ default_time $ stack $ git
]