[systemd-devel] Environment Variables are not getting passed to a child script started from a service
Mantas Mikulėnas
grawity at gmail.com
Thu Aug 22 04:45:24 UTC 2019
On Wed, Aug 21, 2019 at 7:30 PM Debraj Manna <subharaj.manna at gmail.com>
wrote:
> I am having a unit file like below running on Ubuntu 16.04 with systemd version 229.
>
> [Unit]
> Description=Hadoop-Yarn-Resourcemanager Service
> [Service]
> Type=simple
> Environment=JAVA_HOME=/usr/lib/jvm/jdk1.8
> Environment=YARN_USER=yarn
> Environment=YARN_IDENT_STRING=yarn
> Environment=YARN_PID_DIR=/var/run/hadoop-yarn
> Environment=YARN_LOG_DIR=/var/log/hadoop-yarn
> Environment=YARN_CONF_DIR=/etc/hadoop/conf
> Environment=HADOOP_LIBEXEC_DIR=/usr/lib/hadoop/libexec
> IgnoreSIGPIPE=false
> ExecStart=/home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-start.sh
> ExecStopPost=-/bin/bash /home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-poststop.sh
> ExecStopPost=-/bin/sleep 1
> RestartSec=2s
> Restart=always
> [Install]
> WantedBy=multi-user.target
>
> hadoop-yarn-resourcemanager-sysd-start.sh looks like below
>
> #!/bin/bash
>
> echo "Running pre-steps for hadoop-yarn-resourcemanager"
> sudo mkdir -p $YARN_LOG_DIR
> sudo chown -R yarn:hadoop $YARN_LOG_DIR
> sudo mkdir -p $YARN_PID_DIR
> sudo chown yarn:yarn $YARN_PID_DIR
> echo "Starting hadoop-yarn-resourcemanager"
> sudo -u yarn /usr/lib/hadoop-yarn/sbin/yarn-daemon.sh start resourcemanager
> sleep 3
> echo "Starting health check for hadoop-yarn-resourcemanager"
> /home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-health.sh
> res=$?
>
>
Usually `sudo` resets all environment variables except whitelisted ones.
That's not a systemd thing – pid1 *cannot* affect how environment variables
are inherited.
Don't use sudo in systemd startup scripts. Create the pid_dir using
RuntimeDirectory= (or tmpfiles.d), then just start yarn-daemon from
ExecStart directly with User=yarn.
And probably more importantly, don't start multiple services from a single
.service unit – it will never work well... (Chances are, if you do this,
you won't even *need* a PIDFile because systemd will be able to track the
process directly.)
--
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20190822/80071ca7/attachment-0001.html>
More information about the systemd-devel
mailing list