Project

General

Profile

Actions

Bug #4198

closed

Cf-execd started by cron is missing environment variables, making the agent unable to run correctly

Added by Michael Gliwinski over 10 years ago. Updated about 10 years ago.

Status:
Released
Priority:
3
Category:
System techniques
Target version:
Severity:
UX impact:
User visibility:
Effort required:
Priority:
Name check:
Fix check:
Regression:

Description

Created a fresh VM, installed minimal Ubuntu 12.04.3 server, added repo and installed rudder-agent (2.6.9) package.

Even though the installation doesn't start the agent, after a while it will be started by the newly added cron job.

Cron sets a very minimal environment for the started jobs, in particular PATH=/usr/bin:/bin. And when cron starts cf-agent and therefore cf-execd, they will inherit that PATH. This can be verified with: tr '\0' '\n' < /proc/$(pgrep cf-execd)/environ (when started from cron).

When cf-agent is running with this PATH setting, any package installations will fail with Bulk package schedule execution failed somewhere - unknown outcome for ... error in the output. This is caused by dpkg failing because required executables are not in the search path, e.g. try (same command as cf-agent would run, but with adjusted PATH):

# /usr/bin/env PATH=/usr/bin:/bin DEBIAN_FRONTEND=noninteractive LC_ALL=C /usr/bin/aptitude \
    -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef \
    -o Aptitude::Delete-Unused=false -o Aptitude::CmdLine::Ignore-Trust-Violations=false \
    --assume-yes install dstat
The following NEW packages will be installed:
  dstat 
0 packages upgraded, 1 newly installed, 0 to remove and 20 not upgraded.
Need to get 0 B/68.1 kB of archives. After unpacking 549 kB will be used.
dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
dpkg: error: 2 expected programs not found in PATH or not executable.
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
E: Sub-process /usr/bin/dpkg returned an error code (2)
A package failed to install.  Trying to recover:
dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
dpkg: error: 2 expected programs not found in PATH or not executable.
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.

This doesn't happen when started as a service as then the PATH is /sbin:/usr/sbin:/bin:/usr/bin (when started on boot by /etc/init.d/rc) or /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (or similar, when started from an interactive session, i.e. the init script inherits the PATH from calling environment).

A solution could be to add PATH setting to /etc/cron.d/rudder-agent, or to body agent control in promises.cf (but this will affect all agent executions, not only cron).


Related issues 1 (0 open1 closed)

Related to Rudder - User story #2472: Initialize a $PATH in shell environnement use by agent for "commands" action.RejectedActions
Actions

Also available in: Atom PDF