copy files from factory->factory/exec, from where they are installed
[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);
20                            Arg.String(fun s->cur_slice:=s;
21                                              input_file_list:=(!cur_dir,!cur_slice)::!input_file_list)], 
22      "frontendN,slicenameN");
23     ("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment");
24     ("-failsafe",Arg.Set(Globals.failsafe), "Never crash. Be stupid, but never crash. Use at your own risk.");
25   ]
26
27 let _ =
28   logprint "Starting Vsys v%s\n" Globals.vsys_version;
29   print "Starting Vsys v%s\n" Globals.vsys_version;
30   Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";  
31   if (!Globals.backend == "") then
32     printf "Try vsys --help\n"
33   else
34     begin
35       if (!daemonize) then
36         begin
37           print "Daemonizing\n";
38           let child = Unix.fork () in
39             if (child <> 0) then
40               begin
41                 let pidfile = open_out !Globals.pid_filepath in
42                   fprintf pidfile "%d" child;
43                   close_out pidfile;
44                   exit(0)
45               end
46         end;
47
48       Dirwatcher.initialize ();
49       Directfifowatcher.initialize ();
50
51       if (!Globals.conffile <> "") then
52         begin
53           let frontends = Conffile.read_frontends !Globals.conffile in
54             input_file_list:=List.concat [!input_file_list;frontends]
55         end;
56
57       let felst = List.map 
58                     (fun lst->let (x,y)=lst in 
59                        logprint "Slice %s (%s)\n" x y;
60                        new frontendHandler lst) 
61                     !input_file_list in
62       let _ = new backendHandler !Globals.backend felst in
63         Fdwatcher.start_watch ()
64     end