My apologies for the double mail to Herbert, I accidentally replied from a non-subscribed address the first time.
On 2023-03-28 at 05:47 -0700, Herbert Helmstreit wrote:
> I am trying to improve my nats server installation on RHEL [...]
Below, I answer your question, but before I do so: have you considered
using one of the systemd .service files which are included in the
nats-server source tree?
https://github.com/nats-io/nats-server/blob/main/util/nats-server-hardened.serviceThat's a good starting for a well-run nats-server install. You could
add to the [service] section something like:
EnvironmentFile=-/etc/defaults/nats-server
and then define any additional variables you want available.
We really don't recommend running the nats-server as root. Even if the
nats-server is probably far safer than many other things run as root,
it's not a good idea to run _anything_ with more privilege than it
needs. The only reason I can think of that you might even want to is
for binding port 443 for websockets support, and you can solve that in
systemd with:
AmbientCapabilities=CAP_NET_BIND_SERVICE
> [...] Given a start
> script like this
>
> export NATS_HOME=/root/NATS-Srv
>
> export PID=$NATS_HOME/bin/pid.txt
>
> export LOG=$NATS_HOME/log/server.log
>
> $NATS_HOME/bin/nats-server -c $NATS_HOME/cfg/server.conf &
>
> nats server is started with $PID pointing to the pid file The documentation
> says “Server configurations can specify variables … resolved from
> environment variables having the same name."
If I run this:
export NATS_HOME=$HOME/NATS-Srv
mkdir -pv $NATS_HOME/bin $NATS_HOME/log $NATS_HOME/cfg
echo 'pid_file=$PID' > $NATS_HOME/cfg/server.conf
export PID=$NATS_HOME/bin/pid.txt
export LOG=$NATS_HOME/log/server.log
nats-server -c $NATS_HOME/cfg/server.conf
then nats-server starts up using the pid-file as expected; the single
quotes keep PID from being expanded, and in fact I write out the
configuration file before the variable is defined.
$ cat -nv $NATS_HOME/cfg/server.conf
1
pid_file=$PID
If I replace $PID with $POD then the error message is:
nats-server: variable reference for 'POD' on line 2 can not be found
So the nats-server (v2.9.15 in my case) works fine.
> *pid_file=$PID* Parse error on line 26: 'Expected a top-level value to end
> with a new line, comment or EOF, but got '0' instead.'
I think that there was a typo in your configuration file.
> *pid_file={$PID}* Parse error on line 56: 'Unexpected EOF processing map.'
Curly braces define a map/dictionary/key-value-paired item.
> *pid_file="$PID"* Parse error on line 26: 'Expected a top-level value to
> end with a new line, comment or EOF, but got '0' instead.'
The $dollar expansion does not happen inside quoted strings in the nats
server configuration, so I would expect this to create a file named
"$PID" (4 characters, no quotes) in the current directory when the
nats-server is started.
> *pid_file=$PID* Parse error on line 26: 'Expected a top-level value to end
> with a new line, comment or EOF, but got '0' instead.'
and so on.
Are you sure that the pid_file directive is actually on line 26?
The only way I can get that sort of error message out of the nats-server
is to have a line which actually has a digit 0 after the closing
delimiter. For instance:
server_tags []0
log_file="foo"0
So I think that you're having some text editor issues.