<div dir="ltr"><div><pre style="font-size:9pt"><pre style="font-size:9pt"><font face="arial, sans-serif" style="" color="#000000">I am having a unit file like below running on Ubuntu 16.04 with systemd version 229</font><font face="Menlo" style="color:rgb(102,14,122)">.</font></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="color:rgb(102,14,122);font-weight:bold">[Unit]<br></span><span style="color:rgb(0,0,128);font-weight:bold">Description</span>=<span style="color:rgb(0,128,0);font-weight:bold">Hadoop-Yarn-Resourcemanager Service</span><span style="color:rgb(0,128,0);font-weight:bold"><br></span><span style="color:rgb(102,14,122);font-weight:bold">[Service]<br></span><span style="color:rgb(0,0,128);font-weight:bold">Type</span>=<span style="color:rgb(0,128,0);font-weight:bold">simple<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">JAVA_HOME=/usr/lib/jvm/jdk1.8<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">YARN_USER=yarn<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">YARN_IDENT_STRING=yarn<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">YARN_PID_DIR=/var/run/hadoop-yarn<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">YARN_LOG_DIR=/var/log/hadoop-yarn<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">YARN_CONF_DIR=/etc/hadoop/conf<br></span><span style="color:rgb(0,0,128);font-weight:bold">Environment</span>=<span style="color:rgb(0,128,0);font-weight:bold">HADOOP_LIBEXEC_DIR=/usr/lib/hadoop/libexec</span><span style="color:rgb(0,128,0);font-weight:bold"><br></span><span style="color:rgb(0,0,128);font-weight:bold">IgnoreSIGPIPE</span>=<span style="color:rgb(0,128,0);font-weight:bold">false</span><span style="color:rgb(0,128,0);font-weight:bold"><br></span><span style="color:rgb(0,0,128);font-weight:bold">ExecStart</span>=<span style="color:rgb(0,128,0);font-weight:bold">/home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-start.sh<br></span><span style="color:rgb(0,0,128);font-weight:bold">ExecStopPost</span>=<span style="color:rgb(0,128,0);font-weight:bold">-/bin/bash /home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-poststop.sh<br></span><span style="color:rgb(0,0,128);font-weight:bold">ExecStopPost</span>=<span style="color:rgb(0,128,0);font-weight:bold">-/bin/sleep 1</span><span style="color:rgb(0,128,0);font-weight:bold"><br></span><span style="color:rgb(0,0,128);font-weight:bold">RestartSec</span>=<span style="color:rgb(0,128,0);font-weight:bold">2s<br></span><span style="color:rgb(0,0,128);font-weight:bold">Restart</span>=<span style="color:rgb(0,128,0);font-weight:bold">always</span><span style="color:rgb(0,128,0);font-weight:bold"><br></span><span style="color:rgb(102,14,122);font-weight:bold">[Install]<br></span><span style="color:rgb(0,0,128);font-weight:bold">WantedBy</span>=<span style="color:rgb(0,128,0);font-weight:bold">multi-user.target<br></span></pre><pre style="font-size:9pt"><pre style="font-size:9pt"><font color="#000000" style="">hadoop-yarn-resourcemanager-sysd-start.sh</font><font color="#000000" style="" face="arial, sans-serif"> looks like below</font></pre><pre style="color:rgb(0,0,0);font-size:9pt"><pre style="font-family:Menlo;font-size:9pt"><span style="font-weight:bold">#!/bin/bash</span></pre><pre style="font-size:9pt"><span style="font-family:Menlo;color:rgb(11,12,149)">echo </span><span style="font-family:Menlo;color:rgb(0,128,0);font-weight:bold">"Running pre-steps for hadoop-yarn-resourcemanager"<br></span><font face="Menlo">sudo mkdir -p $YARN_LOG_DIR<br>sudo chown -R yarn:hadoop $YARN_LOG_DIR<br>sudo mkdir -p $YARN_PID_DIR<br>sudo chown yarn:yarn $YARN_PID_DIR<br></font><span style="font-family:Menlo;color:rgb(11,12,149)">echo </span><span style="font-family:Menlo;color:rgb(0,128,0);font-weight:bold">"Starting hadoop-yarn-resourcemanager"<br></span><font face="Menlo">sudo -u yarn /usr/lib/hadoop-yarn/sbin/yarn-daemon.sh start resourcemanager<br>sleep </font><span style="font-family:Menlo;color:rgb(0,0,255)">3<br></span><span style="font-family:Menlo;color:rgb(11,12,149)">echo </span><span style="font-family:Menlo;color:rgb(0,128,0);font-weight:bold">"Starting health check for hadoop-yarn-resourcemanager"<br></span><font face="Menlo">/home/ubuntu/build-target/cdh/yarn-rm/hadoop-yarn-resourcemanager-sysd-health.sh<br>res=$?<br><br>sleep </font><span style="font-family:Menlo;color:rgb(0,0,255)">1<br></span><span style="font-family:Menlo;color:rgb(11,12,149)">exit </span><font face="Menlo">$res<br><br></font><pre style="font-size:9pt">yarn-daemon.sh<font face="arial, sans-serif"> has code like below</font></pre><pre style="font-family:Menlo;font-size:9pt"><span style="font-size:9pt">#!/usr/bin/env bash</span><br></pre><pre style="font-family:Menlo;font-size:9pt">echo "debrah $YARN_LOG_DIR $HADOOP_LIBEXEC_DIR"<br></pre><pre style="font-family:Menlo;font-size:9pt">...</pre><pre style="font-family:Menlo;font-size:9pt"><br></pre><pre style="font-size:9pt"><font face="arial, sans-serif">But I am observing the environment variable values are not getting passed to </font>yarn-daemon.sh<font face="arial, sans-serif">. Below are the logs</font></pre><pre style="font-family:Menlo;font-size:9pt">Aug 21 16:06:14 vrni-platform systemd[1]: Stopped Hadoop-Yarn-Resourcemanager Service.<br>Aug 21 16:06:14 vrni-platform systemd[1]: Started Hadoop-Yarn-Resourcemanager Service.<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + echo 'Running pre-steps for hadoop-yarn-resourcemanager'<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: Running pre-steps for hadoop-yarn-resourcemanager<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo mkdir -p /var/log/hadoop-yarn<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo chown -R yarn:hadoop /var/log/hadoop-yarn<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo mkdir -p /var/run/hadoop-yarn<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo chown yarn:yarn /var/run/hadoop-yarn<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + echo 'Starting hadoop-yarn-resourcemanager'<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: Starting hadoop-yarn-resourcemanager<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo -u yarn /usr/lib/hadoop-yarn/sbin/yarn-daemon.sh start resourcemanager<br>Aug 21 16:06:14 vrni-platform hadoop-yarn-resourcemanager-sysd-start.sh[12333]: debrah<br></pre><font face="Menlo">Can someone let me know what is the correct way to declare the enviroment variable so that it gets passed to a child script started by a systemd service?</font></pre></pre></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="color:rgb(0,128,0);font-weight:bold"><br></span></pre></pre></div></div>