Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions bazel/rules/dd_agent_expand_template.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""dd_agent_expand_template. Expand a template, splicing in agent specific flags."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_pkg//pkg:providers.bzl", "PackageFilesInfo")

# The place we will install to if we run bazel pkg_install without a destdir
# We use /tmp for lack of a better safe space.
Expand All @@ -26,7 +28,9 @@ def _dd_agent_expand_template_impl(ctx):

# TODO: decide if we should default etc to the output base or relative to install_dir.
# There are use cases for either. For now, we are relative to the output base.
subs["{etc_dir}"] = subs["{output_config_dir}"] + "/etc"
# Note that the choice of /etc/datadog-agent seems odd, in that /etc is usually /etc,
# but this matches what is done in the current product packaging.
subs["{etc_dir}"] = subs["{output_config_dir}"] + "/etc/datadog-agent"

# Now let local substitutions override the flags.
subs.update(ctx.attr.substitutions)
Expand All @@ -42,7 +46,30 @@ def _dd_agent_expand_template_impl(ctx):
output = ctx.outputs.out,
substitutions = subs,
)
return [DefaultInfo(files = depset([ctx.outputs.out]))]

# Now build an output path relative to this package.
workspace_root = paths.join("..", ctx.label.workspace_name) if ctx.label.workspace_name else ""
package_path = paths.join(workspace_root, ctx.outputs.out.owner.package)
dest_path = paths.relativize(ctx.outputs.out.short_path, package_path)
destination = paths.join(ctx.attr.prefix, dest_path)
return [
DefaultInfo(files = depset([ctx.outputs.out])),
PackageFilesInfo(
dest_src_map = {destination: ctx.outputs.out},
attributes = json.decode(ctx.attr.attributes),
),
]

OUT_DOC = """The destination of the expanded file.

When this target is consummed by pkg_* rules, the output destinaion
of the file is computed relative to the package. This is effectively
the equivalent to using `strip_prefix=strip_prefix.from_pkg()` of a
`pkg_files` rule.

If `prefix` is also specified, that is applied after computing the
package relative path.
"""

dd_agent_expand_template = rule(
implementation = _dd_agent_expand_template_impl,
Expand Down Expand Up @@ -70,10 +97,12 @@ explicitly add delimiters to the key strings, for example "{KEY}" or "@KEY@"."""
"substitutions": attr.string_dict(
doc = "A dictionary mapping strings to their substitutions. These take precedence over flags.",
),
"out": attr.output(
mandatory = True,
doc = "The destination of the expanded file.",
"out": attr.output(mandatory = True, doc = OUT_DOC),
"attributes": attr.string(
doc = """See @rules_pkg for documentation.""",
default = "{}", # Empty JSON
),
"prefix": attr.string(doc = """See @rules_pkg for documentation."""),
"_install_dir": attr.label(default = "@@//:install_dir"),
"_output_config_dir": attr.label(default = "@@//:output_config_dir"),
},
Expand Down
27 changes: 1 addition & 26 deletions omnibus/config/software/init-scripts-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,7 @@
project.extra_package_file '/etc/init.d/datadog-agent-security'
project.extra_package_file '/etc/init.d/datadog-agent-data-plane'
elsif redhat_target? || suse_target?
# Ship a different upstart job definition on RHEL to accommodate the old
# version of upstart (0.6.5) that RHEL 6 provides.
erb source: "upstart_redhat.conf.erb",
dest: "/etc/init/datadog-agent.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
erb source: "upstart_redhat.process.conf.erb",
dest: "/etc/init/datadog-agent-process.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
erb source: "upstart_redhat.sysprobe.conf.erb",
dest: "/etc/init/datadog-agent-sysprobe.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
erb source: "upstart_redhat.trace.conf.erb",
dest: "/etc/init/datadog-agent-trace.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
erb source: "upstart_redhat.security.conf.erb",
dest: "/etc/init/datadog-agent-security.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
erb source: "upstart_redhat.data-plane.conf.erb",
dest: "/etc/init/datadog-agent-data-plane.conf",
mode: 0644,
vars: { install_dir: install_dir, etc_dir: etc_dir }
command_on_repo_root "bazelisk run --//:output_config_dir='#{output_config_dir}' --//:install_dir=#{install_dir} -- //packages/redhat/etc:install --verbose --destdir=#{destdir}"
end
project.extra_package_file '/etc/init/datadog-agent.conf'
project.extra_package_file '/etc/init/datadog-agent-process.conf'
Expand Down
70 changes: 70 additions & 0 deletions packages/redhat/etc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Rules to build /etc for Debian distributions."""

load("@rules_pkg//pkg:install.bzl", "pkg_install")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup")
load("//bazel/rules:dd_agent_expand_template.bzl", "dd_agent_expand_template")

package(default_visibility = ["//packages:__subpackages__"])

# Ship a different upstart job definition from debian on RHEL to accommodate
# the old version of upstart (0.6.5) that RHEL 6 provides.
dd_agent_expand_template(
name = "upstart_redhat_conf_gen",
out = "etc/init/datadog-agent.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.conf.in",
)

dd_agent_expand_template(
name = "upstart_redhat_process_conf_gen",
out = "etc/init/datadog-agent-process.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.process.conf.in",
)

dd_agent_expand_template(
name = "upstart_redhat_sysprobe_conf_gen",
out = "etc/init/datadog-agent-sysprobe.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.sysprobe.conf.in",
)

dd_agent_expand_template(
name = "upstart_redhat_trace_conf_gen",
out = "etc/init/datadog-agent-trace.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.trace.conf.in",
)

dd_agent_expand_template(
name = "upstart_redhat_security_conf_gen",
out = "etc/init/datadog-agent-security.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.security.conf.in",
)

dd_agent_expand_template(
name = "upstart_redhat_data_plane_conf_gen",
out = "etc/init/datadog-agent-data-plane.conf",
attributes = pkg_attributes(mode = "0644"),
template = "upstart_redhat.data-plane.conf.in",
)

pkg_filegroup(
name = "all_files",
srcs = [
":upstart_redhat_conf_gen",
":upstart_redhat_data_plane_conf_gen",
":upstart_redhat_process_conf_gen",
":upstart_redhat_security_conf_gen",
":upstart_redhat_sysprobe_conf_gen",
":upstart_redhat_trace_conf_gen",
],
)

pkg_install(
name = "install",
srcs = [
":all_files",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script
#
# setuid is not available in versions of upstart before 1.4. CentOS/RHEL6 use an earlier version of upstart.
# This is the best way to set the user in the absence of setuid.
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- <%= install_dir %>/bin/agent/agent run -p <%= install_dir %>/run/agent.pid &>> /var/log/datadog/errors.log
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- {install_dir}/bin/agent/agent run -p {install_dir}/run/agent.pid &>> /var/log/datadog/errors.log
end script

pre-start script
Expand All @@ -29,5 +29,5 @@ pre-start script
end script

post-stop script
rm -f <%= install_dir %>/run/agent.pid
rm -f {install_dir}/run/agent.pid
end script
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script
#
# setuid is not available in versions of upstart before 1.4. CentOS/RHEL6 use an earlier version of upstart.
# This is the best way to set the user in the absence of setuid.
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- <%= install_dir %>/embedded/bin/agent-data-plane run --config <%= etc_dir %>/datadog.yaml --pidfile <%= install_dir %>/run/agent-data-plane.pid &>> /var/log/datadog/data-plane-errors.log
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- {install_dir}/embedded/bin/agent-data-plane run --config {etc_dir}/datadog.yaml --pidfile {install_dir}/run/agent-data-plane.pid &>> /var/log/datadog/data-plane-errors.log
end script

pre-start script
Expand All @@ -29,5 +29,5 @@ pre-start script
end script

post-stop script
rm -f <%= install_dir %>/run/agent-data-plane.pid
rm -f {install_dir}/run/agent-data-plane.pid
end script
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script
#
# setuid is not available in versions of upstart before 1.4. CentOS/RHEL6 use an earlier version of upstart.
# This is the best way to set the user in the absence of setuid.
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- <%= install_dir %>/embedded/bin/process-agent --cfgpath=<%= etc_dir %>/datadog.yaml --sysprobe-config=<%= etc_dir %>/system-probe.yaml --pid=<%= install_dir %>/run/process-agent.pid &>> /var/log/datadog/process-errors.log
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- {install_dir}/embedded/bin/process-agent --cfgpath={etc_dir}/datadog.yaml --sysprobe-config={etc_dir}/system-probe.yaml --pid={install_dir}/run/process-agent.pid &>> /var/log/datadog/process-errors.log
end script

pre-start script
Expand All @@ -29,5 +29,5 @@ pre-start script
end script

post-stop script
rm -f <%= install_dir %>/run/process-agent.pid
rm -f {install_dir}/run/process-agent.pid
end script
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ script
# Logging to console from the agent is disabled since the agent already logs using file or
# syslog depending on its configuration. We then redirect the stdout/stderr of the agent process
# to log panic/crashes.
exec <%= install_dir %>/embedded/bin/security-agent start -c <%= etc_dir %>/datadog.yaml -c <%= etc_dir %>/security-agent.yaml --sysprobe-config <%= etc_dir %>/system-probe.yaml -p <%= install_dir %>/run/security-agent.pid &>> /var/log/datadog/security-errors.log
exec {install_dir}/embedded/bin/security-agent start -c {etc_dir}/datadog.yaml -c {etc_dir}/security-agent.yaml --sysprobe-config {etc_dir}/system-probe.yaml -p {install_dir}/run/security-agent.pid &>> /var/log/datadog/security-errors.log
end script

pre-start script
# Do not run if security-agent.yaml does not exist
test -f <%= etc_dir %>/security-agent.yaml || { stop ; exit 0; }
test -f {etc_dir}/security-agent.yaml || { stop ; exit 0; }

# Manual rotation of errors log
log_file_size=`du -b /var/log/datadog/security-errors.log | cut -f1`
Expand All @@ -29,5 +29,5 @@ pre-start script
end script

post-stop script
rm -f <%= install_dir %>/run/security-agent.pid
rm -f {install_dir}/run/security-agent.pid
end script
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ console output

pre-start script
# Do not run if config file doesn't exist
test -f <%= etc_dir %>/system-probe.yaml || { stop ; exit 0; }
test -f {etc_dir}/system-probe.yaml || { stop ; exit 0; }

# Manual rotation of errors log
log_file_size=`du -b /var/log/datadog/system-probe-errors.log | cut -f1`
Expand All @@ -32,9 +32,9 @@ script
# Logging to console from the agent is disabled since the agent already logs using file or
# syslog depending on its configuration. We then redirect the stdout/stderr of the agent process
# to log panic/crashes.
exec <%= install_dir %>/embedded/bin/system-probe run --config=<%= etc_dir %>/system-probe.yaml --pid=<%= install_dir %>/run/system-probe.pid &>> /var/log/datadog/system-probe-errors.log
exec {install_dir}/embedded/bin/system-probe run --config={etc_dir}/system-probe.yaml --pid={install_dir}/run/system-probe.pid &>> /var/log/datadog/system-probe-errors.log
end script

post-stop script
rm -f <%= install_dir %>/run/system-probe.pid
rm -f {install_dir}/run/system-probe.pid
end script
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script
#
# setuid is not available in versions of upstart before 1.4. CentOS/RHEL6 use an earlier version of upstart.
# This is the best way to set the user in the absence of setuid.
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- <%= install_dir %>/embedded/bin/trace-loader <%= etc_dir %>/datadog.yaml <%= install_dir %>/embedded/bin/trace-agent --config <%= etc_dir %>/datadog.yaml --pidfile <%= install_dir %>/run/trace-agent.pid &>> /var/log/datadog/trace-errors.log
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- {install_dir}/embedded/bin/trace-loader {etc_dir}/datadog.yaml {install_dir}/embedded/bin/trace-agent --config {etc_dir}/datadog.yaml --pidfile {install_dir}/run/trace-agent.pid &>> /var/log/datadog/trace-errors.log
end script

pre-start script
Expand All @@ -29,5 +29,5 @@ pre-start script
end script

post-stop script
rm -f <%= install_dir %>/run/trace-agent.pid
rm -f {install_dir}/run/trace-agent.pid
end script