Next: Configuration Examples, Previous: Init Process, Up: Top [Contents][Index]
Another use for pies
is as an entrypoint in a docker
container. This is similar to the init
mode described in
the previous chapter in that pies
runs with PID 1. However,
in this case pies
uses its regular configuration file.
When started with PID 1 from a docker container, pies
detects the fact automatically and switches to the entrypoint mode.
Up to version 1.4.90, automatical detection was not implemented, and
it was necessary to use the --no-init option to discern
between the entrypoint
and init
modes. This is no longer
the case. The option, however, is still retained.
The following Dockerfile fragment illustrates how to configure
pies
to be run from a container:
COPY pies.conf /etc ENTRYPOINT [ "/usr/sbin/pies", "--foreground", "--stderr" ]
It is supposed, of course, that the configuration file pies.conf is available in the same directory as Dockerfile.
It is a common practice to supply configuration settings via the
environment variables. To implement it in pies.conf, use
either expandenv
or shell
flag (see Early Environment Expansion). For example:
flags expandenv; command "syslogd -n -R $LOGHOST";
This will expand the environment variable LOGHOST
and pass its
value as one of the arguments to syslog
. The usual shell
syntax is supported. For example, to provide a default value for the
-R option above (in case LOGHOST
is empty or
undefined), use:
flags expandenv; command "syslogd -n -R ${LOGHOST:-172.19.255.255}";
Configuration preprocessing (see Preprocessor) can be used to
conditionally enable parts of the pies.conf file, depending
on the value of an environment variable. The technique described
below assumes that you use GNU m4
as preprocessor.
Define the following two M4 macros:
Expands the environment variable name within text. The macro does so by temporarily redefining the symbol name to the value of the environment variable name and expanding text.
The definition of the macro is:
m4_define(`CF_WITH_ENVAR',m4_dnl `m4_pushdef(`$1',m4_esyscmd(printf "$`$1'"))m4_dnl $2`'m4_dnl m4_popdef(`$1')m4_dnl ')
This macro allows you to use environment expansion where it is not normally supported. Consider, for example, this fragment:
component { CF_WITH_ENVAR(`WORKDIR', `chdir "WORKDIR";') ... }
If you set WORKDIR=/var/wd
prior to invoking pies
, it
will actually expand to
component { chdir "/var/wd"; ... }
See chdir, for details about the
chdir
statement.
If the environment variable name is defined and has a non-empty value, expand if-set, otherwise expand if-unset. Expand each occurrence of name in if-set to the actual value of the environment variable.
Following is the definition of this macro:
m4_define(`CF_IF_ENVAR',m4_dnl `CF_WITH_ENVAR(`$1',`m4_ifelse($1,`',$3,$2)')')
This macro makes it possible to conditionally enable configuration file fragments depending on whether some environment variable is defined. E.g.:
CF_IF_ENVAR(`LOGHOST',` component logger { command "syslogd -n -R LOGHOST; } ')
Place both macros in a single file and include it at the top of your
pies.conf using the m4_include
command. Alternatively,
you can place them in the pp-setup file (see pp-setup),
in which case they will be included automatically.
Next: Configuration Examples, Previous: Init Process, Up: Top [Contents][Index]