Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-24 Thread Damien Robert
>From Lennart Poettering, Wed 08 Oct 2014 at 20:48:55 (+0200) :
> SyslogIdentifier= should do it.

It works, thanks!

> See systemd.exec(5) for details.

When I was looking for something like that in the doc, I was confused by
this passage: "This option is only useful when StandardOutput= or
StandardError= are set to syslog or kmsg.", but it apparently actually
works with StandardOutput=journal.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-24 Thread Mantas Mikulėnas
On Tue, Oct 7, 2014 at 8:12 PM, Jon Stanley  wrote:
> Since EnvironmentFile in a service isn't sourced by any shell, shell
> expressions in it will obviously not work the way that they did in a
> SysV style script.
>
> Nor does it seems that the environment gets preserved between
> ExecStartPre (where one could run a script that sets environment
> variables to be later used in the starting of the service) and
> ExecStart, so something like the following won't work:
>
> [Service]
> ExecStartPre=/something/that/sets/var
> ExecStart=/some/file $var
>
> Is there some way to get dynamically determined data into the
> environment such that it can be passed to the daemon at start?

Dynamic arguments sound like a bad idea in general. But the easiest
way to do this is by pointing ExecStart at a wrapper script which
first generates & exports variables, then just `exec`'s the actual
daemon.

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


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-09 Thread Lennart Poettering
On Thu, 09.10.14 10:00, Damien Robert (damien.olivier.rob...@gmail.com) wrote:

> >From Lennart Poettering, Wed 08 Oct 2014 at 20:48:55 (+0200) :
> > SyslogIdentifier= should do it.
> 
> It works, thanks!
> 
> > See systemd.exec(5) for details.
> 
> When I was looking for something like that in the doc, I was confused by
> this passage: "This option is only useful when StandardOutput= or
> StandardError= are set to syslog or kmsg.", but it apparently actually
> works with StandardOutput=journal.

Oh, indeed. That's a bug in the man page. Fixed now. Thanks for the pointer!

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-08 Thread Lennart Poettering
On Wed, 08.10.14 18:07, Damien Robert (damien.olivier.robert+gm...@gmail.com) 
wrote:

> Lennart Poettering  wrote in message
> <20141008094838.GB26284@gardel-login>:
> > On Tue, 07.10.14 19:18, Simon Peeters (peeters.si...@gmail.com) wrote:
> >> ExecStart=/bin/sh -c ". /something/that/sets/var; /some/file $var"
> > THis would certainly work, but I'd strongly advise to use "exec" for
> > executing /some/file at the end, so that the shell process is replaced
> > by the actual daemon process, instead of continuing running with the
> > demon process as child.
> 
> I am hijacking the thread because one minor inconvenience I have with sh -c
> 'exec foo' is that in journalctl the logging refers to 'sh':
> For instance:
> 
> [Unit]
> Description=Git backup
> ConditionPathIsDirectory=%h/backups/gitbackup
> 
> [Service]
> Type=simple
> ExecStart=/bin/sh -c 'exec %h/mine/script/gitbackup -v save'
> Nice=19
> IOSchedulingClass=best-effort
> IOSchedulingPriority=7
> 
> gives me the log:
> 
> Oct 08 21:35:43 mithrim sh[9680]: [master 54c23ae]
> Oct 08 21:35:43 mithrim sh[9680]: 2 files changed, 3 insertions(+), 3 
> deletions(-)
>  
> Do you know of any way to get 'gitbackup' in the log rather than 'sh'?

SyslogIdentifier= should do it.

See systemd.exec(5) for details.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-08 Thread Damien Robert
Lennart Poettering  wrote in message
<20141008094838.GB26284@gardel-login>:
> On Tue, 07.10.14 19:18, Simon Peeters (peeters.si...@gmail.com) wrote:
>> ExecStart=/bin/sh -c ". /something/that/sets/var; /some/file $var"
> THis would certainly work, but I'd strongly advise to use "exec" for
> executing /some/file at the end, so that the shell process is replaced
> by the actual daemon process, instead of continuing running with the
> demon process as child.

I am hijacking the thread because one minor inconvenience I have with sh -c
'exec foo' is that in journalctl the logging refers to 'sh':
For instance:

[Unit]
Description=Git backup
ConditionPathIsDirectory=%h/backups/gitbackup

[Service]
Type=simple
ExecStart=/bin/sh -c 'exec %h/mine/script/gitbackup -v save'
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

gives me the log:

Oct 08 21:35:43 mithrim sh[9680]: [master 54c23ae]
Oct 08 21:35:43 mithrim sh[9680]: 2 files changed, 3 insertions(+), 3 
deletions(-)
 
Do you know of any way to get 'gitbackup' in the log rather than 'sh'?

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


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-08 Thread Lennart Poettering
On Tue, 07.10.14 19:18, Simon Peeters (peeters.si...@gmail.com) wrote:

> 2014-10-07 19:12 GMT+02:00 Jon Stanley :
> > Since EnvironmentFile in a service isn't sourced by any shell, shell
> > expressions in it will obviously not work the way that they did in a
> > SysV style script.
> >
> > Nor does it seems that the environment gets preserved between
> > ExecStartPre (where one could run a script that sets environment
> > variables to be later used in the starting of the service) and
> > ExecStart, so something like the following won't work:
> 
> Which is logical since no system exists to modify the environment of
> the parent proces.
> 
> > [Service]
> > ExecStartPre=/something/that/sets/var
> > ExecStart=/some/file $var
> 
> ExecStart=/bin/sh -c ". /something/that/sets/var; /some/file $var"

THis would certainly work, but I'd strongly advise to use "exec" for
executing /some/file at the end, so that the shell process is replaced
by the actual daemon process, instead of continuing running with the
demon process as child.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-08 Thread Lennart Poettering
On Tue, 07.10.14 13:12, Jon Stanley (jonstan...@gmail.com) wrote:

> Since EnvironmentFile in a service isn't sourced by any shell, shell
> expressions in it will obviously not work the way that they did in a
> SysV style script.
> 
> Nor does it seems that the environment gets preserved between
> ExecStartPre (where one could run a script that sets environment
> variables to be later used in the starting of the service) and
> ExecStart, so something like the following won't work:
> 
> [Service]
> ExecStartPre=/something/that/sets/var
> ExecStart=/some/file $var
> 
> Is there some way to get dynamically determined data into the
> environment such that it can be passed to the daemon at start?

In such a case I'd suggest wrapping your daemon invocation in a shell
script, setting the environment variables first, and then using "exec"
to replace the shell process by the actual daemon process.

ExecStartPre= and ExecStart= are run in separate, cleaned up execution
contexts, in particular they do not inherit any environment variables
between each other.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-07 Thread Dale R. Worley
> From: Simon Peeters 
> 
> 2014-10-07 19:12 GMT+02:00 Jon Stanley :
> > [Service]
> > ExecStartPre=/something/that/sets/var
> > ExecStart=/some/file $var
> 
> ExecStart=/bin/sh -c ". /something/that/sets/var; /some/file $var"

Yeah, I think some thing like this would work:

ExecStartPre=/bin/sh -c '/something/that/sets/var ; printenv >/tmp/special'
ExecStart=/bin/sh -c '. /tmp/special ; /some/file $var'

But you probably want to reorganize how you're doing the job.
You probably want a wrapper script that calculates $var and then
invokes "/some/file $var".

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


Re: [systemd-devel] Shell expressions in EnvironmentFile

2014-10-07 Thread Simon Peeters
2014-10-07 19:12 GMT+02:00 Jon Stanley :
> Since EnvironmentFile in a service isn't sourced by any shell, shell
> expressions in it will obviously not work the way that they did in a
> SysV style script.
>
> Nor does it seems that the environment gets preserved between
> ExecStartPre (where one could run a script that sets environment
> variables to be later used in the starting of the service) and
> ExecStart, so something like the following won't work:

Which is logical since no system exists to modify the environment of
the parent proces.

> [Service]
> ExecStartPre=/something/that/sets/var
> ExecStart=/some/file $var

ExecStart=/bin/sh -c ". /something/that/sets/var; /some/file $var"

in other words: If you want shell behaviour, use a shell.

> Is there some way to get dynamically determined data into the
> environment such that it can be passed to the daemon at start?


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


[systemd-devel] Shell expressions in EnvironmentFile

2014-10-07 Thread Jon Stanley
Since EnvironmentFile in a service isn't sourced by any shell, shell
expressions in it will obviously not work the way that they did in a
SysV style script.

Nor does it seems that the environment gets preserved between
ExecStartPre (where one could run a script that sets environment
variables to be later used in the starting of the service) and
ExecStart, so something like the following won't work:

[Service]
ExecStartPre=/something/that/sets/var
ExecStart=/some/file $var

Is there some way to get dynamically determined data into the
environment such that it can be passed to the daemon at start?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel