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 about 9 years ago. Updated almost 9 years ago.

Status:
Released
Priority:
3
Category:
System techniques
Target version:
Severity:
UX impact:
User visibility:
Effort required:
Priority:
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 #1

Updated by Vincent MEMBRÉ about 9 years ago

  • Assignee set to Vincent MEMBRÉ
  • Priority changed from N/A to 3
  • Target version set to 2.4.13

Hello Mickael!

Thanks for reporting and the explanations!

As it concerns the cron-agent, it must affect 2.4 too. It must be confirm though.

To reprocuce the procedure seems:

  1. install rudder-agent
  2. configure it (/var/rudder/cfengine-community/policy_server.dat)
  3. wait for cron-agent to start the agent
  4. fails on installation of package

using rudder-vagrant and modifying provision script to not start the agent at the end should help.

Adding the PATH to cron seems a good idea to me and less invasive than modifying all techniques.

Matthieu or me should take care of this.

Actions #2

Updated by Vincent MEMBRÉ about 9 years ago

  • Target version changed from 2.4.13 to 2.6.11

Since version 2.4 is not maintained anymore, retargeting to branch 2.6

Actions #3

Updated by Matthieu CERDA almost 9 years ago

  • Category set to System techniques
  • Status changed from New to In progress
  • Assignee changed from Vincent MEMBRÉ to Matthieu CERDA
Actions #4

Updated by Matthieu CERDA almost 9 years ago

  • Subject changed from Bulk package schedule execution failed when cf-execd started from cron to Cron is starting cf-execd with missing environment variables
Actions #5

Updated by Matthieu CERDA almost 9 years ago

  • Status changed from In progress to Pending technical review
  • Assignee changed from Matthieu CERDA to Jonathan CLARKE
  • % Done changed from 0 to 100
  • Pull Request set to https://github.com/Normation/rudder-techniques/pull/297

PR available.

Actions #6

Updated by Matthieu CERDA almost 9 years ago

PR updated !

Actions #7

Updated by Jonathan CLARKE almost 9 years ago

  • Assignee changed from Jonathan CLARKE to Matthieu CERDA
Actions #8

Updated by Matthieu CERDA almost 9 years ago

  • Assignee changed from Matthieu CERDA to Jonathan CLARKE

Question answered on the PR.

Actions #9

Updated by Matthieu CERDA almost 9 years ago

  • Status changed from Pending technical review to Pending release

Applied in changeset policy-templates:commit:16c35f55dd88c6a52d455d58ed1b45af4fbc67c1.

Actions #10

Updated by Jonathan CLARKE almost 9 years ago

Applied in changeset policy-templates:commit:d61679aa55bfe2eb377d46308e081baea570cd25.

Actions #11

Updated by Vincent MEMBRÉ almost 9 years ago

  • Subject changed from Cron is starting cf-execd with missing environment variables to Cf-execd started by cron is missing environment variables, making the agent unable to run correctly
Actions #12

Updated by Vincent MEMBRÉ almost 9 years ago

  • Status changed from Pending release to Released

This bug has been fixed in Rudder 2.6.11, which was released today.
Check out:

Actions

Also available in: Atom PDF