logwrap.sh
detects your nodejs
or node
binary and offers some more
features that you can enable by setting these environment variables:
As the manpage of my version of xinetd
says:
"There is no way to put a SPACE in an environment variable."
If yours has the same problem, you can work around this with LW_ENVDEC
,
but only for vars that don't start with LW_
or are listed below LW_ENVDEC
.
First of all, sleep
a bit.
Meant to slow down rapid server respawns and the resulting syslog flood.
Value can be anything that your sleep
command would accept, e.g. 30s
.
Invoke the umask
bash command early, with this argument.
Defaults to 0022
, i.e. let anyone read and execute newly
create files/ directories/ pipes but not modify them.
Run just this one function, instead of the entire logwrap script. Meant for debugging logwrap itself.
Dump some debug info into this file about what the shell context looks like from inside: environment variables, paths, file descriptors, …
- If it doesn't start with a slash,
/tmp/
is prefixed. - If it ends with a slash, try to create a directory with that name (no-op it exists already), then append a probably-unique filename.
Try to redirect all output to syslog, using this tag name.
Only affects output that LW_STDOUT
and LW_STDERR
failed to grab.
.
(U+002E full stop): Try to redirect stdout to stderr. (Useful to capture what would have been sent over the network.)- anything else: Try to redirect stdout to this file, appending to it.
Try to redirect stderr to this file, appending to it.
A colon-separated list of names of LV_…
vars whose values shall be decoded.
In this list (NOT in the actual environment),
names are case-insensitive and you may omit the leading LV_
.
The encoded value should be prefixed with a codec name and a colon. These codecs are supported:
base64
: RFC 4648; also acceptsbase64url
.- When using the
base64
utility in your shell to encode values, double-check whether you meant to include a final newline in your input. Example:base64 <<<'hello'
→aGVsbG8K
→"hello\n"
- When using the
printf
: Letbash
'sprintf
render it.urldecode
:%hh
hex decoding, usingperl
and a regexp.
A colon-separated list of files that logwrap should source
(meaning the so-named bash
command) before it tries to use node.js.
You may want to set this to /etc/profile
in order to get
your usual env vars, including NODE_PATH
.
- Some versions of node ship with a profile script that discards
the previous value of
NODE_PATH
, so with them there's no use in settingNODE_PATH
via your xinetd service manifest. You can add paths viaLW_NODE_PATH
though.
List item magic:
- A leading
?
marks an item as optional, and the?
will be removed. - A leading
~/
will be replaced with the value of the the$HOME
environment variable and a/
. - If the resulting path is not a file (e.g. because it doesn't exist), logwrap will complain and fail – unless the item is optional, in which case it will be skipped silently.
- If the source operation fails, logwrap will complain and fail, even for optional items.
Will be added to your NODE_PATH
environment variable.
If it has been set already, old and new value are separated with a colon.
Evaluated after LW_SOURCE_INIT
in order to work even when a profile
script discards the old value (see above).
What command to use to invoke node.js.
Should be something like nodejs
, node
,
or an absolute path to your node.js binary.
- Default: Try to guess, with a fallback of
node
. - This program is used for stuff like
LW_CWD_RESOLVE
.
You can use newline characters to sneak arguments in.
The command to be used for the actual server invocation.
Default: use LW_NODEJS_CMD
- Special value
/
means to skip this part when constructing the effective command. Use this if you want to "just write your command" in theserver_args
setting of your xinetd service config. It's a bit like configuringserver = /usr/bin/env
except you can use all of the otherLW_*
features, likeLW_STDERR=/dev/null
. - You can use newline characters to sneak arguments in.
Meant to chdir into some node module's directory.
If you want to chdir here, you'd set this to inetd-util-pmb/README.md
,
or more reliably, inetd-util-pmb/package.json
.
Takes a colon-separated list of node module identifiers.
They're each require.resolve()
d with node, stopping at the first success.
(If none of them resolve, fatal error.)
If the resolved path has any slashes in it, cut at the last slash.
Try to chdir into whatever remains.
Try to chdir into whatever this variable's value is.
This happens after LW_CWD_RESOLVE
so you can refine its result.
Like LW_SOURCE_INIT
but it happens later,
especially after the chdirs,
which may give you better opportunities for some relative paths.
Takes a colon-separated list of node module identifiers.
Each of them is given to nodejs via the -r
option.
Given to nodejs via the -e
option.
Given to nodejs via the -p
option.
Path to your node script, if you want to run one.
Added to the nodejs command after all the potential -r
/-e
/-p
options.
Also, --
is added after the script path.
Start a bash(!) REPL (read-eval-print loop) just before nodejs would be started.
If you have redirected output (normal and/or errors), remember to watch the destination in addition to your input channel.
The value is expected to be a file system path to an acceptable REPL input, i.e. something that forgets those bytes that have been read from it, like a named pipe or a character device or a socket. If it's neither, tries to create a named pipe with that name.
-
is an alias for/dev/stdin
. This will only work for services withwait=no
, as you'd need a client socket on stdin.
As long as it's (still) an acceptable REPL input,
the REPL reads one line from it, then eval
s it,
unless it's one of these magic commands:
pid
: Show the REPL's process ID.unrepl
orQ
: Quit the REPL cleanly, to continue normal operation.rmrepl
orQr
: LikeQ
but try to delete the input pipe.flinch
orpanic
orDIE
: Alias forexit 42
.
If you delete the input while the REPL is still active, it will
remind you to clean up, then
fail, which should make logwrap
flinch.
In case your main nodejs command failed, eval
this in bash
.
Magic values:
REPL:
+ optional path: Do the REPL stuff as described forLW_BASH_REPL
. Empty path means to useLW_BASH_REPL
; if that's empty as well, do nothing.
In case your main nodejs command failed, take a nap, like LW_DELAY
.