Add drop command
This commit is contained in:
parent
f9cfab1e0d
commit
6302579f22
8
catsit.8
8
catsit.8
@ -1,4 +1,4 @@
|
|||||||
.Dd August 15, 2020
|
.Dd August 16, 2020
|
||||||
.Dt CATSIT 8
|
.Dt CATSIT 8
|
||||||
.Os
|
.Os
|
||||||
.
|
.
|
||||||
@ -9,7 +9,7 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl c Ar control
|
.Op Fl c Ar control
|
||||||
.Cm start|stop|restart|status Ns | Ns Ar signal
|
.Cm start|stop|restart|status|drop Ns | Ns Ar signal
|
||||||
.Ar service ...
|
.Ar service ...
|
||||||
.
|
.
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -55,6 +55,10 @@ then stopped services will be started.
|
|||||||
.It Cm status
|
.It Cm status
|
||||||
Log the current status of any matching services.
|
Log the current status of any matching services.
|
||||||
.
|
.
|
||||||
|
.It Cm drop
|
||||||
|
Drop any matching stopped services
|
||||||
|
from the services list.
|
||||||
|
.
|
||||||
.It Ar signal
|
.It Ar signal
|
||||||
Send the named signal
|
Send the named signal
|
||||||
to the processes of any matching started services.
|
to the processes of any matching started services.
|
||||||
|
@ -27,7 +27,7 @@ fi
|
|||||||
[ $# -lt 2 ] && die 'service name required'
|
[ $# -lt 2 ] && die 'service name required'
|
||||||
|
|
||||||
action=$(echo "${1}" | tr 'A-Z' 'a-z')
|
action=$(echo "${1}" | tr 'A-Z' 'a-z')
|
||||||
for valid in start stop restart status $(kill -l | tr 'A-Z' 'a-z'); do
|
for valid in start stop restart status drop $(kill -l | tr 'A-Z' 'a-z'); do
|
||||||
[ "${action}" = "${valid}" ] && break
|
[ "${action}" = "${valid}" ] && break
|
||||||
done
|
done
|
||||||
if [ "${action}" != "${valid}" ]; then
|
if [ "${action}" != "${valid}" ]; then
|
||||||
|
11
daemon.c
11
daemon.c
@ -126,6 +126,7 @@ static void parseControl(char *command) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool drop = false;
|
||||||
Action *fn = NULL;
|
Action *fn = NULL;
|
||||||
int signal = 0;
|
int signal = 0;
|
||||||
if (!strcmp(action, "start")) {
|
if (!strcmp(action, "start")) {
|
||||||
@ -136,6 +137,8 @@ static void parseControl(char *command) {
|
|||||||
fn = serviceRestart;
|
fn = serviceRestart;
|
||||||
} else if (!strcmp(action, "status")) {
|
} else if (!strcmp(action, "status")) {
|
||||||
fn = serviceStatus;
|
fn = serviceStatus;
|
||||||
|
} else if (!strcmp(action, "drop")) {
|
||||||
|
drop = true;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 1; i < NSIG; ++i) {
|
for (int i = 1; i < NSIG; ++i) {
|
||||||
if (strcasecmp(action, sys_signame[i])) continue;
|
if (strcasecmp(action, sys_signame[i])) continue;
|
||||||
@ -143,7 +146,7 @@ static void parseControl(char *command) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!fn && !signal) {
|
if (!drop && !fn && !signal) {
|
||||||
syslog(LOG_NOTICE, "unknown action or signal %s", action);
|
syslog(LOG_NOTICE, "unknown action or signal %s", action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,10 +154,12 @@ static void parseControl(char *command) {
|
|||||||
while (command) {
|
while (command) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
char *pattern = strsep(&command, WS);
|
char *pattern = strsep(&command, WS);
|
||||||
for (size_t i = 0; i < services.len; ++i) {
|
for (size_t i = services.len - 1; i < services.len; --i) {
|
||||||
struct Service *service = &services.ptr[i];
|
struct Service *service = &services.ptr[i];
|
||||||
if (fnmatch(pattern, service->name, 0)) continue;
|
if (fnmatch(pattern, service->name, 0)) continue;
|
||||||
if (signal) {
|
if (drop) {
|
||||||
|
serviceDrop(i);
|
||||||
|
} else if (signal) {
|
||||||
serviceSignal(service, signal);
|
serviceSignal(service, signal);
|
||||||
} else {
|
} else {
|
||||||
fn(service);
|
fn(service);
|
||||||
|
1
daemon.h
1
daemon.h
@ -130,6 +130,7 @@ extern struct Services {
|
|||||||
} services;
|
} services;
|
||||||
|
|
||||||
int serviceAdd(const char *name, const char *command);
|
int serviceAdd(const char *name, const char *command);
|
||||||
|
void serviceDrop(size_t index);
|
||||||
void serviceStatus(struct Service *service);
|
void serviceStatus(struct Service *service);
|
||||||
void serviceStart(struct Service *service);
|
void serviceStart(struct Service *service);
|
||||||
void serviceStop(struct Service *service);
|
void serviceStop(struct Service *service);
|
||||||
|
@ -119,6 +119,14 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serviceDrop(size_t index) {
|
||||||
|
struct Service *service = &services.ptr[index];
|
||||||
|
if (service->state != Stop) return;
|
||||||
|
syslog(LOG_NOTICE, "%s[] dropped", service->name);
|
||||||
|
serviceFree(service);
|
||||||
|
services.ptr[index] = services.ptr[--services.len];
|
||||||
|
}
|
||||||
|
|
||||||
void serviceStatus(struct Service *service) {
|
void serviceStatus(struct Service *service) {
|
||||||
if (service->state == Stop && service->intent == Stop) {
|
if (service->state == Stop && service->intent == Stop) {
|
||||||
syslog(LOG_NOTICE, "%s[] is stopped", service->name);
|
syslog(LOG_NOTICE, "%s[] is stopped", service->name);
|
||||||
|
Loading…
Reference in New Issue
Block a user