[systemd-devel] How to compute a value for a service argument or environment value?

Umut Tezduyar umut at tezduyar.com
Wed Mar 19 08:00:48 PDT 2014


Hi Alan,

As Cristian has suggested, the correct behavior is letting daemons
pick up the right argument.

Though, there is a hack if you can't re implement the daemon. You
could compute the variables in an ExecStartPre= and write them to a
file (/run/yourservice/arg) and point your
EnvironmentFile=/run/yourservice/arg. Hope it helps.

Thanks

On Thu, Mar 13, 2014 at 7:37 PM, Alan Stern <stern at rowland.harvard.edu> wrote:
> This question has probably been asked many times before, but I didn't
> see it mentioned anywhere on the systemd web site.
>
> I want to create a unit file for a service where the server program
> requires an argument or environment value that has to be computed at
> run time; it isn't known in advance.  For example, suppose the server
> requires the numeric UID value corresponding to some particular
> username, passed as an argument or an environment value.
>
> In a SysV-type shell script, I could simply do:
>
>         exec /path/to/server_program `id -u username`
>
> or
>
>         export USERID=`id -u username`
>         exec /path/to/server_program
>
> Neither of these is possible in a systemd service unit file.  So what
> is the best way to accomplish the same result?
>
> All I have been able to think of is to have ExecStart= run a shell
> script that computes the necessary values and then execs the actual
> server program.  Is there a better way?
>
> Alan Stern
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list