mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
test: new test to verify support for forking services
Issue #223 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
6416e2a1a4
commit
6baf2990e8
5 files changed
+111
No files matched your search
@@ -29,6 +29,7 @@ TESTS += start-stop-service.sh
|
|||||||
TESTS += start-stop-service-sub-config.sh
|
TESTS += start-stop-service-sub-config.sh
|
||||||
TESTS += start-kill-service.sh
|
TESTS += start-kill-service.sh
|
||||||
TESTS += start-stop-sysv.sh
|
TESTS += start-stop-sysv.sh
|
||||||
|
TESTS += start-stop-fserv.sh
|
||||||
TESTS += signal-service.sh
|
TESTS += signal-service.sh
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
/Makefile
|
/Makefile
|
||||||
/Makefile.in
|
/Makefile.in
|
||||||
|
|
||||||
|
/.deps/
|
||||||
|
/fserv
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
EXTRA_DIST = service.conf service.sh S01-service.sh slay.sh
|
EXTRA_DIST = service.conf service.sh S01-service.sh slay.sh
|
||||||
|
|
||||||
|
noinst_PROGRAMS = fserv
|
||||||
|
fserv_SOURCES = fserv.c
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/* Basic forking UNIX daemon with no options to run in foreground */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static void sig(int signo)
|
||||||
|
{
|
||||||
|
warnx("We got signal %d ...", signo);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pidfile(char *nm)
|
||||||
|
{
|
||||||
|
char fn[80];
|
||||||
|
pid_t pid;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
if (!nm)
|
||||||
|
nm = "fserv";
|
||||||
|
|
||||||
|
snprintf(fn, sizeof(fn), "%s%s.pid", _PATH_VARRUN, nm);
|
||||||
|
pid = getpid();
|
||||||
|
warnx("Creating PID file %s with %d", fn, pid);
|
||||||
|
|
||||||
|
fp = fopen(fn, "w");
|
||||||
|
if (!fp)
|
||||||
|
exit(1);
|
||||||
|
fprintf(fp, "%d\n", pid);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/* Daemonize, fork to background etc. */
|
||||||
|
if (daemon(0, 1))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* Signal handlers first *then* PID file */
|
||||||
|
signal(SIGTERM, sig);
|
||||||
|
|
||||||
|
/* Tell finit where we really are */
|
||||||
|
pidfile(NULL);
|
||||||
|
|
||||||
|
warnx("Entering while(1) loop");
|
||||||
|
while (1)
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
warnx("Leaving ...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Executable
+50
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/tenv/lib.sh"
|
||||||
|
|
||||||
|
test_teardown()
|
||||||
|
{
|
||||||
|
say "Test done $(date)"
|
||||||
|
say "Running test teardown."
|
||||||
|
|
||||||
|
texec rm -f "$FINIT_CONF"
|
||||||
|
texec rm -f /test_assets/fserv
|
||||||
|
}
|
||||||
|
|
||||||
|
say "Test start $(date)"
|
||||||
|
|
||||||
|
cp "$TEST_DIR"/common/fserv "$TENV_ROOT"/test_assets/
|
||||||
|
|
||||||
|
say "Add service stanza in $FINIT_CONF"
|
||||||
|
texec sh -c "echo 'service [2345] pid:!/run/fserv.pid /test_assets/fserv -- Forking service' > $FINIT_CONF"
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
#texec sh -c "initctl debug"
|
||||||
|
texec sh -c "initctl reload"
|
||||||
|
#texec sh -c "initctl status"
|
||||||
|
#texec sh -c "ps"
|
||||||
|
|
||||||
|
# Wait for process to fork, create its PID file so Finit can register
|
||||||
|
# its new PID -- this is the major difference from regular services.
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
#texec sh -c "initctl status"
|
||||||
|
#texec sh -c "ps"
|
||||||
|
#texec sh -c "initctl status fserv"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 fserv'
|
||||||
|
|
||||||
|
say 'Stop the service'
|
||||||
|
texec sh -c "initctl stop fserv"
|
||||||
|
|
||||||
|
retry 'assert_num_children 0 fserv'
|
||||||
|
|
||||||
|
say 'Start the service again'
|
||||||
|
texec sh -c "initctl start fserv"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 fserv'
|
||||||
Reference in new issue
Block a user