[systemd-devel] Environment Variables are not getting passed to a child script started from a service

Debraj Manna subharaj.manna at gmail.com
Wed Aug 21 16:29:50 UTC 2019


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=$?

sleep 1
exit $res

yarn-daemon.sh has code like below

#!/usr/bin/env bash

echo "debrah $YARN_LOG_DIR $HADOOP_LIBEXEC_DIR"

...


But I am observing the environment variable values are not getting
passed to yarn-daemon.sh. Below are the logs

Aug 21 16:06:14 vrni-platform systemd[1]: Stopped
Hadoop-Yarn-Resourcemanager Service.
Aug 21 16:06:14 vrni-platform systemd[1]: Started
Hadoop-Yarn-Resourcemanager Service.
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + echo 'Running
pre-steps for hadoop-yarn-resourcemanager'
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: Running pre-steps
for hadoop-yarn-resourcemanager
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo mkdir -p
/var/log/hadoop-yarn
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo chown -R
yarn:hadoop /var/log/hadoop-yarn
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo mkdir -p
/var/run/hadoop-yarn
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + sudo chown
yarn:yarn /var/run/hadoop-yarn
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: + echo 'Starting
hadoop-yarn-resourcemanager'
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: Starting
hadoop-yarn-resourcemanager
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
Aug 21 16:06:14 vrni-platform
hadoop-yarn-resourcemanager-sysd-start.sh[12333]: debrah

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20190821/4685ad52/attachment.html>


More information about the systemd-devel mailing list