mirror of
https://github.com/troglobit/finit.git
synced 2026-10-20 11:19:35 +00:00
Support delayed load of services from plugins and bundled services
This adds a new function conf_save_service() replacing service_register() for plugins and bundled services like watchdogd, keventd, runparts, etc. The benefits to this change are several: - Plugin/Bundled services no longer risk starting before udev or other critical services/task have started - Definitions can be overridden by an administrator (see docs) - Increases visibility (user: where are all these services coming from?) Previously the origin (file the service was loaded from) was NULL. - Adds another level of extensibility to Finit The most notable change is that dbus is no longer started before udevd. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
eaaf8d862e
commit
5d703fd39e
6 files changed
+61
-14
No files matched your search
+2
-1
@@ -298,6 +298,7 @@ pkglibdir=$libdir/finit
|
|||||||
AC_SUBST(pkglibexecdir)
|
AC_SUBST(pkglibexecdir)
|
||||||
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
||||||
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
|
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
|
||||||
|
AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "/run/finit/system", [Finit runtime dynamic system services])
|
||||||
|
|
||||||
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
|
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
|
||||||
AC_SUBST(plugin_path)
|
AC_SUBST(plugin_path)
|
||||||
@@ -313,7 +314,7 @@ AC_DEFINE_UNQUOTED(FINIT_TMPFILES, "$finit_tmpfiles", [Finit tmpfiles.d/ .conf p
|
|||||||
|
|
||||||
AC_EXPAND_DIR(system_path, "$pkglibdir/system")
|
AC_EXPAND_DIR(system_path, "$pkglibdir/system")
|
||||||
AC_SUBST(system_path)
|
AC_SUBST(system_path)
|
||||||
AC_DEFINE_UNQUOTED(FINIT_SYSPATH, "$system_path", [Static services, previously generated at runtime by plugins])
|
AC_DEFINE_UNQUOTED(FINIT_SYSPATH_, "$system_path", [Static services, previously generated at runtime by plugins])
|
||||||
|
|
||||||
AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf")
|
AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf")
|
||||||
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
||||||
|
|||||||
+17
-2
@@ -68,10 +68,18 @@ the following layout is recommended:
|
|||||||
| : `- another-static.conf
|
| : `- another-static.conf
|
||||||
| :
|
| :
|
||||||
| `- finit.conf
|
| `- finit.conf
|
||||||
`- lib/
|
|- lib
|
||||||
|
| `- finit/
|
||||||
|
| `- system/
|
||||||
|
| |- 10-hotplug.conf
|
||||||
|
| `- ...
|
||||||
|
`- run/
|
||||||
`- finit/
|
`- finit/
|
||||||
`- system/
|
`- system/
|
||||||
|- 10-hotplug.conf
|
|- dbus.conf
|
||||||
|
|- keventd.conf
|
||||||
|
|- runparts.conf
|
||||||
|
|- watchdogd.conf
|
||||||
`- ...
|
`- ...
|
||||||
|
|
||||||
Configuration files in `/etc` are provided by the user, or projects like
|
Configuration files in `/etc` are provided by the user, or projects like
|
||||||
@@ -85,6 +93,11 @@ the hard-coded services provided by plugins before. All .conf files in this
|
|||||||
directory be either replaced by a system administrator or overridden by a
|
directory be either replaced by a system administrator or overridden by a
|
||||||
file with the same name in `/etc/finit.d/`.
|
file with the same name in `/etc/finit.d/`.
|
||||||
|
|
||||||
|
The files in `/run/finit/system/*.conf` are created by plugins and Finit
|
||||||
|
bundled services like runparts, the [watchdog](#watchdog), and `keventd`
|
||||||
|
if they are enabled. Like `/lib/finit/system/*.conf`, these files can
|
||||||
|
be overridden by file with the same name in `/etc/finit.d/`.
|
||||||
|
|
||||||
Services in the `available/` and `enabled/` sub-directories are called
|
Services in the `available/` and `enabled/` sub-directories are called
|
||||||
dynamic services, in contrast to static services -- the only difference
|
dynamic services, in contrast to static services -- the only difference
|
||||||
being where they are installed and if the `initctl` tool can manage them
|
being where they are installed and if the `initctl` tool can manage them
|
||||||
@@ -100,6 +113,8 @@ unique group, where files within each group are sorted alphabetically.
|
|||||||
|
|
||||||
/lib/finit/system/10-hotplug.conf
|
/lib/finit/system/10-hotplug.conf
|
||||||
/lib/finit/system/90-testserv.conf
|
/lib/finit/system/90-testserv.conf
|
||||||
|
/run/finit/system/dbus.conf
|
||||||
|
/run/finit/system/runparts.conf
|
||||||
/etc/finit.d/10-abc.conf
|
/etc/finit.d/10-abc.conf
|
||||||
/etc/finit.d/20-abc.conf
|
/etc/finit.d/20-abc.conf
|
||||||
/etc/finit.d/enabled/1-aaa.conf
|
/etc/finit.d/enabled/1-aaa.conf
|
||||||
|
|||||||
+1
-3
@@ -157,9 +157,7 @@ static void setup(void *arg)
|
|||||||
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s",
|
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s",
|
||||||
cmd, DBUS_ARGS, DBUS_DESC);
|
cmd, DBUS_ARGS, DBUS_DESC);
|
||||||
|
|
||||||
if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL))
|
conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf");
|
||||||
err(1, "Failed registering %s", DBUS_DAEMON);
|
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+39
-7
@@ -462,6 +462,30 @@ void conf_save_exec_order(svc_t *svc, char *cmdline, int result)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called by plugins and similar that dynamically generate system services
|
||||||
|
*/
|
||||||
|
void conf_save_service(int type, char *cfg, char *file)
|
||||||
|
{
|
||||||
|
char fn[256];
|
||||||
|
svc_t foo;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
snprintf(fn, sizeof(fn), "%s/%s", FINIT_RUNPATH_, file);
|
||||||
|
if (fexist(fn))
|
||||||
|
warn("File %s already exists, overwriting.", fn);
|
||||||
|
fp = fopen(fn, "w");
|
||||||
|
if (!fp) {
|
||||||
|
err(1, "Failed creating %s", fn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foo.type = type;
|
||||||
|
fprintf(fp, "# Generated by finit:%s()\n", __func__);
|
||||||
|
fprintf(fp, "%s %s\n", svc_typestr(&foo), cfg);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
||||||
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
||||||
@@ -1207,13 +1231,16 @@ int conf_reload(void)
|
|||||||
*
|
*
|
||||||
* /lib/finit/system/10-hotplug.conf
|
* /lib/finit/system/10-hotplug.conf
|
||||||
* /lib/finit/system/90-testserv.conf
|
* /lib/finit/system/90-testserv.conf
|
||||||
|
* /run/finit/system/dbus.conf
|
||||||
|
* /run/finit/system/tty.conf
|
||||||
* /etc/finit.d/10-abc.conf
|
* /etc/finit.d/10-abc.conf
|
||||||
* /etc/finit.d/20-abc.conf
|
* /etc/finit.d/20-abc.conf
|
||||||
* /etc/finit.d/enabled/1-aaa.conf
|
* /etc/finit.d/enabled/1-aaa.conf
|
||||||
* /etc/finit.d/enabled/1-abc.conf
|
* /etc/finit.d/enabled/1-abc.conf
|
||||||
* /etc/finit.d/enabled/2-aaa.conf
|
* /etc/finit.d/enabled/2-aaa.conf
|
||||||
*/
|
*/
|
||||||
glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH);
|
glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH_);
|
||||||
|
glob_append(&gl, 1, "%s/*.conf", FINIT_RUNPATH_);
|
||||||
glob_append(&gl, 1, "%s/*.conf", finit_rcsd);
|
glob_append(&gl, 1, "%s/*.conf", finit_rcsd);
|
||||||
glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd);
|
glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd);
|
||||||
|
|
||||||
@@ -1238,9 +1265,10 @@ int conf_reload(void)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
size_t j, len;
|
size_t j, len;
|
||||||
|
|
||||||
/* check for FINIT_SYSPATH overrides */
|
/* check for FINIT_SYSPATH_ or FINIT_RUNPATH_ overrides */
|
||||||
for (j = i + 1; j < gl.gl_pathc; j++) {
|
for (j = i + 1; j < gl.gl_pathc; j++) {
|
||||||
if (strncmp(path, FINIT_SYSPATH, strlen(FINIT_SYSPATH)))
|
if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) &&
|
||||||
|
strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_)))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(basename(path), basename(gl.gl_pathv[j])))
|
if (strcmp(basename(path), basename(gl.gl_pathv[j])))
|
||||||
continue;
|
continue;
|
||||||
@@ -1300,6 +1328,9 @@ done:
|
|||||||
/* Drop record of all .conf changes */
|
/* Drop record of all .conf changes */
|
||||||
drop_changes();
|
drop_changes();
|
||||||
|
|
||||||
|
if (bootstrap)
|
||||||
|
wdog = svc_find("watchdog", "finit");
|
||||||
|
|
||||||
/* Override configured runlevel, user said 'S' on /proc/cmdline */
|
/* Override configured runlevel, user said 'S' on /proc/cmdline */
|
||||||
if (BOOTSTRAP && single)
|
if (BOOTSTRAP && single)
|
||||||
cfglevel = 1;
|
cfglevel = 1;
|
||||||
@@ -1536,15 +1567,16 @@ int conf_init(uev_ctx_t *ctx)
|
|||||||
*/
|
*/
|
||||||
#ifdef WDT_DEVNODE
|
#ifdef WDT_DEVNODE
|
||||||
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
|
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
|
||||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", global_rlimit, NULL);
|
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit "
|
||||||
wdog = svc_find("watchdog", "finit");
|
FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* Start kernel event daemon as soon as possible, if enabled
|
* Start kernel event daemon as soon as possible, if enabled
|
||||||
*/
|
*/
|
||||||
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
||||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", global_rlimit, NULL);
|
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init "
|
||||||
|
FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf");
|
||||||
|
|
||||||
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
||||||
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
||||||
@@ -1580,7 +1612,7 @@ int conf_init(uev_ctx_t *ctx)
|
|||||||
snprintf(conf, sizeof(conf), "[S] <int/bootstrap> log:console %s %s %s"
|
snprintf(conf, sizeof(conf), "[S] <int/bootstrap> log:console %s %s %s"
|
||||||
" -- Calling runparts %s in the background",
|
" -- Calling runparts %s in the background",
|
||||||
_PATH_RUNPARTS, args, runparts, runparts);
|
_PATH_RUNPARTS, args, runparts, runparts);
|
||||||
service_register(SVC_TYPE_TASK, conf, global_rlimit, NULL);
|
conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ int conf_monitor (void);
|
|||||||
void conf_reset_env (void);
|
void conf_reset_env (void);
|
||||||
void conf_saverc (void);
|
void conf_saverc (void);
|
||||||
void conf_save_exec_order (svc_t *svc, char *cmdline, int result);
|
void conf_save_exec_order (svc_t *svc, char *cmdline, int result);
|
||||||
|
void conf_save_service (int type, char *cfg, char *file);
|
||||||
void conf_parse_cmdline (int argc, char *argv[]);
|
void conf_parse_cmdline (int argc, char *argv[]);
|
||||||
int conf_parse_runlevels (char *runlevels);
|
int conf_parse_runlevels (char *runlevels);
|
||||||
void conf_parse_cond (svc_t *svc, char *cond);
|
void conf_parse_cond (svc_t *svc, char *cond);
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ d /run/finit/cond 0755 - - -
|
|||||||
d /run/finit/cond/pid 0755 - - -
|
d /run/finit/cond/pid 0755 - - -
|
||||||
d /run/finit/cond/sys 0755 - - -
|
d /run/finit/cond/sys 0755 - - -
|
||||||
d /run/finit/cond/usr 0755 - - -
|
d /run/finit/cond/usr 0755 - - -
|
||||||
|
d /run/finit/system 0755 - - -
|
||||||
Reference in new issue
Block a user