[systemd-devel] Using Multiple EnvironmentFile lines
Hello, I noticed that the ypbind.service used multiple EnvironmentFile lines so thought this would be a good way to build command lines to daemons on the fly... 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 [Install] WantedBy=multi-user.target The /etc/sysconf/nfs like what is installed today. 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 case $MOUNTD_NFS_V2 in no|NO) RPCMOUNTDOPTS=$RPCMOUNTDOPTS --no-nfs-version 2 ;; esac case $MOUNTD_NFS_V3 in no|NO) RPCMOUNTDOPTS=$RPCMOUNTDOPTS --no-nfs-version 3 ;; esac # # Set up arguments to rpc.nfsd # # Define the number of nfsd processes to be started by default [ -z $RPCNFSDCOUNT ] RPCNFSDCOUNT=8 # Set v4 grace period if requested [ -n $NFSD_V4_GRACE ] { echo $NFSD_V4_GRACE /proc/fs/nfsd/nfsv4gracetime } Now it appears the variables being set in nfs-server.preconfig (the second EnvironmentFile line) are not be carried over into the .service file. For example if RPCNFSDCOUNT is not set in /etc/sysconfg/nfs (the first EnvironmentFile line) and is set in the second EnvironmentFile, ${RPCNFSDCOUNT} does not have a value when rpc.nfsd is started in the service file. Note setting the variable in the first EnvironmentFile always works. Can one have multiple Environment Files to set multiple env variables? Is this the correct way to build command lines for daemon on the fly? tia, steved. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Using Multiple EnvironmentFile lines
(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. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Using Multiple EnvironmentFile lines
On 08/02/2011 07:11 PM, Mantas Mikulėnas wrote: t 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: Same thing I did but Steve did not like that... JBG ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Using Multiple EnvironmentFile lines
On 08/02/2011 03:17 PM, Jóhann B. Guðmundsson wrote: On 08/02/2011 07:11 PM, Mantas Mikulėnas wrote: t 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: Same thing I did but Steve did not like that... I did play around with Mantas idea of breaking things up in that fashion but I quickly into a decency knot that look a bit looked a bit ominous ;-) So I just intergraded Mantas changes to the existing scripts and keep nfs-server.service the same. The scripts I plan on committing tomorrow are at: http://people.redhat.com/steved/.tmp/systemd/ I'm waiting on the NFS team at Red Hat to make comments... but please feel free share you opinion as well... They will be well used scripts... ;-) In the end, Johann, they are very similar to what you suggested a while ago, which means I lost a number of configuration knobs due to the simplistic environment that systemd supports. But... only time will tell how much they will be missed and they were mostly on legacy daemon that I can hopefully get rid of in the near future... I just want to thank everybody for their help! Its truly appreciated! steved. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel