Re: [systemd-devel] Query regarding "EnvironmentFile"

2015-12-09 Thread Soumya Koduri



On 12/10/2015 01:16 AM, Lennart Poettering wrote:

On Wed, 09.12.15 18:27, Soumya Koduri (skod...@redhat.com) wrote:


Hi,

I have created a systemd.unit(nfs-ganesha.service) file as below :

[Unit]

After=nfs-ganesha-config.service
Requires=nfs-ganesha-config.service


[Service]
EnvironmentFile=-/run/sysconfig/ganesha
ExecStart=/usr/bin/ganesha.nfsd $OPTIONS ${EPOCH}

...



My intention is to execute/start nfs-ganesha-config.service always prior to
running nfs-ganesha.service (even during restart).

nfs-ganesha-config.service writes certain configuration values to
'/run/sysconfig/ganesha' which I would want nfs-ganesha.service to read
before starting ganesha.nfsd daemon.

But from my tests I see that nfs-ganesha.service picks up old configuration
values defined in '/run/sysconfig/ganesha' than the ones generated by
'nfs-ganesha-config.service' at that point. So I am assuming
'EnvironmentFile' gets loaded prior to running any dependent services (which
is 'nfs-ganesha-config.service' here).

Please confirm if that is the case. Also is there any way to load
'EnvironmentFile' only after executing all the dependent services.


EnvironmentFile= is processed immediately before forking off the
service process. The env vars the process will see are hence the
contents of that file after all deps with After= ran.

(But honestly, there's really no point in trying to dynamically
convert stuff into a file that is suitable for EnvironmentFile=. I
mean, if you want a shell script, then use a shell script, and invoke
that from the main daemon's ExecStart= line, and make it exec the real
daemon as last step. There's really no point in playing these
multi-service conversion games. Also /etc/sysconfig is a Redhatism
that should really go away, the whole concept is flawed. Adding a new
/run/sysconfig/ certainly makes that even worse.)

Thanks again for the clarification and your inputs. I wanted to 
understand the behavior before taking any other approach.


-Soumya


I probably should never have added EnvironmentFile= in the first
place. Packagers misunderstand that unit files are subject to admin
configuration and should be treated as such, and that spliting out
configuration of unit files into separate EnvironmentFiles= is a
really non-sensical game of unnecessary indirection.

Lennart


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Query regarding "EnvironmentFile"

2015-12-09 Thread Soumya Koduri

Hi,

I have created a systemd.unit(nfs-ganesha.service) file as below :

[Unit]

After=nfs-ganesha-config.service
Requires=nfs-ganesha-config.service


[Service]
EnvironmentFile=-/run/sysconfig/ganesha
ExecStart=/usr/bin/ganesha.nfsd $OPTIONS ${EPOCH}

...



My intention is to execute/start nfs-ganesha-config.service always prior 
to running nfs-ganesha.service (even during restart).


nfs-ganesha-config.service writes certain configuration values to 
'/run/sysconfig/ganesha' which I would want nfs-ganesha.service to read 
before starting ganesha.nfsd daemon.


But from my tests I see that nfs-ganesha.service picks up old 
configuration values defined in '/run/sysconfig/ganesha' than the ones 
generated by 'nfs-ganesha-config.service' at that point. So I am 
assuming 'EnvironmentFile' gets loaded prior to running any dependent 
services (which is 'nfs-ganesha-config.service' here).


Please confirm if that is the case. Also is there any way to load 
'EnvironmentFile' only after executing all the dependent services.


Thanks,
Soumya
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How to source a variable file using systemd

2015-10-28 Thread Soumya Koduri

Thank you so much for your inputs.

-Soumya

On 10/27/2015 05:49 PM, Lennart Poettering wrote:

On Tue, 27.10.15 16:05, Soumya Koduri (skod...@redhat.com) wrote:


Hi,

We have a use-case where in we have to read an environment variable (say
${MY_ENV_FILE}) from a file (say /etc/myconfig) and source ${MY_ENV_FILE} to
read yet another environment variable (say ${MY_ENV_VAR} in our systemd
service file.


Please use a shell script if you actually want the power of a
shell. Unit files are explicitly designed to be a simple, non-turing
complete language, with only minimal templating, and we have no
intention to change that.

If you want a scripting language, then please go for one, there's
nothing wrong with invoking a shell script from ExecStart= that then
does an "exec" for the real binary as last step.

Of course, I think well written software doesn't require doing this,
and supports good configuration files on its own, but if you have
software that isn't that way, then by all means go ahead and write a
shell script around it.



I first tried out below --

EnvironmentFile=/etc/myconfig
EnvironmentFile=${MY_ENV_FILE}
...
...
ExecStart='/bin/echo ${MY_ENV_VAR}'


env vars are *only* expanded in ExecXYZ= lines. This is because they
are determined at execution time from everything passed in from the
manager, runtime env vars, env vars from the unit file and env vars
from EnvironmentFile=.

Lennart


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How to source a variable file using systemd

2015-10-27 Thread Soumya Koduri

Thanks Richard & Mantas. That did the trick.

-Soumya

On 10/27/2015 04:11 PM, Richard Maw wrote:

On Tue, Oct 27, 2015 at 04:05:18PM +0530, Soumya Koduri wrote:


EnvironmentFile=/etc/myconfig

ExecStart=/bin/bash -c 'source ${MY_ENV_FILE} && echo ${MY_ENV_VAR}'


Systemd also does shell-like variable substitution, so potentially it's decided
to interpolate in the value of $MY_ENV_VAR before `source $MY_ENV_FILE` found
it.

Both those variables should be set in the environment appropriately when
ExecStart= is loaded, so I'd suggest escaping the $ as $$ so that bash gets to
do the interpolation instead of systemd.


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] How to source a variable file using systemd

2015-10-27 Thread Soumya Koduri

Hi,

We have a use-case where in we have to read an environment variable (say 
${MY_ENV_FILE}) from a file (say /etc/myconfig) and source 
${MY_ENV_FILE} to read yet another environment variable (say 
${MY_ENV_VAR} in our systemd service file.


I first tried out below --

EnvironmentFile=/etc/myconfig
EnvironmentFile=${MY_ENV_FILE}
...
...
ExecStart='/bin/echo ${MY_ENV_VAR}'


But this gave an error saying that EnvironmentFile can take only 
absolute paths. So instead I tried to find a work around and get the 
behavior using the bash script as below -


EnvironmentFile=/etc/myconfig

ExecStart=/bin/bash -c 'source ${MY_ENV_FILE} && echo ${MY_ENV_VAR}'


This doesn't throw any warnings but the ${MY_ENV_VAR} is still not read 
from the ${MY_ENV_FILE}



Kindly let me know what is the best way to read Environment variables 
from a file whose path is not fixed but yet another variable.



Thanks,
Soumya
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel