mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
Merge branch 'reload-script'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
38 files changed
+226
-235
No files matched your search
+13
-2
@@ -913,9 +913,20 @@ configurable with the following options:
|
|||||||
endless restarts. Useful in many use-cases, but not what `service`
|
endless restarts. Useful in many use-cases, but not what `service`
|
||||||
was originally designed for so not the default behavior
|
was originally designed for so not the default behavior
|
||||||
* `oncrash:reboot` -- when all retries have failed, and the service
|
* `oncrash:reboot` -- when all retries have failed, and the service
|
||||||
has *crashed*, if this option is set the system is rebooted.
|
has *crashed*, if this option is set the system is rebooted
|
||||||
* `oncrash:script` -- similarly, but instead of rebooting, call the
|
* `oncrash:script` -- similarly, but instead of rebooting, call the
|
||||||
`post:script` action if set, see below.
|
`post:script` action with exit code `crashed`, see below
|
||||||
|
* `reload:script [args]` -- some services do not support `SIGHUP` but
|
||||||
|
may have other ways to update the configuration of a running daemon.
|
||||||
|
When `reload:script` is defined it is preferred over `SIGHUP`
|
||||||
|
* `stop:script [args]` -- some services may require alternate methods
|
||||||
|
to be stopped. When `stop:script` is defined it is preferred over
|
||||||
|
`SIGTERM` and `stop`, for `service` and `sysv` stanzas, respectively
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> Both `reload:script` and `stop:script` are called as PID 1, without
|
||||||
|
> any timeout! Meaning, it is up to you to ensure the script is not
|
||||||
|
> blocking for seconds at a time or never terminates.
|
||||||
|
|
||||||
When stopping a service (run/task/sysv/service), either manually or when
|
When stopping a service (run/task/sysv/service), either manually or when
|
||||||
moving to another runlevel, Finit starts by sending `SIGTERM`, to allow
|
moving to another runlevel, Finit starts by sending `SIGTERM`, to allow
|
||||||
|
|||||||
+90
-50
@@ -1002,6 +1002,7 @@ static void service_cleanup(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
int service_stop(svc_t *svc)
|
int service_stop(svc_t *svc)
|
||||||
{
|
{
|
||||||
|
const char *id = svc_ident(svc, NULL, 0);
|
||||||
char cmdline[CMD_SIZE] = "";
|
char cmdline[CMD_SIZE] = "";
|
||||||
int do_progress = 1;
|
int do_progress = 1;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@@ -1014,11 +1015,11 @@ int service_stop(svc_t *svc)
|
|||||||
|
|
||||||
service_timeout_cancel(svc);
|
service_timeout_cancel(svc);
|
||||||
|
|
||||||
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
if (svc->stop_script[0]) {
|
||||||
if (!svc_is_sysv(svc)) {
|
logit(LOG_CONSOLE | LOG_NOTICE, "%s[%d], calling stop:%s ...", id, svc->pid, svc->stop_script);
|
||||||
|
} else if (!svc_is_sysv(svc)) {
|
||||||
char *nm = pid_get_name(svc->pid, NULL, 0);
|
char *nm = pid_get_name(svc->pid, NULL, 0);
|
||||||
const char *sig = sig_name(svc->sighalt);
|
const char *sig = sig_name(svc->sighalt);
|
||||||
char *id = svc_ident(svc, NULL, 0);
|
|
||||||
|
|
||||||
if (svc->pid <= 1)
|
if (svc->pid <= 1)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1030,9 +1031,10 @@ int service_stop(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbg("Sending %s to pid:%d name:%s(%s)", sig, svc->pid, id, nm);
|
dbg("Sending %s to pid:%d name:%s(%s)", sig, svc->pid, id, nm);
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...", id, svc->pid, sig);
|
logit(LOG_CONSOLE | LOG_NOTICE, "%s[%d], stopping, sending %s ...", id, svc->pid, sig);
|
||||||
} else {
|
} else {
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", cmdline);
|
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
||||||
|
logit(LOG_CONSOLE | LOG_NOTICE, "%s[%d], calling '%s stop' ...", id, svc->pid, cmdline);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1060,7 +1062,9 @@ int service_stop(svc_t *svc)
|
|||||||
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
|
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
|
||||||
print_desc("Stopping ", svc->desc);
|
print_desc("Stopping ", svc->desc);
|
||||||
|
|
||||||
if (!svc_is_sysv(svc)) {
|
if (svc->stop_script[0]) {
|
||||||
|
rc = run(svc->stop_script, NULL);
|
||||||
|
} else if (!svc_is_sysv(svc)) {
|
||||||
if (svc->pid > 1) {
|
if (svc->pid > 1) {
|
||||||
/*
|
/*
|
||||||
* Send SIGTERM to parent process of process group, not to the
|
* Send SIGTERM to parent process of process group, not to the
|
||||||
@@ -1071,11 +1075,8 @@ int service_stop(svc_t *svc)
|
|||||||
rc = kill(svc->pid, svc->sighalt);
|
rc = kill(svc->pid, svc->sighalt);
|
||||||
dbg("kill(%d, %d) => rc %d, errno %d", svc->pid, svc->sighalt, rc, errno);
|
dbg("kill(%d, %d) => rc %d, errno %d", svc->pid, svc->sighalt, rc, errno);
|
||||||
/* PID lost or forking process never really started */
|
/* PID lost or forking process never really started */
|
||||||
if (rc == -1 && (errno == ESRCH || errno == ENOENT)) {
|
if (rc == -1 && (errno == ESRCH || errno == ENOENT))
|
||||||
service_cleanup(svc);
|
rc = 1;
|
||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
|
||||||
} else
|
|
||||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
|
||||||
} else {
|
} else {
|
||||||
service_cleanup(svc);
|
service_cleanup(svc);
|
||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
@@ -1083,7 +1084,6 @@ int service_stop(svc_t *svc)
|
|||||||
} else {
|
} else {
|
||||||
char *args[MAX_NUM_SVC_ARGS + 1];
|
char *args[MAX_NUM_SVC_ARGS + 1];
|
||||||
size_t i = 0, j;
|
size_t i = 0, j;
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
args[i++] = svc->cmd;
|
args[i++] = svc->cmd;
|
||||||
/* this handles, e.g., bridge-stop br0 stop */
|
/* this handles, e.g., bridge-stop br0 stop */
|
||||||
@@ -1095,8 +1095,7 @@ int service_stop(svc_t *svc)
|
|||||||
args[i++] = "stop";
|
args[i++] = "stop";
|
||||||
args[i] = NULL;
|
args[i] = NULL;
|
||||||
|
|
||||||
pid = fork();
|
switch (fork()) {
|
||||||
switch (pid) {
|
|
||||||
case 0:
|
case 0:
|
||||||
setsid();
|
setsid();
|
||||||
redirect(svc);
|
redirect(svc);
|
||||||
@@ -1108,11 +1107,16 @@ int service_stop(svc_t *svc)
|
|||||||
rc = 1;
|
rc = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rc == 1) {
|
||||||
|
service_cleanup(svc);
|
||||||
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
|
} else
|
||||||
|
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||||
|
|
||||||
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
|
if (runlevel != 1 && do_progress && svc_is_daemon(svc))
|
||||||
print_result(rc);
|
print_result(rc);
|
||||||
|
|
||||||
@@ -1120,34 +1124,27 @@ int service_stop(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* service_restart - Restart a service by sending %SIGHUP
|
* service_reload - Reload a service
|
||||||
* @svc: Service to reload
|
* @svc: Service to reload
|
||||||
*
|
*
|
||||||
* This function does some basic checks of the runtime state of Finit
|
* This function does some basic checks of the runtime state of Finit
|
||||||
* and a sanity check of the @svc before sending %SIGHUP.
|
* and a sanity check of the @svc before sending %SIGHUP or calling
|
||||||
|
* the reload:script command.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* POSIX OK(0) or non-zero on error.
|
* POSIX OK(0) or non-zero on error.
|
||||||
*/
|
*/
|
||||||
static int service_restart(svc_t *svc)
|
static int service_reload(svc_t *svc)
|
||||||
{
|
{
|
||||||
|
const char *id = svc_ident(svc, NULL, 0);
|
||||||
int do_progress = 1;
|
int do_progress = 1;
|
||||||
pid_t lost = 0;
|
pid_t lost = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Ignore if finit is SIGSTOP'ed */
|
/* Ignore if service is invalid or finit is SIGSTOP'ed */
|
||||||
if (is_norespawn())
|
if (!svc || is_norespawn())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!svc || !svc->sighup)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (svc->pid <= 1) {
|
|
||||||
dbg("%s: bad PID %d for %s, SIGHUP", svc_ident(svc, NULL, 0), svc->pid, svc->cmd);
|
|
||||||
svc->start_time = svc->pid = 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skip progress if desc disabled or bootstrap task */
|
/* Skip progress if desc disabled or bootstrap task */
|
||||||
if (!svc->desc[0] || svc_in_runlevel(svc, INIT_LEVEL))
|
if (!svc->desc[0] || svc_in_runlevel(svc, INIT_LEVEL))
|
||||||
do_progress = 0;
|
do_progress = 0;
|
||||||
@@ -1155,14 +1152,28 @@ static int service_restart(svc_t *svc)
|
|||||||
if (do_progress)
|
if (do_progress)
|
||||||
print_desc("Restarting ", svc->desc);
|
print_desc("Restarting ", svc->desc);
|
||||||
|
|
||||||
dbg("Sending SIGHUP to PID %d", svc->pid);
|
if (svc->reload_script[0]) {
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Restarting %s[%d], sending SIGHUP ...",
|
logit(LOG_CONSOLE | LOG_NOTICE, "%s[%d], calling reload:%s ...", id, svc->pid, svc->reload_script);
|
||||||
svc_ident(svc, NULL, 0), svc->pid);
|
rc = run(svc->reload_script, NULL);
|
||||||
rc = kill(svc->pid, SIGHUP);
|
} else if (svc->sighup) {
|
||||||
if (rc == -1 && (errno == ESRCH || errno == ENOENT)) {
|
if (svc->pid <= 1) {
|
||||||
/* nobody home, reset internal state machine */
|
dbg("%s[%d]: bad PID, cannot reload service", id, svc->pid);
|
||||||
lost = svc->pid;
|
svc->start_time = svc->pid = 0;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
dbg("%s[%d], sending SIGHUP", id, svc->pid);
|
||||||
|
logit(LOG_CONSOLE | LOG_NOTICE, "%s[%d], sending SIGHUP ...", id, svc->pid);
|
||||||
|
rc = kill(svc->pid, SIGHUP);
|
||||||
|
if (rc == -1 && (errno == ESRCH || errno == ENOENT)) {
|
||||||
|
/* nobody home, reset internal state machine */
|
||||||
|
lost = svc->pid;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
warnx("%s: neither HUP nor reload:script defined, no action.", id);
|
||||||
|
rc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rc) {
|
||||||
/* Declare we're waiting for svc to re-assert/touch its pidfile */
|
/* Declare we're waiting for svc to re-assert/touch its pidfile */
|
||||||
svc_starting(svc);
|
svc_starting(svc);
|
||||||
|
|
||||||
@@ -1172,7 +1183,7 @@ static int service_restart(svc_t *svc)
|
|||||||
touch(pid_file(svc));
|
touch(pid_file(svc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
if (do_progress)
|
if (do_progress)
|
||||||
print_result(rc);
|
print_result(rc);
|
||||||
|
|
||||||
@@ -1386,26 +1397,36 @@ static void parse_script(svc_t *svc, char *type, char *script, int *tmo, char *b
|
|||||||
if (errstr) {
|
if (errstr) {
|
||||||
errx(1, "%s: tmo %s is %s (0-3600)", svc_ident(svc, NULL, 0),
|
errx(1, "%s: tmo %s is %s (0-3600)", svc_ident(svc, NULL, 0),
|
||||||
script, errstr);
|
script, errstr);
|
||||||
return;
|
goto err;
|
||||||
}
|
}
|
||||||
*tmo = (int)(sec * 1000);
|
*tmo = (int)(sec * 1000);
|
||||||
} else {
|
} else {
|
||||||
path = script;
|
path = script;
|
||||||
*tmo = svc->killdelay;
|
if (tmo)
|
||||||
|
*tmo = svc->killdelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unquote(&path, NULL)) {
|
||||||
|
errx(1, "Syntax error, unterminated quote in %s:%s", type, path);
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
found = which(path);
|
found = which(path);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
/* Not in $PATH, check if path exists and is executable */
|
logit(LOG_WARNING, "%s:%s is missing or not executable, skipping.", type, path);
|
||||||
if (access(path, X_OK)) {
|
goto err;
|
||||||
logit(LOG_WARNING, "%s:%s is missing or not executable, skipping.",
|
}
|
||||||
type, path);
|
free(found);
|
||||||
return;
|
|
||||||
}
|
if (strlen(path) >= len) {
|
||||||
} else
|
errx(1, "Command too long in %s:%s", type, path);
|
||||||
free(found);
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
strlcpy(buf, path, len);
|
strlcpy(buf, path, len);
|
||||||
|
return;
|
||||||
|
err:
|
||||||
|
memset(buf, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1591,6 +1612,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
char *id = NULL, *env = NULL, *cgroup = NULL;
|
char *id = NULL, *env = NULL, *cgroup = NULL;
|
||||||
char *pre_script = NULL, *post_script = NULL;
|
char *pre_script = NULL, *post_script = NULL;
|
||||||
char *ready_script = NULL, *conflict = NULL;
|
char *ready_script = NULL, *conflict = NULL;
|
||||||
|
char *reload_script = NULL, *stop_script = NULL;
|
||||||
char *cleanup_script = NULL;
|
char *cleanup_script = NULL;
|
||||||
char ident[MAX_IDENT_LEN];
|
char ident[MAX_IDENT_LEN];
|
||||||
char *ifstmt = NULL;
|
char *ifstmt = NULL;
|
||||||
@@ -1701,6 +1723,10 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
ready_script = arg;
|
ready_script = arg;
|
||||||
else if (MATCH_CMD(cmd, "cleanup:", arg))
|
else if (MATCH_CMD(cmd, "cleanup:", arg))
|
||||||
cleanup_script = arg;
|
cleanup_script = arg;
|
||||||
|
else if (MATCH_CMD(cmd, "reload:", arg))
|
||||||
|
reload_script = arg;
|
||||||
|
else if (MATCH_CMD(cmd, "stop:", arg))
|
||||||
|
stop_script = arg;
|
||||||
else if (MATCH_CMD(cmd, "env:", arg))
|
else if (MATCH_CMD(cmd, "env:", arg))
|
||||||
env = arg;
|
env = arg;
|
||||||
/* catch both cgroup: and cgroup. handled in parse_cgroup() */
|
/* catch both cgroup: and cgroup. handled in parse_cgroup() */
|
||||||
@@ -1896,6 +1922,16 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
else
|
else
|
||||||
memset(svc->cleanup_script, 0, sizeof(svc->cleanup_script));
|
memset(svc->cleanup_script, 0, sizeof(svc->cleanup_script));
|
||||||
|
|
||||||
|
if (reload_script)
|
||||||
|
parse_script(svc, "reload", reload_script, NULL, svc->reload_script, sizeof(svc->reload_script));
|
||||||
|
else
|
||||||
|
memset(svc->reload_script, 0, sizeof(svc->reload_script));
|
||||||
|
|
||||||
|
if (stop_script)
|
||||||
|
parse_script(svc, "stop", stop_script, NULL, svc->stop_script, sizeof(svc->stop_script));
|
||||||
|
else
|
||||||
|
memset(svc->stop_script, 0, sizeof(svc->stop_script));
|
||||||
|
|
||||||
if (!svc_is_tty(svc)) {
|
if (!svc_is_tty(svc)) {
|
||||||
if (log)
|
if (log)
|
||||||
parse_log(svc, log);
|
parse_log(svc, log);
|
||||||
@@ -2141,7 +2177,7 @@ void service_update_rdeps(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Service supports reloading conf without stop/start */
|
/* Service supports reloading conf without stop/start */
|
||||||
if (!svc_is_nohup(svc))
|
if (!svc_is_noreload(svc))
|
||||||
continue; /* Yup, no need to stop start rdeps */
|
continue; /* Yup, no need to stop start rdeps */
|
||||||
|
|
||||||
svc_mark_affected(mkcond(svc, cond, sizeof(cond)));
|
svc_mark_affected(mkcond(svc, cond, sizeof(cond)));
|
||||||
@@ -2776,7 +2812,11 @@ restart:
|
|||||||
|
|
||||||
case COND_ON:
|
case COND_ON:
|
||||||
if (svc_is_changed(svc)) {
|
if (svc_is_changed(svc)) {
|
||||||
if (svc_nohup(svc) || !svc_is_daemon(svc)) {
|
/*
|
||||||
|
* If service does not suport reload, or its command line
|
||||||
|
* arguments have been modified, we need to stop-start it.
|
||||||
|
*/
|
||||||
|
if (svc_is_noreload(svc) || svc->args_dirty) {
|
||||||
service_stop(svc);
|
service_stop(svc);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
@@ -2786,7 +2826,7 @@ restart:
|
|||||||
if (sm_in_reload())
|
if (sm_in_reload())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
service_restart(svc);
|
service_reload(svc);
|
||||||
}
|
}
|
||||||
|
|
||||||
svc_mark_clean(svc);
|
svc_mark_clean(svc);
|
||||||
|
|||||||
@@ -212,6 +212,12 @@ typedef struct svc {
|
|||||||
char cleanup_script[MAX_CMD_LEN];
|
char cleanup_script[MAX_CMD_LEN];
|
||||||
int cleanup_tmo;
|
int cleanup_tmo;
|
||||||
|
|
||||||
|
/* When set, used instead of SIGHUP or stop-start */
|
||||||
|
char reload_script[MAX_CMD_LEN];
|
||||||
|
|
||||||
|
/* When set, used instead of SIGTERM or sysv 'stop' */
|
||||||
|
char stop_script[MAX_CMD_LEN];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used to forcefully kill services that won't shutdown on
|
* Used to forcefully kill services that won't shutdown on
|
||||||
* termination and to delay restarts of crashing services.
|
* termination and to delay restarts of crashing services.
|
||||||
@@ -272,10 +278,9 @@ static inline int svc_is_tty (svc_t *svc) { return svc && SVC_TYPE_TTY
|
|||||||
static inline int svc_is_runtask (svc_t *svc) { return svc && (SVC_TYPE_RUNTASK & svc->type);}
|
static inline int svc_is_runtask (svc_t *svc) { return svc && (SVC_TYPE_RUNTASK & svc->type);}
|
||||||
static inline int svc_is_forking (svc_t *svc) { return svc && svc->forking; }
|
static inline int svc_is_forking (svc_t *svc) { return svc && svc->forking; }
|
||||||
static inline int svc_is_manual (svc_t *svc) { return svc && svc->manual; }
|
static inline int svc_is_manual (svc_t *svc) { return svc && svc->manual; }
|
||||||
static inline int svc_is_nohup (svc_t *svc) { return svc && (0 == svc->sighup); }
|
static inline int svc_is_noreload (svc_t *svc) { return svc && (0 == svc->sighup && 0 == svc->reload_script[0]); }
|
||||||
|
|
||||||
static inline int svc_in_runlevel (svc_t *svc, int runlevel) { return svc && ISSET(svc->runlevels, runlevel); }
|
static inline int svc_in_runlevel (svc_t *svc, int runlevel) { return svc && ISSET(svc->runlevels, runlevel); }
|
||||||
static inline int svc_nohup (svc_t *svc) { return svc && (0 == svc->sighup || 0 != svc->args_dirty); }
|
|
||||||
static inline int svc_has_pidfile (svc_t *svc) { return svc_is_daemon(svc) && svc->pidfile[0] != 0 && svc->pidfile[0] != '!'; }
|
static inline int svc_has_pidfile (svc_t *svc) { return svc_is_daemon(svc) && svc->pidfile[0] != 0 && svc->pidfile[0] != '!'; }
|
||||||
static inline int svc_has_pre (svc_t *svc) { return svc->pre_script[0]; }
|
static inline int svc_has_pre (svc_t *svc) { return svc->pre_script[0]; }
|
||||||
static inline int svc_has_post (svc_t *svc) { return svc->post_script[0]; }
|
static inline int svc_has_post (svc_t *svc) { return svc->post_script[0]; }
|
||||||
|
|||||||
@@ -642,6 +642,7 @@ int main(int argc, char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
tmpfiles(line);
|
tmpfiles(line);
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
|
|
||||||
say "Add a dynamic service in $FINIT_RCSD/service.conf"
|
say "Add a dynamic service in $FINIT_RCSD/service.conf"
|
||||||
run "echo 'service [2345] kill:20 log service.sh -- Dyn serv' > $FINIT_RCSD/service.conf"
|
run "echo 'service [2345] kill:20 log service.sh -- Dyn serv' > $FINIT_RCSD/service.conf"
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
|
|
||||||
say "Add a dynamic service in $FINIT_CONF"
|
say "Add a dynamic service in $FINIT_CONF"
|
||||||
run "echo 'service [2345] kill:20 log service.sh -- Dyn service' > $FINIT_CONF"
|
run "echo 'service [2345] kill:20 log service.sh -- Dyn service' > $FINIT_CONF"
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ BOOTSTRAP="run [S] crasher.sh -- Party crasher"
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ set COLORTERM=yes\n\
|
|||||||
b aq=oroszoe\n\
|
b aq=oroszoe\n\
|
||||||
baz=qux"
|
baz=qux"
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -362,6 +362,8 @@ echo "Finit running as PID $finit_pid"
|
|||||||
#tty=/dev/$(texec cat /sys/class/tty/console/active)
|
#tty=/dev/$(texec cat /sys/class/tty/console/active)
|
||||||
#texec cat "$tty" &
|
#texec cat "$tty" &
|
||||||
|
|
||||||
|
sep "Test start $(date)"
|
||||||
|
|
||||||
# Allow Finit to start up properly before launching the test
|
# Allow Finit to start up properly before launching the test
|
||||||
i=0
|
i=0
|
||||||
set +u
|
set +u
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-11
@@ -1,26 +1,20 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Regression test for basic /etc/rc.local functionality
|
# Regression test for basic /etc/rc.local functionality
|
||||||
# shellcheck disable=SC2317
|
# shellcheck disable=2317,2034
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
RCLOCAL="echo 'KILROY WAS HERE' > /tmp/rclocal"
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
#DEBUG=1
|
#DEBUG=1
|
||||||
# shellcheck disable=SC2034
|
|
||||||
RCLOCAL="echo 'KILROY WAS HERE' > /tmp/rclocal"
|
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
assert_file_contains /tmp/rclocal "KILROY WAS HERE"
|
assert_file_contains /tmp/rclocal "KILROY WAS HERE"
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
export TEST_TIMEOUT=5
|
export TEST_TIMEOUT=5
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,14 @@ run [4] name:four initctl restart service.sh -- Restart service"
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
RCLOCAL="echo \"$0 ==============\" &1>2"
|
RCLOCAL="echo \"$0 ==============\" &1>2"
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "$FINIT_CONF:"
|
say "$FINIT_CONF:"
|
||||||
run "cat $FINIT_CONF"
|
run "cat $FINIT_CONF"
|
||||||
say "/etc/rc.local:"
|
say "/etc/rc.local:"
|
||||||
|
|||||||
+1
-7
@@ -1,17 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Verify selecting alternate runlevel from cmdline
|
# Verify selecting alternate runlevel from cmdline
|
||||||
|
# shellcheck disable=SC2034
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
FINIT_RUNLEVEL=9
|
FINIT_RUNLEVEL=9
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
+5
-11
@@ -8,26 +8,20 @@
|
|||||||
# - SNNfoo should be called with a 'start' argument
|
# - SNNfoo should be called with a 'start' argument
|
||||||
# - KNNfoo should be called with a 'stop' argument
|
# - KNNfoo should be called with a 'stop' argument
|
||||||
#
|
#
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
BOOTSTRAP="runparts /etc/rc.d"
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
#DEBUG=1
|
#DEBUG=1
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
BOOTSTRAP="runparts /etc/rc.d"
|
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
lvl=$(texec initctl runlevel)
|
lvl=$(texec initctl runlevel)
|
||||||
say "Current runlevel $lvl"
|
say "Current runlevel $lvl"
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
|
|
||||||
say 'Ensure file system is cleared'
|
say 'Ensure file system is cleared'
|
||||||
run "rm -f /tmp/usr1.log"
|
run "rm -f /tmp/usr1.log"
|
||||||
|
|
||||||
|
|||||||
@@ -6,46 +6,54 @@ PIDFILE="/var/run/service.pid"
|
|||||||
|
|
||||||
start()
|
start()
|
||||||
{
|
{
|
||||||
printf 'Starting %s: ' "$DAEMON"
|
printf 'Starting %s: ' "$DAEMON"
|
||||||
start-stop-daemon -S -b -q -p "$PIDFILE" -x "$DAEMON"
|
start-stop-daemon -S -b -q -p "$PIDFILE" -x "$DAEMON"
|
||||||
|
|
||||||
status=$?
|
status=$?
|
||||||
if [ "$status" -eq 0 ]; then
|
if [ "$status" -eq 0 ]; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
else
|
else
|
||||||
echo "FAIL"
|
echo "FAIL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return "$status"
|
return "$status"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
printf 'Stopping %s: ' "$DAEMON"
|
printf 'Stopping %s: ' "$DAEMON"
|
||||||
start-stop-daemon -K -q -p "$PIDFILE"
|
start-stop-daemon -K -q -p "$PIDFILE"
|
||||||
|
|
||||||
status=$?
|
status=$?
|
||||||
if [ "$status" -eq 0 ]; then
|
if [ "$status" -eq 0 ]; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
else
|
else
|
||||||
echo "FAIL"
|
echo "FAIL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return "$status"
|
return "$status"
|
||||||
|
}
|
||||||
|
|
||||||
|
reload()
|
||||||
|
{
|
||||||
|
if [ -f "$PIDFILE" ]; then
|
||||||
|
PID=$(cat "$PIDFILE")
|
||||||
|
kill -HUP "$PID"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
restart()
|
restart()
|
||||||
{
|
{
|
||||||
stop
|
stop
|
||||||
sleep 1
|
sleep 1
|
||||||
start
|
start
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start|stop|restart)
|
start|stop|reload|restart)
|
||||||
"$1"
|
"$1"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 {start|stop|restart}, got $0 $1"
|
echo "Usage: $0 {start|stop|reload|restart}, got $0 $1"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
@@ -2,23 +2,33 @@
|
|||||||
|
|
||||||
cleanup()
|
cleanup()
|
||||||
{
|
{
|
||||||
echo "Got signal, stopping ..."
|
echo "Got signal, stopping ..."
|
||||||
rm -f /run/service.pid
|
rm -f /run/service.pid
|
||||||
exit 0
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
reload()
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
echo "Ready."
|
||||||
|
echo
|
||||||
|
sleep 1
|
||||||
|
echo $$ > /run/service.pid
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hook SIGUSR1 and dump trace to file system
|
# Hook SIGUSR1 and dump trace to file system
|
||||||
# shellcheck disable=SC2172
|
# shellcheck disable=SC2172
|
||||||
trap 'echo USR1 > /tmp/usr1.log' USR1
|
trap 'echo USR1 > /tmp/usr1.log' USR1
|
||||||
|
trap reload HUP
|
||||||
trap cleanup INT
|
trap cleanup INT
|
||||||
trap cleanup TERM
|
trap cleanup TERM
|
||||||
trap cleanup QUIT
|
trap cleanup QUIT
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
echo $$ > /run/service.pid
|
reload
|
||||||
|
|
||||||
# sleep may exit on known signal, so
|
# sleep may exit on known signal, so
|
||||||
# we cannot use 'set -e'
|
# we cannot use 'set -e'
|
||||||
while true; do
|
while true; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
@@ -17,7 +17,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
rm -f "$SYSROOT"/oldpid
|
rm -f "$SYSROOT"/oldpid
|
||||||
|
|
||||||
say "Add service stanza in $FINIT_CONF"
|
say "Add service stanza in $FINIT_CONF"
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ test_teardown()
|
|||||||
say "Check deps ..."
|
say "Check deps ..."
|
||||||
check_dep jq
|
check_dep jq
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
rm -f "$SYSROOT"/oldpid
|
rm -f "$SYSROOT"/oldpid
|
||||||
|
|
||||||
say "Add service stanza in $FINIT_CONF"
|
say "Add service stanza in $FINIT_CONF"
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ set -eu
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
|
|
||||||
say "Add service stanza in $FINIT_RCSD/service.conf"
|
say "Add service stanza in $FINIT_RCSD/service.conf"
|
||||||
run "echo 'service [2345] kill:20 log service.sh -- Subserv' > $FINIT_RCSD/service.conf"
|
run "echo 'service [2345] kill:20 log service.sh -- Subserv' > $FINIT_RCSD/service.conf"
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ test_teardown()
|
|||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
|
||||||
|
|
||||||
say "Add service stanza in $FINIT_CONF"
|
say "Add service stanza in $FINIT_CONF"
|
||||||
run "echo 'service [2345] kill:20 log service.sh -- Test service' > $FINIT_CONF"
|
run "echo 'service [2345] kill:20 log service.sh -- Test service' > $FINIT_CONF"
|
||||||
|
|
||||||
|
|||||||
+44
-22
@@ -1,38 +1,60 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# shellcheck disable=2034 source=/dev/null
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
STANZA1="sysv [2345] pid:!/run/service.pid name:service.sh log:stdout \
|
||||||
|
/etc/init.d/S01-service.sh -- SysV test service"
|
||||||
|
STANZA2="sysv [2345] pid:!/run/service.pid name:service.sh log:stdout \
|
||||||
|
reload:'/etc/init.d/S01-service.sh reload' \
|
||||||
|
stop:'/etc/init.d/S01-service.sh stop' \
|
||||||
|
/etc/init.d/S01-service.sh -- SysV test service"
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
#DEBUG=1
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
sep "Test done $(date)"
|
||||||
|
assert "Running test teardown." "run rm -f $FINIT_RCSD/service.conf"
|
||||||
|
}
|
||||||
|
|
||||||
say "Running test teardown."
|
test_one()
|
||||||
run "rm -f $FINIT_CONF"
|
{
|
||||||
|
say "Add sysv stanza #1 in $FINIT_CONF"
|
||||||
|
run "echo \"$1\" > $FINIT_RCSD/service.conf"
|
||||||
|
|
||||||
|
say "Reload Finit"
|
||||||
|
run "initctl reload"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 service.sh'
|
||||||
|
retry 'assert_cond service/service.sh/ready'
|
||||||
|
|
||||||
|
sep 'Stop the sysv service'
|
||||||
|
run "initctl stop service.sh"
|
||||||
|
|
||||||
|
retry 'assert_num_children 0 service.sh'
|
||||||
|
|
||||||
|
sep 'Start the sysv service again'
|
||||||
|
run "initctl start service.sh"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 service.sh'
|
||||||
|
retry 'assert_cond service/service.sh/ready'
|
||||||
|
|
||||||
|
sep 'Touch the sysv service'
|
||||||
|
run "initctl touch service.conf"
|
||||||
|
run "initctl reload"
|
||||||
|
#run "initctl cond dump"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 service.sh'
|
||||||
|
retry 'assert_cond service/service.sh/ready'
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
say "Test start $(date)"
|
sep "―― 1) Basic sysv daemon"
|
||||||
|
test_one "$STANZA1"
|
||||||
|
|
||||||
say "Add sysv stanza in $FINIT_CONF"
|
sep "―― 2) Custom reload/start script for sysv daemon"
|
||||||
run "echo 'sysv [2345] pid:!/run/service.pid name:service.sh /etc/init.d/S01-service.sh -- SysV test service' > $FINIT_CONF"
|
test_one "$STANZA2"
|
||||||
|
|
||||||
say 'Reload Finit'
|
|
||||||
run "initctl reload"
|
|
||||||
|
|
||||||
retry 'assert_num_children 1 service.sh'
|
|
||||||
|
|
||||||
say 'Stop the sysv service'
|
|
||||||
run "initctl stop service.sh"
|
|
||||||
|
|
||||||
retry 'assert_num_children 0 service.sh'
|
|
||||||
|
|
||||||
say 'Start the sysv service again'
|
|
||||||
run "initctl start service.sh"
|
|
||||||
|
|
||||||
retry 'assert_num_children 1 service.sh'
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -4,11 +4,6 @@ set -e
|
|||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|||||||
+5
-12
@@ -8,27 +8,20 @@
|
|||||||
# - SNNfoo should be called with a 'start' argument
|
# - SNNfoo should be called with a 'start' argument
|
||||||
# - KNNfoo should be called with a 'stop' argument
|
# - KNNfoo should be called with a 'stop' argument
|
||||||
#
|
#
|
||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
|
||||||
# shellcheck disable=2034
|
# shellcheck disable=2034
|
||||||
DEBUG=1
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
BOOTSTRAP="runparts sysv /etc/rcS.d"
|
BOOTSTRAP="runparts sysv /etc/rcS.d"
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
# shellcheck source=/dev/null
|
DEBUG=1
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
|
||||||
|
|
||||||
test_setup()
|
|
||||||
{
|
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
lvl=$(texec initctl runlevel)
|
lvl=$(texec initctl runlevel)
|
||||||
say "Current runlevel $lvl"
|
say "Current runlevel $lvl"
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ service log:stdout notify:s6 <service/B/ready> name:C serv -np -i C -N %n
|
|||||||
service log:stdout notify:none <pid/A> name:D type:forking serv -i D -- D needs A (forking)
|
service log:stdout notify:none <pid/A> name:D type:forking serv -i D -- D needs A (forking)
|
||||||
task <service/C/ready,service/D/ready> name:allup initctl cond set allup -- Everything is up
|
task <service/C/ready,service/D/ready> name:allup initctl cond set allup -- Everything is up
|
||||||
EOF
|
EOF
|
||||||
say "Test start $(date)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
|
|||||||
Reference in new issue
Block a user