From: Richard W.M. Jones Date: Sat, 10 Mar 2012 13:21:59 +0000 (+0000) Subject: Implement 'whenjobs --daemon-status'. X-Git-Tag: 0.6~2 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=46130209a2535fe06801f933e164c65084119705;p=whenjobs.git Implement 'whenjobs --daemon-status'. --- diff --git a/tools/whenjobs.ml b/tools/whenjobs.ml index e0f3cc9..db32eaf 100644 --- a/tools/whenjobs.ml +++ b/tools/whenjobs.ml @@ -424,7 +424,15 @@ and daemon_restart () = assert false 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 +522,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 +533,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