<div dir="ltr"><div dir="ltr">On Wed, Aug 21, 2019 at 7:30 PM Debraj Manna <<a href="mailto:subharaj.manna@gmail.com">subharaj.manna@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><pre style="font-size:9pt"><pre style="font-size:9pt"><font face="arial, sans-serif" 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">hadoop-yarn-resourcemanager-sysd-start.sh</font><font color="#000000" 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></font></pre></pre></pre></pre></div></div></blockquote><div><br></div><div>Usually `sudo` resets all environment variables except whitelisted ones. That's not a systemd thing – pid1 *cannot* affect how environment variables are inherited.</div><div><br></div><div>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.</div><div><br></div><div>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.)</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>