Skip to content

Commit

Permalink
(fleet) move the installer run path to /var/run/datadog/installer (#2…
Browse files Browse the repository at this point in the history
…5509)

Co-authored-by: BaptisteFoy <baptiste.foy@datadoghq.com>
  • Loading branch information
arbll and BaptisteFoy committed May 15, 2024
1 parent 1d5c52e commit f70fbf1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/installer/subcommands/daemon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func runFxWrapper(global *command.GlobalParams) error {
core.Bundle(),
fx.Supply(&rcservice.Params{
Options: []service.Option{
service.WithDatabaseFileName("remote-config-updater.db"),
service.WithDatabaseFileName("remote-config-installer.db"),
},
}),
rctelemetryreporterimpl.Module(),
Expand Down
2 changes: 1 addition & 1 deletion omnibus/config/software/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
env = with_embedded_path(env)

if linux_target?
command "invoke installer.build --rebuild --install-path=#{install_dir}", env: env
command "invoke installer.build --rebuild --run-path=/var/run/datadog/installer --install-path=#{install_dir}", env: env
mkdir "#{install_dir}/bin"
mkdir "#{install_dir}/run/"
mkdir "#{install_dir}/systemd/"
Expand Down
6 changes: 3 additions & 3 deletions omnibus/package-scripts/installer-deb/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

PACKAGES_DIR=/opt/datadog-packages
INSTALL_DIR=/opt/datadog-installer
PACKAGES_LOCK_DIR=/var/run/datadog-packages
RUN_DIR=/var/run/datadog/installer

set -e

case "$1" in
remove | purge)
datadog-installer purge || true
rm -f "/usr/bin/datadog-bootstrap"
echo "Force-deleting $INSTALL_DIR $PACKAGES_DIR $PACKAGES_LOCK_DIR"
echo "Force-deleting $INSTALL_DIR $PACKAGES_DIR $RUN_DIR"
rm -rf $PACKAGES_DIR
rm -rf $PACKAGES_LOCK_DIR
rm -rf $RUN_DIR
rm -rf $INSTALL_DIR
;;
*)
Expand Down
6 changes: 3 additions & 3 deletions omnibus/package-scripts/installer-rpm/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PACKAGES_DIR=/opt/datadog-packages
INSTALL_DIR=/opt/datadog-installer
PACKAGES_LOCK_DIR=/var/run/datadog-packages
RUN_DIR=/var/run/datadog/installer

set -e

Expand All @@ -17,9 +17,9 @@ fi

datadog-installer purge || true
rm -f "/usr/bin/datadog-bootstrap"
echo "Force-deleting $INSTALL_DIR $PACKAGES_DIR $PACKAGES_LOCK_DIR"
echo "Force-deleting $INSTALL_DIR $PACKAGES_DIR $RUN_DIR"
rm -rf $PACKAGES_DIR
rm -rf $PACKAGES_LOCK_DIR
rm -rf $RUN_DIR
rm -rf $INSTALL_DIR

exit 0
2 changes: 1 addition & 1 deletion pkg/fleet/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
// TmpDirPath is the path to the temporary directory used for package installation.
TmpDirPath = "/opt/datadog-packages"
// LocksPack is the path to the locks directory.
LocksPack = "/var/run/datadog-packages"
LocksPack = "/var/run/datadog/installer/locks"

defaultConfigsDir = "/etc"

Expand Down
20 changes: 14 additions & 6 deletions pkg/fleet/installer/service/datadog_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,30 @@ func SetupInstaller(ctx context.Context) (err error) {
if err != nil {
return fmt.Errorf("error creating /var/log/datadog: %w", err)
}
err = os.MkdirAll("/var/run/datadog-packages", 0777)
err = os.MkdirAll("/var/run/datadog/installer", 0755)
if err != nil {
return fmt.Errorf("error creating /var/run/datadog-packages: %w", err)
return fmt.Errorf("error creating /var/run/datadog/installer: %w", err)
}
err = os.MkdirAll("/var/run/datadog/installer/locks", 0777)
if err != nil {
return fmt.Errorf("error creating /var/run/datadog/installer/locks: %w", err)
}
// Locks directory can already be created by a package install
err = os.Chmod("/var/run/datadog-packages", 0777)
err = os.Chmod("/var/run/datadog/installer/locks", 0777)
if err != nil {
return fmt.Errorf("error changing permissions of /var/run/datadog-packages: %w", err)
return fmt.Errorf("error changing permissions of /var/run/datadog/installer/locks: %w", err)
}
err = os.Chown("/var/log/datadog", ddAgentUID, ddAgentGID)
if err != nil {
return fmt.Errorf("error changing owner of /var/log/datadog: %w", err)
}
err = os.Chown("/opt/datadog-packages/datadog-installer/stable/run", ddAgentUID, ddAgentGID)
err = os.Chown("/var/run/datadog", ddAgentUID, ddAgentGID)
if err != nil {
return fmt.Errorf("error changing owner of /var/run/datadog: %w", err)
}
err = os.Chown("/var/run/datadog/installer", ddAgentUID, ddAgentGID)
if err != nil {
return fmt.Errorf("error changing owner of /opt/datadog-packages/datadog-installer/stable/run: %w", err)
return fmt.Errorf("error changing owner of /var/run/datadog/installer: %w", err)
}

// Create installer path symlink
Expand Down
5 changes: 4 additions & 1 deletion tasks/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def build(
rebuild=False,
race=False,
install_path=None,
run_path=None,
build_include=None,
build_exclude=None,
arch="x64",
Expand All @@ -28,7 +29,9 @@ def build(
Build the updater.
"""

ldflags, gcflags, env = get_build_flags(ctx, major_version=MAJOR_VERSION, install_path=install_path)
ldflags, gcflags, env = get_build_flags(
ctx, major_version=MAJOR_VERSION, install_path=install_path, run_path=run_path
)

build_include = (
get_default_build_tags(
Expand Down
5 changes: 5 additions & 0 deletions tasks/libs/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def get_build_flags(
static=False,
prefix=None,
install_path=None,
run_path=None,
embedded_path=None,
rtloader_root=None,
python_home_2=None,
Expand Down Expand Up @@ -201,6 +202,10 @@ def get_build_flags(
if sys.platform.startswith('linux') and install_path:
ldflags += f"-X {REPO_PATH}/pkg/config/setup.InstallPath={install_path} "

# setting the run path
if sys.platform.startswith('linux') and run_path:
ldflags += f"-X {REPO_PATH}/pkg/config/setup.defaultRunPath={run_path} "

# setting python homes in the code
if python_home_2:
ldflags += f"-X {REPO_PATH}/pkg/collector/python.pythonHome2={python_home_2} "
Expand Down
8 changes: 5 additions & 3 deletions test/new-e2e/tests/installer/package_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ func (s *packageInstallerSuite) TestInstall() {
state.AssertUserHasGroup("dd-agent", "dd-agent")

state.AssertDirExists("/var/log/datadog", 0755, "dd-agent", "dd-agent")
state.AssertDirExists("/var/run/datadog-packages", 0777, "root", "root")
state.AssertDirExists("/var/run/datadog", 0755, "dd-agent", "dd-agent")
state.AssertDirExists("/var/run/datadog/installer", 0755, "dd-agent", "dd-agent")
state.AssertDirExists("/var/run/datadog/installer/locks", 0777, "root", "root")

state.AssertDirExists("/opt/datadog-installer", 0755, "root", "root")
state.AssertDirExists("/opt/datadog-packages", 0755, "root", "root")
state.AssertDirExists("/opt/datadog-packages/datadog-installer", 0755, "root", "root")
state.AssertDirExists("/opt/datadog-packages/datadog-installer/stable/run", 0755, "dd-agent", "dd-agent")

state.AssertSymlinkExists("/usr/bin/datadog-bootstrap", "/opt/datadog-installer/bin/installer/installer", "root", "root")
state.AssertSymlinkExists("/usr/bin/datadog-installer", "/opt/datadog-packages/datadog-installer/stable/bin/installer/installer", "root", "root")
Expand All @@ -60,10 +61,11 @@ func (s *packageInstallerSuite) TestUninstall() {
state.AssertUserHasGroup("dd-agent", "dd-agent")

state.AssertDirExists("/var/log/datadog", 0755, "dd-agent", "dd-agent")
state.AssertDirExists("/var/run/datadog", 0755, "dd-agent", "dd-agent")

// state that should get removed
state.AssertPathDoesNotExist("/opt/datadog-installer")
state.AssertPathDoesNotExist("/var/run/datadog-packages")
state.AssertPathDoesNotExist("/var/run/datadog/installer")
state.AssertPathDoesNotExist("/opt/datadog-packages")

state.AssertPathDoesNotExist("/usr/bin/datadog-bootstrap")
Expand Down

0 comments on commit f70fbf1

Please sign in to comment.