3 using System
.Diagnostics
;
4 using System
.Threading
;
14 // Returns the daemon's version
15 static public string Ping ()
17 Beagle
.RequestMessage request
;
18 request
= new Beagle
.DaemonInformationRequest ();
20 Beagle
.ResponseMessage response
= null;
22 while (response
== null) {
24 response
= request
.Send ();
26 Log
.Spew ("ERROR: Daemon is not responding");
31 Beagle
.DaemonInformationResponse info
;
32 info
= (Beagle
.DaemonInformationResponse
) response
;
37 static public void Start ()
39 Log
.Spew ("Starting daemon");
42 beagled
= Environment
.GetEnvironmentVariable ("BEAGLED_COMMAND");
45 args
= "--debug --bg --allow-backend files";
49 p
.StartInfo
.UseShellExecute
= false;
51 p
.StartInfo
.FileName
= beagled
;
52 p
.StartInfo
.Arguments
= args
;
54 p
.StartInfo
.EnvironmentVariables
["BEAGLE_HOME"] = Beagle
.Util
.PathFinder
.HomeDir
;
55 p
.StartInfo
.EnvironmentVariables
["BEAGLE_EXERCISE_THE_DOG"] = "1";
57 Thread
.Sleep (2000); // wait 2s to let the daemon get started
62 version
= Ping (); // Then try to ping the daemon
64 Log
.Spew ("Successfully started daemon (version={0})", version
);
67 static public string GetStatus ()
69 Beagle
.RequestMessage request
;
70 request
= new Beagle
.DaemonInformationRequest ();
72 Beagle
.ResponseMessage response
= null;
74 int failure_count
= 0;
75 while (response
== null) {
77 response
= request
.Send ();
80 if (failure_count
> 10)
81 Log
.Spew ("Daemon is not responding");
86 Beagle
.DaemonInformationResponse info
;
87 info
= (Beagle
.DaemonInformationResponse
) response
;
89 return info
.HumanReadableStatus
;
92 static public void WaitUntilIdle ()
94 Stopwatch sw
= new Stopwatch ();
101 status
= GetStatus ();
102 if (status
.IndexOf ("Waiting on empty queue") != -1)
106 Log
.Spew ("Waiting for daemon to become idle");
114 Log
.Spew ("Waited for {0}", sw
);
117 static public void OptimizeIndexes ()
119 Beagle
.RequestMessage request
;
120 request
= new Beagle
.OptimizeIndexesRequest ();
122 Log
.Spew ("Optimizing Indexes");
127 Log
.Failure ("Optimize request failed");
131 static public void Shutdown ()
133 Beagle
.RequestMessage request
;
134 request
= new Beagle
.ShutdownRequest ();
136 Log
.Spew ("Shutting down daemon");
141 Log
.Failure ("beagled shutdown failed");