Startup log
[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     ("-failsafe",Arg.Set(Globals.failsafe), "Never crash. Be stupid, but never crash. Use at your own risk.");
22   ]
23
24 let cont = ref true
25
26 let _ =
27   printf "Vsys v%s\n" Globals.vsys_version;flush stdout;
28   fprintf logfd "Starting Vsys v%s\n" Globals.vsys_version;flush logfd;
29   Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";  
30   if (!Globals.backend == "") then
31       printf "Try vsys --help\n"
32   else
33     begin
34       if (!daemonize) then
35         begin
36           printf "Daemonizing\n";flush Pervasives.stdout;
37         let child = Unix.fork () in
38           if (child <> 0) then
39             begin
40                 let pidfile = open_out !Globals.pid_filepath in
41                   fprintf pidfile "%d" child;
42                     close_out pidfile;
43                     exit(0)
44             end
45           end;
46
47             Dirwatcher.initialize ();
48             Directfifowatcher.initialize ();
49
50             if (!Globals.conffile <> "") then
51               begin
52               let frontends = Conffile.read_frontends !Globals.conffile in
53                 input_file_list:=List.concat [!input_file_list;frontends]
54               end;
55
56             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
57                 let _ = new backendHandler !Globals.backend felst in
58                  Fdwatcher.start_watch ()
59     end