[systemd-devel] Using Multiple EnvironmentFile lines

Mantas Mikulėnas grawity at gmail.com
Tue Aug 2 12:11:59 PDT 2011


(Apparently, I've still yet to learn the difference between "Reply" and "Reply to List". Bleh. Disregard duplicates.)

On Tue, Aug 02, 2011 at 08:36:49AM -0400, Steve Dickson wrote:
> [...]
> So the nfs-server.service looks like:
> 
> [Unit]
> Description=NFS Protocol Daemon
> After=network.target rpcbind.service
> ConditionPathIsDirectory=/sys/module/sunrpc
> 
> [Service]
> EnvironmentFile=-/etc/sysconfig/nfs
> EnvironmentFile=/usr/lib/nfs-utils/scripts/nfs-server.preconfig
> ExecStartPre=-/usr/sbin/rpc.rquotad $RPCRQUOTADOPTS
> ExecStartPre=/usr/sbin/exportfs -r
> ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS ${RPCNFSDCOUNT}
> ExecStartPost=/usr/sbin/rpc.mountd $RPCMOUNTDOPTS
> ExecStartPost=-/usr/lib/nfs-utils/scripts/nfs-server.postconfig
> RemainAfterExit=yes

It doesn't make much sense for me to run nfsd, mountd, rquotad and everything from a single .service unit - after all, they are separate services with their own protocols... I might want to just restart rpc.idmapd without killing the rest of NFS.

For Arch Linux I tried to separate everything into their own units; far from perfect, but it's much cleaner:

https://github.com/grawity/systemd-arch-units/compare/master...nfs

Of course, Arch handles service configuration a bit differently (/etc/conf.d/nfs-* only had simple assignments in the first place), so it might not work for other distros.

> The nfs-server.preconfig looks like:
> 
> #
> # Set up arguments to rpc.mountd
> #
> # Define the port rpc.mountd listens on if requested
> [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
> 
> [...]
> 
> Now it appears the variables being set in nfs-server.preconfig
> (the second EnvironmentFile line) are not be carried over 
> into the .service file. 

EnvironmentFiles are parsed as static key=value pairs, *not* as shell scripts, so you cannot use 'case' or '&&' or other shell constructs in them. If you need that flexibility, run a single script from ExecStart and let it handle the configuration guessing.

> EnvironmentFile, ${RPCNFSDCOUNT} does not have a value when 

$RPCNFSDCOUNT can safely be empty, as rpc.nfsd already defaults to 8.

> Can one have multiple Environment Files to set multiple
> env variables?  

Yes, as long as they consist only of variable definitions.

> Is this the correct way to build command lines for daemon on the fly?

No. If you need the flexibility of shell constructs, just have a single ExecStart, point it to a shell script, and let the script handle the rest, calling "exec realservice" at the end.

-- 
Mantas M.


More information about the systemd-devel mailing list