Trellis branch of vsys
[vsys.git] / main.ml
1 (** main () *)
2 open Globals
3 open Printf
4 open Inotify
5 open Backend
6 open Frontend
7 open Conffile
8
9 let input_file_list = ref []
10 let cur_dir = ref ""
11 let cur_slice = ref ""
12 let daemonize = ref false
13
14 let cmdspeclist =
15   [
16     ("-daemon",Arg.Set(daemonize), "Daemonize");
17     ("-conffile",Arg.Set_string(Globals.conffile), "Config file");
18     ("-backend",Arg.Set_string(Globals.backend), "Backend directory");
19     ("-frontend",Arg.Tuple[Arg.String(fun s->cur_dir:=s);Arg.String(fun s->cur_slice:=s;input_file_list:=(!cur_dir,!cur_slice)::!input_file_list)], "frontendN,slicenameN");
20     ("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment")
21   ]
22
23 let cont = ref true
24
25 let _ =
26   printf "Vsys v%s\n" Globals.vsys_version;flush stdout;
27   Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";  
28   if (!Globals.backend == "") then
29       printf "Try vsys --help\n"
30   else
31     begin
32       if (!daemonize) then
33         begin
34           printf "Daemonizing\n";flush Pervasives.stdout;
35         let child = Unix.fork () in
36           if (child <> 0) then
37             begin
38                 let pidfile = open_out !Globals.pid_filepath in
39                   fprintf pidfile "%d" child;
40                     close_out pidfile;
41                     exit(0)
42             end
43           end;
44
45             Dirwatcher.initialize ();
46             Directfifowatcher.initialize ();
47
48             if (!Globals.conffile <> "") then
49               begin
50               let frontends = Conffile.read_frontends !Globals.conffile in
51                 input_file_list:=List.concat [!input_file_list;frontends]
52               end;
53
54             let felst = List.map (fun lst->let (x,y)=lst in fprintf logfd "Slice %s (%s)\n" x y;flush logfd;new frontendHandler lst) !input_file_list in
55                 let _ = new backendHandler !Globals.backend felst in
56                  Fdwatcher.start_watch ()
57     end