mirror of
https://github.com/pygos/init.git
synced 2024-11-22 11:19:45 +01:00
Cleanup status reporting
- mimic format of initd - skip formatting if not a tty - distinguish exited because failed vs exited because done Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
3f40c4d3ed
commit
a9602ad6e0
3 changed files with 32 additions and 16 deletions
|
@ -53,31 +53,35 @@ static int cmd_status(int argc, char **argv)
|
||||||
switch (resp.state) {
|
switch (resp.state) {
|
||||||
case ESS_RUNNING:
|
case ESS_RUNNING:
|
||||||
if (!is_tty) {
|
if (!is_tty) {
|
||||||
state = "Running";
|
state = "UP";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state = "\033[22;32mRunning\033[0m";
|
state = "\033[22;32m UP \033[0m";
|
||||||
break;
|
break;
|
||||||
case ESS_ENQUEUED:
|
case ESS_ENQUEUED:
|
||||||
state = " Queue ";
|
state = "SCHED";
|
||||||
break;
|
break;
|
||||||
case ESS_EXITED:
|
case ESS_FAILED:
|
||||||
if (!is_tty) {
|
if (!is_tty) {
|
||||||
state = "Exited ";
|
state = "FAIL";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (resp.exit_status == EXIT_SUCCESS) {
|
state = "\033[22;31mFAIL\033[0m";
|
||||||
state = "\033[22;33mExited \033[0m";
|
break;
|
||||||
} else {
|
case ESS_DONE:
|
||||||
state = "\033[22;31mExited \033[0m";
|
if (!is_tty) {
|
||||||
|
state = "DONE";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state = "\033[22;33mDONE\033[0m";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!is_tty) {
|
if (!is_tty) {
|
||||||
state = "Unknown";
|
state = "UNKNOWN";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state = "\033[22;31mUnknown\033[0m";
|
state = "\033[22;31mUNKNOWN\033[0m";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,8 +102,8 @@ static command_t status = {
|
||||||
.usage = "",
|
.usage = "",
|
||||||
.s_desc = "report the status of the currently enabled services",
|
.s_desc = "report the status of the currently enabled services",
|
||||||
.l_desc = "Gathers a list of all currently running services and the "
|
.l_desc = "Gathers a list of all currently running services and the "
|
||||||
"state that they are in (currently running, exited, wating "
|
"state that they are in (currently running, done, failed, "
|
||||||
"to get scheduled).",
|
"wating to get scheduled).",
|
||||||
.run_cmd = cmd_status,
|
.run_cmd = cmd_status,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ static service_t *running = NULL;
|
||||||
static service_t *terminated = NULL;
|
static service_t *terminated = NULL;
|
||||||
static service_t *queue = NULL;
|
static service_t *queue = NULL;
|
||||||
static service_t *completed = NULL;
|
static service_t *completed = NULL;
|
||||||
|
static service_t *failed = NULL;
|
||||||
static int singleshot = 0;
|
static int singleshot = 0;
|
||||||
static bool waiting = false;
|
static bool waiting = false;
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ static void handle_terminated_service(service_t *svc)
|
||||||
|
|
||||||
if (svc->rspwn_limit == 0) {
|
if (svc->rspwn_limit == 0) {
|
||||||
print_status(svc->desc, STATUS_FAIL, false);
|
print_status(svc->desc, STATUS_FAIL, false);
|
||||||
break;
|
goto out_failure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +52,8 @@ static void handle_terminated_service(service_t *svc)
|
||||||
STATUS_OK : STATUS_FAIL, true);
|
STATUS_OK : STATUS_FAIL, true);
|
||||||
if (singleshot == 0 && queue == NULL)
|
if (singleshot == 0 && queue == NULL)
|
||||||
target_completed(target);
|
target_completed(target);
|
||||||
|
if (svc->status != EXIT_SUCCESS)
|
||||||
|
goto out_failure;
|
||||||
break;
|
break;
|
||||||
case SVC_ONCE:
|
case SVC_ONCE:
|
||||||
singleshot -= 1;
|
singleshot -= 1;
|
||||||
|
@ -59,10 +62,16 @@ static void handle_terminated_service(service_t *svc)
|
||||||
STATUS_OK : STATUS_FAIL, false);
|
STATUS_OK : STATUS_FAIL, false);
|
||||||
if (singleshot == 0 && queue == NULL && !waiting)
|
if (singleshot == 0 && queue == NULL && !waiting)
|
||||||
target_completed(target);
|
target_completed(target);
|
||||||
|
if (svc->status != EXIT_SUCCESS)
|
||||||
|
goto out_failure;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
svc->next = completed;
|
svc->next = completed;
|
||||||
completed = svc;
|
completed = svc;
|
||||||
|
return;
|
||||||
|
out_failure:
|
||||||
|
svc->next = failed;
|
||||||
|
failed = svc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void supervisor_handle_exited(pid_t pid, int status)
|
void supervisor_handle_exited(pid_t pid, int status)
|
||||||
|
@ -185,7 +194,9 @@ void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen)
|
||||||
{
|
{
|
||||||
if (send_svc_list(fd, dst, addrlen, ESS_RUNNING, running))
|
if (send_svc_list(fd, dst, addrlen, ESS_RUNNING, running))
|
||||||
return;
|
return;
|
||||||
if (send_svc_list(fd, dst, addrlen, ESS_EXITED, completed))
|
if (send_svc_list(fd, dst, addrlen, ESS_DONE, completed))
|
||||||
|
return;
|
||||||
|
if (send_svc_list(fd, dst, addrlen, ESS_FAILED, failed))
|
||||||
return;
|
return;
|
||||||
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, queue))
|
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, queue))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -15,7 +15,8 @@ typedef enum {
|
||||||
ESS_NONE = 0x00,
|
ESS_NONE = 0x00,
|
||||||
ESS_RUNNING = 0x01,
|
ESS_RUNNING = 0x01,
|
||||||
ESS_ENQUEUED = 0x02,
|
ESS_ENQUEUED = 0x02,
|
||||||
ESS_EXITED = 0x03,
|
ESS_DONE = 0x03,
|
||||||
|
ESS_FAILED = 0x04
|
||||||
} E_SERVICE_STATE;
|
} E_SERVICE_STATE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue