rc-status -c now lists services that have crashed.

It returns 0 if there are crashed services, otherwise 1.
This it easy to restart crashed services automatically.
More for #120.
This commit is contained in:
Roy Marples 2009-04-24 10:17:53 +00:00
parent e2629b0a3b
commit 9966a902ab
2 changed files with 21 additions and 10 deletions

View File

@ -1,4 +1,4 @@
.\" Copyright 2007-2008 Roy Marples .\" Copyright 2007-2009 Roy Marples
.\" All rights reserved .\" All rights reserved
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd Arp 9, 2008 .Dd April 24, 2008
.Dt RC-STATUS 8 SMM .Dt RC-STATUS 8 SMM
.Os OpenRC .Os OpenRC
.Sh NAME .Sh NAME
@ -30,7 +30,7 @@
.Nd show status info about runlevels .Nd show status info about runlevels
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl alsuC .Op Fl aclsuC
.Op Ar runlevel .Op Ar runlevel
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -43,6 +43,8 @@ The options are as follows:
.Bl -tag -width ".Fl test , test string" .Bl -tag -width ".Fl test , test string"
.It Fl a , -all .It Fl a , -all
Show all runlevels and their services. Show all runlevels and their services.
.It Fl c , -crashed
List all services that have crashed.
.It Fl l , -list .It Fl l , -list
List all defined runlevels. List all defined runlevels.
.It fl r , -runlevel .It fl r , -runlevel
@ -57,6 +59,9 @@ Disable color output.
Show information only for the named Show information only for the named
.Ar runlevel . .Ar runlevel .
.El .El
.Sh EXIT STATUS
.Nm
exits 0, except when checking for crashed services and it doesn't find any.
.Sh SEE ALSO .Sh SEE ALSO
.Xr rc 8 , .Xr rc 8 ,
.Xr rc-update 8 .Xr rc-update 8

View File

@ -172,9 +172,10 @@ print_services(const char *runlevel, RC_STRINGLIST *svcs)
#include "_usage.h" #include "_usage.h"
#define extraopts "[runlevel1] [runlevel2] ..." #define extraopts "[runlevel1] [runlevel2] ..."
#define getoptstring "alrsu" getoptstring_COMMON #define getoptstring "aclrsu" getoptstring_COMMON
static const struct option longopts[] = { static const struct option longopts[] = {
{"all", 0, NULL, 'a'}, {"all", 0, NULL, 'a'},
{"crashed", 0, NULL, 'c'},
{"list", 0, NULL, 'l'}, {"list", 0, NULL, 'l'},
{"runlevel", 0, NULL, 'r'}, {"runlevel", 0, NULL, 'r'},
{"servicelist", 0, NULL, 's'}, {"servicelist", 0, NULL, 's'},
@ -183,6 +184,7 @@ static const struct option longopts[] = {
}; };
static const char * const longopts_help[] = { static const char * const longopts_help[] = {
"Show services from all run levels", "Show services from all run levels",
"Show crashed services",
"Show list of run levels", "Show list of run levels",
"Show the name of the current runlevel", "Show the name of the current runlevel",
"Show service list", "Show service list",
@ -196,7 +198,7 @@ rc_status(int argc, char **argv)
{ {
RC_STRING *s, *l, *t; RC_STRING *s, *l, *t;
char *p, *runlevel = NULL; char *p, *runlevel = NULL;
int opt, aflag = 0; int opt, aflag = 0, retval = 0;
test_crashed = _rc_can_find_pids(); test_crashed = _rc_can_find_pids();
@ -207,10 +209,14 @@ rc_status(int argc, char **argv)
aflag++; aflag++;
levels = rc_runlevel_list(); levels = rc_runlevel_list();
break; break;
case 'l': case 'c':
levels = rc_runlevel_list(); services = rc_services_in_state(RC_SERVICE_STARTED);
TAILQ_FOREACH (l, levels, entries) retval = 1;
printf("%s\n", l->value); TAILQ_FOREACH(s, services, entries)
if (rc_service_daemons_crashed(s->value)) {
printf("%s\n", s->value);
retval = 0;
}
goto exit; goto exit;
/* NOTREACHED */ /* NOTREACHED */
case 'r': case 'r':
@ -344,5 +350,5 @@ exit:
rc_deptree_free(deptree); rc_deptree_free(deptree);
#endif #endif
return(EXIT_SUCCESS); return retval;
} }