X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=main.ml;h=ac7a8cea88bccdc03c8a213e2b0bf27a8b2abfc6;hb=11c28a7eb5d029479076ed21e5a2f0601be3761a;hp=be96b82e074bafa8996f1ac0436499190cfb2f27;hpb=d549a9725e4e1f731a08a147a33d6f3a13c4e648;p=vsys.git diff --git a/main.ml b/main.ml index be96b82..ac7a8ce 100644 --- a/main.ml +++ b/main.ml @@ -4,31 +4,56 @@ open Printf open Inotify open Backend open Frontend -open Fifowatcher +open Conffile let input_file_list = ref [] let cur_dir = ref "" let cur_slice = ref "" +let daemonize = ref false let cmdspeclist = [ + ("-daemon",Arg.Set(daemonize), "Daemonize"); + ("-conffile",Arg.Set_string(Globals.conffile), "Config file"); ("-backend",Arg.Set_string(Globals.backend), "Backend directory"); ("-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"); - ("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment") + ("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment"); + ("-failsafe",Arg.Set(Globals.failsafe), "Never crash. Be stupid, but never crash. Use at your own risk."); ] let cont = ref true let _ = printf "Vsys v%s\n" Globals.vsys_version;flush stdout; + fprintf logfd "Starting Vsys v%s\n" Globals.vsys_version;flush logfd; Arg.parse cmdspeclist (fun x->()) "Usage: vsys "; - if (!Globals.backend == "" || !input_file_list == []) then + if (!Globals.backend == "") then printf "Try vsys --help\n" else begin - Dirwatcher.initialize (); - Fifowatcher.initialize (); - let felst = List.map (fun lst->new frontendHandler lst) !input_file_list in - let _ = new backendHandler !Globals.backend felst in - Fdwatcher.start_watch () + if (!daemonize) then + begin + printf "Daemonizing\n";flush Pervasives.stdout; + let child = Unix.fork () in + if (child <> 0) then + begin + let pidfile = open_out !Globals.pid_filepath in + fprintf pidfile "%d" child; + close_out pidfile; + exit(0) + end + end; + + Dirwatcher.initialize (); + Directfifowatcher.initialize (); + + if (!Globals.conffile <> "") then + begin + let frontends = Conffile.read_frontends !Globals.conffile in + input_file_list:=List.concat [!input_file_list;frontends] + end; + + 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 + let _ = new backendHandler !Globals.backend felst in + Fdwatcher.start_watch () end