supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* [PATCH] svlogd: implement option to use alternate config file
@ 2019-07-31 18:00 Patrick Steinhardt
  2019-07-31 19:12 ` Kevin Berry
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Steinhardt @ 2019-07-31 18:00 UTC (permalink / raw)
  To: supervision; +Cc: Patrick Steinhardt

Right now, the svlogd daemon will always look up the log configuration
in the target log directory itself. There's reasons though for having
the configuration file located at a different place, e.g. to provide a
global log configuration or to separate data from configuration.

Introduce a new command line option, "-c", that takes as parameter an
alternative log file. It can either be given a relative path, in which
case svlogd will try to open it relative to the log directories, or an
absolute path, where it will try to use a single configuration for each
of the log directories.

Add tests to verify that svlogd is correctly reading the alternative
configuration file.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---

Hi,

I don't quite know whether this is the right place to send
patches to, but runit's homepage didn't mention any way to
contribute patches (or I didn't find it). Please feel free to
redirect me if I've chosen the wrong place.

Regards
Patrick

 man/svlogd.8     | 15 ++++++++++++++-
 src/svlogd.c     | 11 ++++++++---
 src/svlogd.check | 10 ++++++++++
 src/svlogd.dist  |  5 +++++
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/man/svlogd.8 b/man/svlogd.8
index 01b2324..5359d94 100644
--- a/man/svlogd.8
+++ b/man/svlogd.8
@@ -3,7 +3,8 @@
 svlogd \- runit's service logging daemon
 .SH SYNOPSIS
 .B svlogd
-[\-tttv] [\-r
+[\-tttv] [\-c
+.I file\fR] [\-r
 .I c\fR] [\-R
 .I xyz\fR] [\-l
 .I len\fR] [\-b
@@ -377,6 +378,18 @@ the form YYYY-MM-DDTHH:MM:SS.xxxxx when writing to
 .I log
 or to standard error.
 .TP
+.B \-c \fIfile
+config file.
+Use
+.I file
+as configuration instead of the default
+.I log/config
+path.
+.I file
+may either be absolute or relative, in which case it will be relative to the
+.I log
+directory.
+.TP
 .B \-r \fIc
 replace.
 .I c
diff --git a/src/svlogd.c b/src/svlogd.c
index 90a3321..0109684 100644
--- a/src/svlogd.c
+++ b/src/svlogd.c
@@ -49,6 +49,7 @@ unsigned long linemax =1000;
 unsigned long buflen =1024;
 unsigned long linelen;
 
+const char *config = "config";
 const char *replace ="";
 char repl =0;
 
@@ -437,13 +438,14 @@ unsigned int logdir_open(struct logdir *ld, const char *fn) {
   while (! stralloc_copys(&ld->processor, "")) pause_nomem();
 
   /* read config */
-  if ((i =openreadclose("config", &sa, 128)) == -1)
+  if ((i =openreadclose(config, &sa, 128)) == -1)
     warn2("unable to read config", ld->name);
   if (i != 0) {
     int len, c;
     unsigned long port;
 
-    if (verbose) strerr_warn4(INFO, "read: ", ld->name, "/config", 0);
+    if (verbose && *config != '/') strerr_warn5(INFO, "read: ", ld->name, "/", config, 0);
+    else if (verbose) strerr_warn3(INFO, "read: ", config, 0);
     for (i =0; i +1 < sa.len; ++i) {
       len =byte_chr(&sa.s[i], sa.len -i, '\n');
       sa.s[len +i] =0;
@@ -667,8 +669,11 @@ int main(int argc, const char **argv) {
 
   progname =*argv;
 
-  while ((opt =getopt(argc, argv, "R:r:l:b:tvV")) != opteof) {
+  while ((opt =getopt(argc, argv, "c:R:r:l:b:tvV")) != opteof) {
     switch(opt) {
+    case 'c':
+      config =optarg;
+      break;
     case 'R':
       replace =optarg;
       if (! repl) repl ='_';
diff --git a/src/svlogd.check b/src/svlogd.check
index 7d926ef..e9584ee 100755
--- a/src/svlogd.check
+++ b/src/svlogd.check
@@ -24,4 +24,14 @@ echo t2 >"${ctmp}"/config
 echo $?
 cat "${ctmp}"/current
 
+echo prelative-alternate >"${ctmp}"/alternate-config
+echo foo |svlogd -c alternate-config "${ctmp}"
+echo $?
+cat "${ctmp}"/current
+
+echo pabsolute-alternate >>"${ctmp}"/alternate-config
+echo foo |svlogd -c "${ctmp}"/alternate-config "${ctmp}"
+echo $?
+cat "${ctmp}"/current
+
 rm -rf "${ctmp}"
diff --git a/src/svlogd.dist b/src/svlogd.dist
index b3329e6..8570230 100644
--- a/src/svlogd.dist
+++ b/src/svlogd.dist
@@ -19,3 +19,8 @@ baz
 :ar
 :az
 0
+0
+relative-alternatefoo
+0
+relative-alternatefoo
+absolute-alternatefoo
-- 
2.22.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] svlogd: implement option to use alternate config file
  2019-07-31 18:00 [PATCH] svlogd: implement option to use alternate config file Patrick Steinhardt
@ 2019-07-31 19:12 ` Kevin Berry
  2019-07-31 19:25   ` Patrick Steinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Berry @ 2019-07-31 19:12 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: supervision

[-- Attachment #1: Type: text/plain, Size: 4381 bytes --]

I always used symlinks for common configuration of svlogd, but I guess this
could be a useful feature.

On Wed, Jul 31, 2019 at 1:27 PM Patrick Steinhardt <ps@pks.im> wrote:

> Right now, the svlogd daemon will always look up the log configuration
> in the target log directory itself. There's reasons though for having
> the configuration file located at a different place, e.g. to provide a
> global log configuration or to separate data from configuration.
>
> Introduce a new command line option, "-c", that takes as parameter an
> alternative log file. It can either be given a relative path, in which
> case svlogd will try to open it relative to the log directories, or an
> absolute path, where it will try to use a single configuration for each
> of the log directories.
>
> Add tests to verify that svlogd is correctly reading the alternative
> configuration file.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>
> Hi,
>
> I don't quite know whether this is the right place to send
> patches to, but runit's homepage didn't mention any way to
> contribute patches (or I didn't find it). Please feel free to
> redirect me if I've chosen the wrong place.
>
> Regards
> Patrick
>
>  man/svlogd.8     | 15 ++++++++++++++-
>  src/svlogd.c     | 11 ++++++++---
>  src/svlogd.check | 10 ++++++++++
>  src/svlogd.dist  |  5 +++++
>  4 files changed, 37 insertions(+), 4 deletions(-)
>
> diff --git a/man/svlogd.8 b/man/svlogd.8
> index 01b2324..5359d94 100644
> --- a/man/svlogd.8
> +++ b/man/svlogd.8
> @@ -3,7 +3,8 @@
>  svlogd \- runit's service logging daemon
>  .SH SYNOPSIS
>  .B svlogd
> -[\-tttv] [\-r
> +[\-tttv] [\-c
> +.I file\fR] [\-r
>  .I c\fR] [\-R
>  .I xyz\fR] [\-l
>  .I len\fR] [\-b
> @@ -377,6 +378,18 @@ the form YYYY-MM-DDTHH:MM:SS.xxxxx when writing to
>  .I log
>  or to standard error.
>  .TP
> +.B \-c \fIfile
> +config file.
> +Use
> +.I file
> +as configuration instead of the default
> +.I log/config
> +path.
> +.I file
> +may either be absolute or relative, in which case it will be relative to
> the
> +.I log
> +directory.
> +.TP
>  .B \-r \fIc
>  replace.
>  .I c
> diff --git a/src/svlogd.c b/src/svlogd.c
> index 90a3321..0109684 100644
> --- a/src/svlogd.c
> +++ b/src/svlogd.c
> @@ -49,6 +49,7 @@ unsigned long linemax =1000;
>  unsigned long buflen =1024;
>  unsigned long linelen;
>
> +const char *config = "config";
>  const char *replace ="";
>  char repl =0;
>
> @@ -437,13 +438,14 @@ unsigned int logdir_open(struct logdir *ld, const
> char *fn) {
>    while (! stralloc_copys(&ld->processor, "")) pause_nomem();
>
>    /* read config */
> -  if ((i =openreadclose("config", &sa, 128)) == -1)
> +  if ((i =openreadclose(config, &sa, 128)) == -1)
>      warn2("unable to read config", ld->name);
>    if (i != 0) {
>      int len, c;
>      unsigned long port;
>
> -    if (verbose) strerr_warn4(INFO, "read: ", ld->name, "/config", 0);
> +    if (verbose && *config != '/') strerr_warn5(INFO, "read: ", ld->name,
> "/", config, 0);
> +    else if (verbose) strerr_warn3(INFO, "read: ", config, 0);
>      for (i =0; i +1 < sa.len; ++i) {
>        len =byte_chr(&sa.s[i], sa.len -i, '\n');
>        sa.s[len +i] =0;
> @@ -667,8 +669,11 @@ int main(int argc, const char **argv) {
>
>    progname =*argv;
>
> -  while ((opt =getopt(argc, argv, "R:r:l:b:tvV")) != opteof) {
> +  while ((opt =getopt(argc, argv, "c:R:r:l:b:tvV")) != opteof) {
>      switch(opt) {
> +    case 'c':
> +      config =optarg;
> +      break;
>      case 'R':
>        replace =optarg;
>        if (! repl) repl ='_';
> diff --git a/src/svlogd.check b/src/svlogd.check
> index 7d926ef..e9584ee 100755
> --- a/src/svlogd.check
> +++ b/src/svlogd.check
> @@ -24,4 +24,14 @@ echo t2 >"${ctmp}"/config
>  echo $?
>  cat "${ctmp}"/current
>
> +echo prelative-alternate >"${ctmp}"/alternate-config
> +echo foo |svlogd -c alternate-config "${ctmp}"
> +echo $?
> +cat "${ctmp}"/current
> +
> +echo pabsolute-alternate >>"${ctmp}"/alternate-config
> +echo foo |svlogd -c "${ctmp}"/alternate-config "${ctmp}"
> +echo $?
> +cat "${ctmp}"/current
> +
>  rm -rf "${ctmp}"
> diff --git a/src/svlogd.dist b/src/svlogd.dist
> index b3329e6..8570230 100644
> --- a/src/svlogd.dist
> +++ b/src/svlogd.dist
> @@ -19,3 +19,8 @@ baz
>  :ar
>  :az
>  0
> +0
> +relative-alternatefoo
> +0
> +relative-alternatefoo
> +absolute-alternatefoo
> --
> 2.22.0
>
>

-- 
Kevin Berry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] svlogd: implement option to use alternate config file
  2019-07-31 19:12 ` Kevin Berry
@ 2019-07-31 19:25   ` Patrick Steinhardt
  2019-08-01  6:43     ` Jan Braun
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Steinhardt @ 2019-07-31 19:25 UTC (permalink / raw)
  To: Kevin Berry; +Cc: supervision

[-- Attachment #1: Type: text/plain, Size: 5311 bytes --]

On Wed, Jul 31, 2019 at 02:12:59PM -0500, Kevin Berry wrote:
> I always used symlinks for common configuration of svlogd, but I guess this
> could be a useful feature.

Yeah, I thought about using a symlink here, too. The main reason
why I didn't want to do this is to keep configuration and data
separate from each other. It honestly feels a bit weird to me to
configure the logger in /var/log/$service -- doing so in
/etc/sv/$service/log seems like the more obvious location to me
and can be cleanly achieved with this new option without
requiring a symlink.

> 
> On Wed, Jul 31, 2019 at 1:27 PM Patrick Steinhardt <ps@pks.im> wrote:
> 
> > Right now, the svlogd daemon will always look up the log configuration
> > in the target log directory itself. There's reasons though for having
> > the configuration file located at a different place, e.g. to provide a
> > global log configuration or to separate data from configuration.
> >
> > Introduce a new command line option, "-c", that takes as parameter an
> > alternative log file. It can either be given a relative path, in which
> > case svlogd will try to open it relative to the log directories, or an
> > absolute path, where it will try to use a single configuration for each
> > of the log directories.
> >
> > Add tests to verify that svlogd is correctly reading the alternative
> > configuration file.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> >
> > Hi,
> >
> > I don't quite know whether this is the right place to send
> > patches to, but runit's homepage didn't mention any way to
> > contribute patches (or I didn't find it). Please feel free to
> > redirect me if I've chosen the wrong place.
> >
> > Regards
> > Patrick
> >
> >  man/svlogd.8     | 15 ++++++++++++++-
> >  src/svlogd.c     | 11 ++++++++---
> >  src/svlogd.check | 10 ++++++++++
> >  src/svlogd.dist  |  5 +++++
> >  4 files changed, 37 insertions(+), 4 deletions(-)
> >
> > diff --git a/man/svlogd.8 b/man/svlogd.8
> > index 01b2324..5359d94 100644
> > --- a/man/svlogd.8
> > +++ b/man/svlogd.8
> > @@ -3,7 +3,8 @@
> >  svlogd \- runit's service logging daemon
> >  .SH SYNOPSIS
> >  .B svlogd
> > -[\-tttv] [\-r
> > +[\-tttv] [\-c
> > +.I file\fR] [\-r
> >  .I c\fR] [\-R
> >  .I xyz\fR] [\-l
> >  .I len\fR] [\-b
> > @@ -377,6 +378,18 @@ the form YYYY-MM-DDTHH:MM:SS.xxxxx when writing to
> >  .I log
> >  or to standard error.
> >  .TP
> > +.B \-c \fIfile
> > +config file.
> > +Use
> > +.I file
> > +as configuration instead of the default
> > +.I log/config
> > +path.
> > +.I file
> > +may either be absolute or relative, in which case it will be relative to
> > the
> > +.I log
> > +directory.
> > +.TP
> >  .B \-r \fIc
> >  replace.
> >  .I c
> > diff --git a/src/svlogd.c b/src/svlogd.c
> > index 90a3321..0109684 100644
> > --- a/src/svlogd.c
> > +++ b/src/svlogd.c
> > @@ -49,6 +49,7 @@ unsigned long linemax =1000;
> >  unsigned long buflen =1024;
> >  unsigned long linelen;
> >
> > +const char *config = "config";
> >  const char *replace ="";
> >  char repl =0;
> >
> > @@ -437,13 +438,14 @@ unsigned int logdir_open(struct logdir *ld, const
> > char *fn) {
> >    while (! stralloc_copys(&ld->processor, "")) pause_nomem();
> >
> >    /* read config */
> > -  if ((i =openreadclose("config", &sa, 128)) == -1)
> > +  if ((i =openreadclose(config, &sa, 128)) == -1)
> >      warn2("unable to read config", ld->name);
> >    if (i != 0) {
> >      int len, c;
> >      unsigned long port;
> >
> > -    if (verbose) strerr_warn4(INFO, "read: ", ld->name, "/config", 0);
> > +    if (verbose && *config != '/') strerr_warn5(INFO, "read: ", ld->name,
> > "/", config, 0);
> > +    else if (verbose) strerr_warn3(INFO, "read: ", config, 0);
> >      for (i =0; i +1 < sa.len; ++i) {
> >        len =byte_chr(&sa.s[i], sa.len -i, '\n');
> >        sa.s[len +i] =0;
> > @@ -667,8 +669,11 @@ int main(int argc, const char **argv) {
> >
> >    progname =*argv;
> >
> > -  while ((opt =getopt(argc, argv, "R:r:l:b:tvV")) != opteof) {
> > +  while ((opt =getopt(argc, argv, "c:R:r:l:b:tvV")) != opteof) {
> >      switch(opt) {
> > +    case 'c':
> > +      config =optarg;
> > +      break;
> >      case 'R':
> >        replace =optarg;
> >        if (! repl) repl ='_';
> > diff --git a/src/svlogd.check b/src/svlogd.check
> > index 7d926ef..e9584ee 100755
> > --- a/src/svlogd.check
> > +++ b/src/svlogd.check
> > @@ -24,4 +24,14 @@ echo t2 >"${ctmp}"/config
> >  echo $?
> >  cat "${ctmp}"/current
> >
> > +echo prelative-alternate >"${ctmp}"/alternate-config
> > +echo foo |svlogd -c alternate-config "${ctmp}"
> > +echo $?
> > +cat "${ctmp}"/current
> > +
> > +echo pabsolute-alternate >>"${ctmp}"/alternate-config
> > +echo foo |svlogd -c "${ctmp}"/alternate-config "${ctmp}"
> > +echo $?
> > +cat "${ctmp}"/current
> > +
> >  rm -rf "${ctmp}"
> > diff --git a/src/svlogd.dist b/src/svlogd.dist
> > index b3329e6..8570230 100644
> > --- a/src/svlogd.dist
> > +++ b/src/svlogd.dist
> > @@ -19,3 +19,8 @@ baz
> >  :ar
> >  :az
> >  0
> > +0
> > +relative-alternatefoo
> > +0
> > +relative-alternatefoo
> > +absolute-alternatefoo
> > --
> > 2.22.0
> >
> >
> 
> -- 
> Kevin Berry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] svlogd: implement option to use alternate config file
  2019-07-31 19:25   ` Patrick Steinhardt
@ 2019-08-01  6:43     ` Jan Braun
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Braun @ 2019-08-01  6:43 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Kevin Berry, supervision

[-- Attachment #1: Type: text/plain, Size: 1088 bytes --]

Patrick Steinhardt schrob:
> Yeah, I thought about using a symlink here, too. The main reason
> why I didn't want to do this is to keep configuration and data
> separate from each other. It honestly feels a bit weird to me to
> configure the logger in /var/log/$service -- doing so in
> /etc/sv/$service/log seems like the more obvious location to me
> and can be cleanly achieved with this new option without
> requiring a symlink.

I agree it feels weird. I expect to be able to rm -r /var/log/$foo
to get rid of logs, without accidentally losing configuration.

My standardized log/run script thus contains (among other things):

| if [ -e main-config ] && [ ! -e main/config ] ; then
|     ln -s "`realpath main-config`" main/config
| fi

I think that's a simpler (and therefore better) way to move the config
location than extending svlogd's C code.

And I likely will s/main/$i/g and put a
| for i in main foo bar ; do
| ...
| done
loop around that code once I need several logdirs with individual
configuration. I don't see how your -c option would achieve that.

regards,
    Jan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-01  6:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 18:00 [PATCH] svlogd: implement option to use alternate config file Patrick Steinhardt
2019-07-31 19:12 ` Kevin Berry
2019-07-31 19:25   ` Patrick Steinhardt
2019-08-01  6:43     ` Jan Braun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).