Version 0.6.
[whenjobs.git] / tools / whenjobs.ml
index e0f3cc9..f77e825 100644 (file)
@@ -407,7 +407,7 @@ and list_variables () =
   stop_client client
 
 and daemon_start () =
-  assert false
+  exit (Sys.command "whenjobsd")
 
 and daemon_stop () =
   let client = start_client () in
@@ -421,10 +421,25 @@ and daemon_stop () =
   stop_client client
 
 and daemon_restart () =
-  assert false
+  (try
+     let client = start_client_no_exit () in
+     ignore (Whenproto_clnt.When.V1.exit_daemon client ());
+     stop_client client
+   with _ -> ()
+  );
+  sleep 1;
+  daemon_start ()
 
 and daemon_status () =
-  assert false
+  let r =
+    try
+      let client = start_client_no_exit () in
+      let r = Whenproto_clnt.When.V1.ping_daemon client () in
+      stop_client client;
+      r = `ok
+    with
+      exn -> false in
+  print_endline (if r then "up" else "down")
 
 and jobs () =
   let client = start_client () in
@@ -514,10 +529,7 @@ and create_tutorial file =
 and start_client () =
   let addr = sprintf "%s/socket" jobsdir in
   let client =
-    try
-      Whenproto_clnt.When.V1.create_client
-        (Rpc_client.Unix addr)
-        Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *)
+    try start_client_no_exit ()
     with
     | Unix_error ((ECONNREFUSED|ENOENT), _, _) ->
       eprintf "whenjobs: error: the daemon ('whenjobsd') is not running\n";
@@ -528,6 +540,12 @@ and start_client () =
       exit 1 in
   client
 
+and start_client_no_exit () =
+  let addr = sprintf "%s/socket" jobsdir in
+  Whenproto_clnt.When.V1.create_client
+    (Rpc_client.Unix addr)
+    Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *)
+
 and stop_client client =
   Rpc_client.shut_down client