Skip to content

Commit 9c99b82

Browse files
authored
[ABLD-327] Move generation of ddot init scripts to bazel. (#45013)
Moves the templating of the init scripts to bazel rules. Co-authored-by: tony.aiuto <tony.aiuto@datadoghq.com>
1 parent dd87258 commit 9c99b82

File tree

6 files changed

+77
-26
lines changed

6 files changed

+77
-26
lines changed

omnibus/config/software/init-scripts-ddot.rb

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,19 @@
55
always_build true
66

77
build do
8+
# This is horrible.
9+
destdir = "/"
810
output_config_dir = ENV["OUTPUT_CONFIG_DIR"] || ""
911
if linux_target?
10-
etc_dir = "#{output_config_dir}/etc/datadog-agent"
11-
mkdir "/etc/init"
1212
if debian_target?
13-
# sysvinit support for debian only for now
14-
mkdir "/etc/init.d"
15-
16-
erb source: "upstart_debian.ddot.conf.erb",
17-
dest: "/etc/init/datadog-agent-ddot.conf",
18-
mode: 0644,
19-
vars: { install_dir: install_dir, etc_dir: etc_dir }
20-
erb source: "sysvinit_debian.ddot.erb",
21-
dest: "/etc/init.d/datadog-agent-ddot",
22-
mode: 0755,
23-
vars: { install_dir: install_dir, etc_dir: etc_dir }
13+
command_on_repo_root "bazelisk run --//:output_config_dir='#{output_config_dir}' --//:install_dir=#{install_dir} -- //packages/ddot/debian:install --verbose --destdir=#{destdir}"
2414

2515
project.extra_package_file '/etc/init.d/datadog-agent-ddot'
16+
project.extra_package_file '/etc/init/datadog-agent-ddot.conf'
2617
elsif redhat_target? || suse_target?
27-
# Ship a different upstart job definition on RHEL to accommodate the old
28-
# version of upstart (0.6.5) that RHEL 6 provides.
29-
erb source: "upstart_redhat.ddot.conf.erb",
30-
dest: "/etc/init/datadog-agent-ddot.conf",
31-
mode: 0644,
32-
vars: { install_dir: install_dir, etc_dir: etc_dir }
18+
command_on_repo_root "bazelisk run --//:output_config_dir='#{output_config_dir}' --//:install_dir=#{install_dir} -- //packages/ddot/redhat:install --verbose --destdir=#{destdir}"
19+
20+
project.extra_package_file '/etc/init/datadog-agent-ddot.conf'
3321
end
34-
project.extra_package_file '/etc/init/datadog-agent-ddot.conf'
3522
end
3623
end

packages/ddot/debian/BUILD.bazel

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Rules to build /etc for ddot."""
2+
3+
load("@rules_pkg//pkg:install.bzl", "pkg_install")
4+
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup")
5+
load("//bazel/rules:dd_agent_expand_template.bzl", "dd_agent_expand_template")
6+
7+
package(default_visibility = ["//packages:__subpackages__"])
8+
9+
dd_agent_expand_template(
10+
name = "upstart_debian_ddot_conf_gen",
11+
out = "etc/init/datadog-agent-ddot.conf",
12+
attributes = pkg_attributes(mode = "0644"),
13+
template = "upstart_debian.ddot.conf.in",
14+
)
15+
16+
dd_agent_expand_template(
17+
name = "sysvinit_debian_ddot_gen",
18+
out = "etc/init.d/datadog-agent-ddot",
19+
attributes = pkg_attributes(mode = "0755"),
20+
template = "sysvinit_debian.ddot.in",
21+
)
22+
23+
pkg_filegroup(
24+
name = "all_files",
25+
srcs = [
26+
":sysvinit_debian_ddot_gen",
27+
":upstart_debian_ddot_conf_gen",
28+
],
29+
)
30+
31+
pkg_install(
32+
name = "install",
33+
srcs = [
34+
":all_files",
35+
],
36+
)

omnibus/config/templates/init-scripts-ddot/sysvinit_debian.ddot.erb renamed to packages/ddot/debian/sysvinit_debian.ddot.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
. /lib/lsb/init-functions
1414

15-
ETC_DIR="<%= etc_dir %>"
16-
INSTALL_DIR="<%= install_dir %>"
15+
ETC_DIR="{etc_dir}"
16+
INSTALL_DIR="{install_dir}"
1717
AGENTPATH="$INSTALL_DIR/embedded/bin/otel-agent"
1818
PIDFILE="$INSTALL_DIR/run/otel-agent.pid"
1919
AGENT_ARGS="run --config=$ETC_DIR/otel-config.yaml --core-config=$ETC_DIR/datadog.yaml --pidfile=$PIDFILE"

omnibus/config/templates/init-scripts-ddot/upstart_debian.ddot.conf.erb renamed to packages/ddot/debian/upstart_debian.ddot.conf.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ env DD_LOG_TO_CONSOLE=false
1616
setuid dd-agent
1717

1818
script
19-
exec <%= install_dir %>/embedded/bin/otel-agent run --config <%= etc_dir %>/otel-config.yaml --core-config <%= etc_dir %>/datadog.yaml --pidfile <%= install_dir %>/run/otel-agent.pid
19+
exec {install_dir}/embedded/bin/otel-agent run --config {etc_dir}/otel-config.yaml --core-config {etc_dir}/datadog.yaml --pidfile {install_dir}/run/otel-agent.pid
2020
end script
2121

2222
post-stop script
23-
rm -f <%= install_dir %>/run/otel-agent.pid
23+
rm -f {install_dir}/run/otel-agent.pid
2424
end script

packages/ddot/redhat/BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Rules to build /etc for ddot."""
2+
3+
load("@rules_pkg//pkg:install.bzl", "pkg_install")
4+
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup")
5+
load("//bazel/rules:dd_agent_expand_template.bzl", "dd_agent_expand_template")
6+
7+
package(default_visibility = ["//packages:__subpackages__"])
8+
9+
dd_agent_expand_template(
10+
name = "upstart_redhat_ddot_conf_gen",
11+
out = "etc/init/datadog-agent-ddot.conf",
12+
attributes = pkg_attributes(mode = "0644"),
13+
template = "upstart_redhat.ddot.conf.in",
14+
)
15+
16+
pkg_filegroup(
17+
name = "all_files",
18+
srcs = [
19+
":upstart_redhat_ddot_conf_gen",
20+
],
21+
)
22+
23+
pkg_install(
24+
name = "install",
25+
srcs = [
26+
":all_files",
27+
],
28+
)

omnibus/config/templates/init-scripts-ddot/upstart_redhat.ddot.conf.erb renamed to packages/ddot/redhat/upstart_redhat.ddot.conf.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ script
1616
#
1717
# setuid is not available in versions of upstart before 1.4. CentOS/RHEL6 use an earlier version of upstart.
1818
# This is the best way to set the user in the absence of setuid.
19-
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- <%= install_dir %>/embedded/bin/otel-agent run --config <%= etc_dir %>/otel-config.yaml --core-config <%= etc_dir %>/datadog.yaml --pidfile <%= install_dir %>/run/otel-agent.pid &>> /var/log/datadog/otel-errors.log
19+
exec su -s /bin/sh -c 'DD_LOG_TO_CONSOLE=false exec "$0" "$@"' dd-agent -- {install_dir}/embedded/bin/otel-agent run --config {etc_dir}/otel-config.yaml --core-config {etc_dir}/datadog.yaml --pidfile {install_dir}/run/otel-agent.pid &>> /var/log/datadog/otel-errors.log
2020
end script
2121

2222
pre-start script
@@ -29,5 +29,5 @@ pre-start script
2929
end script
3030

3131
post-stop script
32-
rm -f <%= install_dir %>/run/otel-agent.pid
32+
rm -f {install_dir}/run/otel-agent.pid
3333
end script

0 commit comments

Comments
 (0)