Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jan 2021 14:31:39 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Scott <freebsd-lists-5@thismonkey.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Need help specifying args in rc.conf for a service
Message-ID:  <20210111143139.278aec37.freebsd@edvax.de>
In-Reply-To: <X/xKy6Y6Cl4+zkhd@thismonkey.com>
References:  <X/w9IwVAFXyDr/ir@thismonkey.com> <20210111132107.82de40d0.freebsd@edvax.de> <X/xKy6Y6Cl4+zkhd@thismonkey.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Mon, 11 Jan 2021 23:55:39 +1100, Scott wrote:
> On Mon, Jan 11, 2021 at 01:21:07PM +0100, Polytropon wrote:
> > On Mon, 11 Jan 2021 22:57:23 +1100, Scott wrote:
> > > Hi all,
> > > 
> > > I posted this on the forums and was unsuccessful so I thought I'd try here:
> > > 
> > > I've been struggling to pass additional arguments to the Prometheus 
> > > node_exporter daemon in /etc/rc.conf.
> > > 
> > > The help for node_exporter provides an example argument (mount points to 
> > > ignore) as:
> > > 
> > > --collector.filesystem.ignored-mount-points="^/(dev)($|/)"
> > >                                 Regexp of mount points to ignore for filesystem collector.
> > > 
> > > The rc script says to use the _args variable to specify arguments to 
> > > node_exporter:
> > > # node_exporter_args (string):          Set extra arguments to pass to 
> > > # Default is "".
> > > 
> > > Adding the line:
> > > 
> > > node_exporter_args="--collector.filesystem.ignored-mount-points=\"^/(dev)($|/)\""
> > > 
> > > to /etc/rc.conf and running sh -x /usr/local/etc/rc.d/node_exporter start 
> > > results in:
> > > 
> > > + limits -C daemon su -m nobody -c 'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""'
> > > 
> > > Illegal variable name.
> > > 
> > > [...]
> > > 
> > > Can anyone please help?
> > 
> > If I see this correctly, the argument given to to the program's
> > option --collector.filesystem.ignored-mount-points= is to be a
> > regex, not the result of evaluating the regex (which the program
> > surely does internally). So my suggestion, without knowing any
> > further details, is to use this in /etc/rc.conf:
> > 
> > 	node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)($|/)"'
> > 
> > Always remember that /etc/rc.conf is, more or less, just a simple
> > shell script, so all rules applying to sh will apply to rc.conf
> > exactly. That's why 'single quotes' will stop any expansion and
> > transfer the value 1:1, which I think is what you are require to
> > do here. Characters such as $, " or ^ will be part of the string
> > handed over to the program, and will _not_ be interpreted by the
> > shell prior to assigning to the _args variable.
> > 
> > Within "double quotes", symbols such as $ have a specific meaning,
> > that's why you see the error ($ not properly quoted). So the
> > error message is completely valid and logical - and expected. ;-)
> > 
> > [...]
> > 
> Thanks Poly,
> 
> here's what I get using:
>         node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)($|/)"'
> 
> + _doit=$' limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""\''
> + _run_rc_doit $' limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""\''
> + debug $'run_rc_command: doit:  limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""\''
> + eval $' limits -C daemon su -m nobody -c \'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""\''
> + limits -C daemon su -m nobody -c 'sh -c "/usr/sbin/daemon  -f -p /var/run/node_exporter.pid -T node_exporter     /usr/bin/env /usr/local/bin/node_exporter     --web.listen-address=:9100     --collector.textfile.directory=/var/tmp/node_exporter     --collector.filesystem.ignored-mount-points="^/(dev)($|/)""'
> Illegal variable name.

So there seems to be another "layer" of possible interpretation.
The call to sh contains still a single $ which leads to the error.
Maybe using the quoted form \$ would help here?

	node_exporter_args='--collector.filesystem.ignored-mount-points="^/(dev)(\$|/)"'

It's not entirely trivial to deal with several layers of
variable expansion, especially when you want to avoid it. ;-)

Another option is to make the ' part of the option argument, but
that would be quite ugly (and maybe doesn't work):

	node_exporter_args="--collector.filesystem.ignored-mount-points='^/(dev)(\$|/)'"

Maybe you can try that as well?




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20210111143139.278aec37.freebsd>