mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
Follow-up to f4a0b99: track modifications of service env: files
Add support for monitoring environment files for services declared with the `env:[-]/path/to/file` option. The default path to such files has been chosen to follow Debian and Buildroot /etc/default/* Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
7ef25abecf
commit
74d3194775
4 files changed
+55
-7
No files matched your search
@@ -109,6 +109,10 @@ AC_ARG_WITH(rc-local,
|
|||||||
AS_HELP_STRING([--with-rc-local=FILE], [SysV init /etc/rc.local file, default /etc/rc.local]),
|
AS_HELP_STRING([--with-rc-local=FILE], [SysV init /etc/rc.local file, default /etc/rc.local]),
|
||||||
[rclocal=$withval], [rclocal=$sysconfdir/rc.local])
|
[rclocal=$withval], [rclocal=$sysconfdir/rc.local])
|
||||||
|
|
||||||
|
AC_ARG_WITH(sysconfig,
|
||||||
|
AS_HELP_STRING([--with-sysconfig=DIR], [Enviroment config directory, default /etc/default]),
|
||||||
|
[sysconfig=$withval], [sysconfig=yes])
|
||||||
|
|
||||||
AC_ARG_WITH(hostname,
|
AC_ARG_WITH(hostname,
|
||||||
AS_HELP_STRING([--with-hostname=NAME], [If /etc/hostname is missing, default: noname]),
|
AS_HELP_STRING([--with-hostname=NAME], [If /etc/hostname is missing, default: noname]),
|
||||||
[hostname=$withval], [hostname=noname])
|
[hostname=$withval], [hostname=noname])
|
||||||
@@ -165,6 +169,13 @@ AS_IF([test "x$with_rc_local" != "xno"], [
|
|||||||
AC_EXPAND_DIR(rclocal_path, "$rclocal")
|
AC_EXPAND_DIR(rclocal_path, "$rclocal")
|
||||||
AC_DEFINE_UNQUOTED(FINIT_RC_LOCAL, "$rclocal_path", [Compat SysV /etc/rc.local file to run last at boot.])
|
AC_DEFINE_UNQUOTED(FINIT_RC_LOCAL, "$rclocal_path", [Compat SysV /etc/rc.local file to run last at boot.])
|
||||||
|
|
||||||
|
AS_IF([test "x$with_sysconfig" != "xno"], [
|
||||||
|
AS_IF([test "x$sysconfig" = "xyes"], [
|
||||||
|
sysconfig=$sysconfdir/default
|
||||||
|
AC_EXPAND_DIR(sysconfig_path, "$sysconfig")
|
||||||
|
AC_DEFINE_UNQUOTED(FINIT_SYSCONFIG, "$sysconfig_path",
|
||||||
|
[System environment, default /etc/default])])])
|
||||||
|
|
||||||
AS_IF([test "x$with_heading" != "xno"], [
|
AS_IF([test "x$with_heading" != "xno"], [
|
||||||
AS_IF([test "x$heading" = "xyes"], [
|
AS_IF([test "x$heading" = "xyes"], [
|
||||||
heading="$PACKAGE_NAME v$PACKAGE_VERSION"])])
|
heading="$PACKAGE_NAME v$PACKAGE_VERSION"])])
|
||||||
@@ -221,6 +232,7 @@ cat <<EOF
|
|||||||
Finit config.d path...: $rcsd_path
|
Finit config.d path...: $rcsd_path
|
||||||
Finit plugin path.....: $plugin_path
|
Finit plugin path.....: $plugin_path
|
||||||
Compat rc.local path..: $rclocal_path
|
Compat rc.local path..: $rclocal_path
|
||||||
|
System environment....: $sysconfig_path
|
||||||
Random seed path......: $random_path
|
Random seed path......: $random_path
|
||||||
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
|
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
|
||||||
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
|
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
|
||||||
|
|||||||
@@ -68,6 +68,34 @@ document [Finit Services](service.md).
|
|||||||
> examples in the `contrib/` directory, which can be used as a base.
|
> examples in the `contrib/` directory, which can be used as a base.
|
||||||
|
|
||||||
|
|
||||||
|
Service Environment
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Finit supports sourcing environment variables from `/etc/default/*`, or
|
||||||
|
similar `--with-sysconfig=DIR`. This is a common pattern from SysV init
|
||||||
|
scripts, where the start-stop script is a generic script for the given
|
||||||
|
service, `foo`, and the options for the service are sourced from the
|
||||||
|
file `/etc/default/foo`. Like this:
|
||||||
|
|
||||||
|
* `/etc/default/foo`:
|
||||||
|
|
||||||
|
FOO_OPTIONS=--extra-arg="bar" -s -x
|
||||||
|
|
||||||
|
* `/etc/finit.conf`:
|
||||||
|
|
||||||
|
service [2345] env:-/etc/default/foo foo -n $FOO_OPTIONS -- Example foo daemon
|
||||||
|
|
||||||
|
Here the service `foo` is started with `-n`, to make sure it runs in the
|
||||||
|
foreground, and the with the options found in the environment file. With
|
||||||
|
the `ps` command we can see that the process is started with:
|
||||||
|
|
||||||
|
foo -n --extra-arg=bar -s -x
|
||||||
|
|
||||||
|
> **Note:** the leading `-` determines if Finit should treat a missing
|
||||||
|
> environment file as blocking the start of the service or not. When
|
||||||
|
> `-` is used, a missing environment file does *not* block the start.
|
||||||
|
|
||||||
|
|
||||||
Service Wrapper Scripts
|
Service Wrapper Scripts
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|||||||
+14
-6
@@ -772,13 +772,13 @@ static void drop_changes(void)
|
|||||||
|
|
||||||
static int do_change(char *dir, char *name, uint32_t mask)
|
static int do_change(char *dir, char *name, uint32_t mask)
|
||||||
{
|
{
|
||||||
char path[strlen(dir) + strlen(name) + 2];
|
char fn[strlen(dir) + strlen(name) + 2];
|
||||||
struct conf_change *node;
|
struct conf_change *node;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s%s", dir, name);
|
snprintf(fn, sizeof(fn), "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
||||||
_d("path: %s", path);
|
_d("path: %s mask: %08x", fn, mask);
|
||||||
|
|
||||||
node = conf_find(path);
|
node = conf_find(fn);
|
||||||
if (mask & (IN_DELETE | IN_MOVED_FROM)) {
|
if (mask & (IN_DELETE | IN_MOVED_FROM)) {
|
||||||
drop_change(node);
|
drop_change(node);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -793,13 +793,13 @@ static int do_change(char *dir, char *name, uint32_t mask)
|
|||||||
if (!node)
|
if (!node)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
node->name = strdup(path);
|
node->name = strdup(fn);
|
||||||
if (!node->name) {
|
if (!node->name) {
|
||||||
free(node);
|
free(node);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_d("Event registered for %s, mask 0x%x", path, mask);
|
_d("Event registered for %s, mask 0x%x", fn, mask);
|
||||||
TAILQ_INSERT_HEAD(&conf_change_list, node, link);
|
TAILQ_INSERT_HEAD(&conf_change_list, node, link);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -881,6 +881,14 @@ int conf_monitor(void)
|
|||||||
rc += iwatch_add(&iw_conf, FINIT_RCSD "/enabled/", IN_ONLYDIR | IN_DONT_FOLLOW);
|
rc += iwatch_add(&iw_conf, FINIT_RCSD "/enabled/", IN_ONLYDIR | IN_DONT_FOLLOW);
|
||||||
rc += iwatch_add(&iw_conf, FINIT_CONF, 0);
|
rc += iwatch_add(&iw_conf, FINIT_CONF, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Systems with /etc/default, or similar, can also monitor changes
|
||||||
|
* in env files sourced by .conf files (above)
|
||||||
|
*/
|
||||||
|
#ifdef FINIT_SYSCONFIG
|
||||||
|
rc += iwatch_add(&iw_conf, FINIT_SYSCONFIG, IN_ONLYDIR);
|
||||||
|
#endif
|
||||||
|
|
||||||
return rc + conf_reload();
|
return rc + conf_reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1116,7 +1116,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
|
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
|
||||||
|
|
||||||
/* New, recently modified or unchanged ... used on reload. */
|
/* New, recently modified or unchanged ... used on reload. */
|
||||||
if (file && conf_changed(file))
|
if ((file && conf_changed(file)) || conf_changed(svc_getenv(svc)))
|
||||||
svc_mark_dirty(svc);
|
svc_mark_dirty(svc);
|
||||||
else
|
else
|
||||||
svc_mark_clean(svc);
|
svc_mark_clean(svc);
|
||||||
|
|||||||
Reference in new issue
Block a user