Westermo service starter and supervisor, inspired by daemontools

finit.c:
        o New service and shell_service stanzas for finit.conf
        o Run service_startup() before /etc/finit.d/ hooks
        o Run service_monitor() at end of startup

helpers.c:
        o Several new functions:
          - print_desc() displays a service starting up
          - print_result() shows if service started OK or not
          - start_process() is used by the services framework

svc.c:
        Generic API for managing svc_t structures

ipc.o:
        TIPC based framework for communicating with the service monitor.
        E.g., to relay (re)configuration signals from a Web/CLI
        front-end via finit to one or many setup daemons, and back.

services.c:
        Service monitor framework

strlcpy.c:
        Secure strncpy() replacement from OpenBSD under the free ISC License.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2012-09-20 01:16:00 +02:00
1 parent c0356b5c7a
commit d21dc2b477
14 files changed
+1352 -28

No files matched your search

+23 -17
View File
@@ -31,6 +31,7 @@
#include "finit.h"
#include "helpers.h"
#include "service.h"
int debug = 0;
char *sdown = NULL;
@@ -49,7 +50,7 @@ static char *build_cmd(char *cmd, char *line, int len)
if (!cmd) {
cmd = malloc (strlen(line) + 1);
if (!cmd) {
fprintf (stderr, "finit: No memory left for '%s'", line);
_e("No memory left for '%s'", line);
return NULL;
}
*cmd = 0;
@@ -130,7 +131,7 @@ int main(int UNUSED(args), char *argv[])
}
cls();
_d("finit " VERSION " (built " __DATE__ " " __TIME__ " by " WHOAMI ")");
echo("finit " VERSION " (built " __DATE__ " " __TIME__ " by " WHOAMI ")");
/*
* Parse configuration file
@@ -194,6 +195,11 @@ int main(int UNUSED(args), char *argv[])
startx = build_cmd(NULL, x, CMD_SIZE);
continue;
}
if (MATCH_CMD(line, "service ", x)) {
if (service_register (x))
_e("Failed, too many services to monitor.\n");
continue;
}
}
fclose(fp);
}
@@ -283,6 +289,8 @@ int main(int UNUSED(args), char *argv[])
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
touch("/etc/network/run/ifstate");
#else
remove("/etc/network/run/ifstate");
#endif
/* Set initial hostname. */
@@ -325,8 +333,20 @@ int main(int UNUSED(args), char *argv[])
*/
mkdir("/tmp/.X11-unix", 01777);
mkdir("/tmp/.ICE-unix", 01777);
mkdir("/var/run/sshd", 01755);
umask(022);
#ifdef USE_MESSAGE_BUS
_d("Starting D-Bus ...");
mkdir("/var/run/dbus", 0755);
mkdir("/var/lock/subsys/messagebus", 0755);
system("dbus-uuidgen --ensure");
system("su -c \"dbus-daemon --system\" messagebus");
#endif
_d("Starting services from %s", FINIT_CONF);
service_startup();
#ifdef LISTEN_INITCTL
listen_initctl();
#endif
@@ -366,14 +386,6 @@ int main(int UNUSED(args), char *argv[])
/* ConsoleKit needs this */
setenv("DISPLAY", ":0", 1);
#ifdef USE_MESSAGE_BUS
_d("Starting D-Bus ...");
mkdir("/var/run/dbus", 0755);
mkdir("/var/lock/subsys/messagebus", 0755);
system("dbus-uuidgen --ensure");
system("su -c \"dbus-daemon --system\" messagebus");
#endif
/* Run startup scripts in /etc/finit.d/, if any. */
run_parts(FINIT_RCSD);
@@ -403,13 +415,7 @@ int main(int UNUSED(args), char *argv[])
exit(0);
}
/* We're the grim reaper of innocent orphaned children ... */
while (1) {
sigset_t nmask;
sigemptyset(&nmask);
pselect(0, NULL, NULL, NULL, NULL, &nmask);
}
service_monitor();
return 0;
}