1

I'm trying to wrap my head around s6 supervisor suite. I've figured out run and log but I'm stuck with s6-envdir and I'm not sure how do I use it.

I see that environment variable gets set, but I can't access it.

To illustrate:

# According to the docs, set a variable
cat /local/s6/services/ping_stdout/env/PING_HOST
ya.ru
# Make sure there's no such variable in my current env
env | grep PING_HOST
echo $?
1
# Make sure it gets exported if I use s6-envdir
s6-envdir /local/s6/services/ping_stdout/env env | grep PING_HOST
PING_HOST=ya.ru
# Now try to get it printed
s6-envdir /local/s6/services/ping_stdout/env echo "=== ${PING_HOST} ==="
===  ===

It's not used, but if I try to use something that already is in my env, no problem:

s6-envdir /local/s6/services/ping_stdout/env echo "=== ${ZSH} ==="
=== /home/hoodoo/.oh-my-zsh ===

Did I get something wrong?

How do I use the variables set with s6-envdir?

Roman Grazhdan
  • 334
  • 3
  • 15

1 Answers1

1

This is the right form:

s6-envdir /local/s6/services/ping_stdout/env sh -c 'echo === ${PING_HOST} ==='

You need to start a subshell that will see the env variables s6-envdir provisioned. Also you need single quotes to make sure the subshell will do the substitution and print the variable.

If you start a daemon it should be like:

s6-envdir /local/s6/services/ping_stdout/env sh -c 'exec /full/path/to/your/executable'

The exec is needed so there will be no leftover extra shell. This is needed to make sure you signal the process directly via s6.

cstamas
  • 6,607
  • 24
  • 42
  • Thanks, it's even more than I asked for, great explanation! But the first example goes like this: ``s6-envdir /local/s6/services/ping_stdout/env bash -c 'echo "=== ${PING_HOST} ==="'`` i.e. I had to quote out what I pass to bash – Roman Grazhdan Sep 07 '16 at 21:25
  • @RomanGrazhdan you are right. I fixed the quoting. copy-paste issue ;-) – cstamas Sep 08 '16 at 10:44