Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
server: add status command
cmd/beterrabad/executor.ha | 31 ++++++++++++++++++++++++++----- cmd/beterrabad/socket.ha | 2 +-
diff --git a/cmd/beterrabad/executor.ha b/cmd/beterrabad/executor.ha index c801811639e0186ba9fbec02dfa97fb3a9a5d5bd..881328df472366d0156b20e1f20838909c424085 100644 --- a/cmd/beterrabad/executor.ha +++ b/cmd/beterrabad/executor.ha @@ -7,8 +7,27 @@ use beterraba; type booterror = !(exec::error | exec::nocmd); -fn status_service(cmdargs: str) str = { - return "TODO"; +fn status_service(svcname: str, serv: *server) str = { + let service: nullable *beterraba::service = null; + + for (let i = 0z; i < len(serv.services); i += 1) { + if (serv.services[i].name == svcname) { + service = &serv.services[i]; + break; + }; + }; + + match (service) { + case null => + return "Didn't find a service with that name"; + case let svc: *beterraba::service => + match (peek(svc)) { + case let stat: beterraba::status => + return beterraba::strstatus(stat); + case void => + return "WTF"; + }; + }; }; fn start_service(svcname: str, serv: *server) str = { @@ -46,7 +65,7 @@ return strings::join("|", names...); }; // Check if the process is still alive and bail out if it's ok -fn peek(service: *beterraba::service) void = { +fn peek(service: *beterraba::service) (void | beterraba::status) = { // TODO: Move this kind of thing into a better structured log facility log::printfln("Peeking on {}", service.name); @@ -57,15 +76,17 @@ match (status) { case exec::exit_status => service.status = beterraba::status::STOPPED; + + return beterraba::status::STOPPED; case exec::signaled => // TODO: Add the exit msg service.status = beterraba::status::CRASHED; }; case void => - log::println("Still running... Moving on"); - return; + return beterraba::status::STARTED; case let err: exec::error => service.status = beterraba::status::CRASHED; + return beterraba::status::CRASHED; }; }; diff --git a/cmd/beterrabad/socket.ha b/cmd/beterrabad/socket.ha index c53a715c5a9dbf9ba1de2c36408f14b45f04ba6c..d5e2c6b9833dc5233e53c18477f0e73ee5d8babf 100644 --- a/cmd/beterrabad/socket.ha +++ b/cmd/beterrabad/socket.ha @@ -194,7 +194,7 @@ case "start" => let status = start_service(args, server); fmt::fprintf(&buf, status)?; case "status" => - let status = status_service(args); + let status = status_service(args, server); fmt::fprintf(&buf, status)?; case "list" => let status = list_services(args, server);