Exemple #1
0
                public static bool StartServer ()
                {
                        Logger.Log.Debug ("Starting messaging server");

                        try {
                                server = new Server ("socket", false, Conf.Networking.GetOption (Conf.Names.ServiceEnabled, false));
                                server.Start ();
                        } catch (InvalidOperationException) {
                                return false;
                        }

                        return true;
                }
Exemple #2
0
                private static void DoMain (string [] args)
                {
                        SystemInformation.SetProcessName ("beagrepd-helper");

                        bool run_by_hand = (Environment.GetEnvironmentVariable ("BEAGREP_RUN_HELPER_BY_HAND") != null);
                        bool log_in_fg = (Environment.GetEnvironmentVariable ("BEAGREP_LOG_IN_THE_FOREGROUND_PLEASE") != null);

                        bool debug = false, disable_textcache = false;

                        foreach (string arg in args)
                                if (arg == "--disable-text-cache")
                                        disable_textcache = true;
                                else if (arg == "--debug")
                                        debug = true;

                        last_activity = DateTime.Now;

                        Log.Initialize (PathFinder.LogDir,
                                        "IndexHelper",
                                        debug ? LogLevel.Debug : LogLevel.Warn,
                                        run_by_hand || log_in_fg);

                        Log.Always ("Starting Index Helper process (version {0})", ExternalStringsHack.Version);
                        Log.Always ("Running on {0}", SystemInformation.MonoRuntimeVersion);
                        Log.Always ("Extended attributes are {0}", ExtendedAttribute.Supported ? "supported" : "not supported");
                        Log.Always ("Command Line: {0}",
                                    Environment.CommandLine != null ? Environment.CommandLine : "(null)");
                        if (disable_textcache)
                                Log.Always ("Text cache is disabled.");

                        // Initialize GObject type system
                        g_type_init ();

                        // Set the IO priority to idle, nice ourselves, and set
                        // a batch scheduling policy so we that we play nice
                        // on the system
                        if (Environment.GetEnvironmentVariable ("BEAGREP_EXERCISE_THE_DOG") != null)
                                Log.Always ("BEAGREP_EXERCISE_THE_DOG is set");

                        Server.Init ();

#if MONO_1_9
                        Shutdown.SetupSignalHandlers (new Shutdown.SignalHandler (HandleSignal));
#else
                        SetupSignalHandlers ();
#endif

                        Shutdown.ShutdownEvent += OnShutdown;

                        main_loop = new MainLoop ();
                        Shutdown.RegisterMainLoop (main_loop);

                        // Start the server
                        Log.Debug ("Starting messaging server");
                        bool server_has_been_started = false;
                        try {
                                server = new Server ("socket-helper", true, false);
                                server.Start ();
                                server_has_been_started = true;
                        } catch (InvalidOperationException ex) {
                                Logger.Log.Error (ex, "Couldn't start server.  Exiting immediately.");
                        }

                        if (server_has_been_started) {
                                // Whether we should generate heap-shot snapshots
                                heap_shot = (Environment.GetEnvironmentVariable ("_HEY_LETS_DO_A_HEAP_SHOT") != null);

                                if (! run_by_hand) {
                                        // Start the monitor thread, which keeps an eye on memory usage and idle time.
                                        ExceptionHandlingThread.Start (new ThreadStart (MemoryAndIdleMonitorWorker));

                                        // Start a thread that watches the daemon and begins a shutdown
                                        // if it terminates.
                                        ExceptionHandlingThread.Start (new ThreadStart (DaemonMonitorWorker));
                                }

                                // Start the main loop
                                main_loop.Run ();

                                ExceptionHandlingThread.JoinAllThreads ();

                                // If we placed our sockets in a temp directory, try to clean it up
                                // Note: this may fail because the daemon is still running
                                if (PathFinder.GetRemoteStorageDir (false) != PathFinder.StorageDir) {
                                        try {
                                                Directory.Delete (PathFinder.GetRemoteStorageDir (false));
                                        } catch (IOException) { }
                                }

                                Log.Always ("Index helper process shut down cleanly.");
                        }
                }