Skip to content

Commit

Permalink
use service wrapper on linux & macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet committed Oct 23, 2024
1 parent 519d652 commit e567275
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 27 deletions.
2 changes: 2 additions & 0 deletions assets/productbuild/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ collector_files=(
"/etc/otelcol-sumo/opamp.d"
"/usr/local/bin/otelcol-config"
"/usr/local/bin/otelcol-sumo"
"/usr/share/otelcol-sumo/otelcol-sumo.sh"
"/usr/share/otelcol-sumo"
"/var/lib/otelcol-sumo/file_storage"
"/var/lib/otelcol-sumo"
"/var/log/otelcol-sumo"
Expand Down
11 changes: 6 additions & 5 deletions assets/services/launchd/com.sumologic.otelcol-sumo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
<string>otelcol-sumo</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/otelcol-sumo</string>
<string>--config</string>
<string>/etc/otelcol-sumo/sumologic.yaml</string>
<string>--config</string>
<string>glob:/etc/otelcol-sumo/conf.d/*.yaml</string>
<string>/usr/share/otelcol-sumo.sh</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>SUMOLOGIC_INSTALLATION_TOKEN</key>
<string></string>
</dict>
<!-- Service user -->
<key>UserName</key>
<string>_otelcol-sumo</string>
Expand Down
2 changes: 1 addition & 1 deletion assets/services/systemd/otelcol-sumo.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=Sumo Logic Distribution for OpenTelemetry Collector

[Service]
ExecStart=/usr/local/bin/otelcol-sumo --config /etc/otelcol-sumo/sumologic.yaml --config "glob:/etc/otelcol-sumo/conf.d/*.yaml"
ExecStart=/usr/share/otelcol-sumo/otelcol-sumo.sh
User=otelcol-sumo
Group=otelcol-sumo
MemoryHigh=2000M
Expand Down
2 changes: 2 additions & 0 deletions ci/verify_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ system_files=(
"usr"
"usr/local"
"usr/local/bin"
"usr/share"
"var"
"var/lib"
"var/log"
Expand All @@ -59,6 +60,7 @@ expected_collector_files=(
"Library/LaunchDaemons/com.sumologic.otelcol-sumo.plist"
"usr/local/bin/otelcol-config"
"usr/local/bin/otelcol-sumo"
"usr/share/otelcol-sumo/otelcol-sumo.sh"
"var/lib/otelcol-sumo"
"var/lib/otelcol-sumo/file_storage"
"var/log/otelcol-sumo"
Expand Down
28 changes: 25 additions & 3 deletions components/otelcol-sumo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ endmacro()
macro(install_otc_service_systemd)
require_variables(
"ASSETS_DIR"
"OTC_SYSTEMD_CONFIG"
"OTC_SYSTEMD_DIR"
)
install_otc_service_script()
install(
FILES "${ASSETS_DIR}/services/systemd/otelcol-sumo.service"
FILES "${ASSETS_DIR}/services/systemd/${OTC_SYSTEMD_CONFIG}"
DESTINATION "${OTC_SYSTEMD_DIR}"
PERMISSIONS
OWNER_READ OWNER_WRITE
Expand All @@ -387,14 +389,34 @@ endmacro()
macro(install_otc_service_launchd)
require_variables(
"ASSETS_DIR"
"OTC_LAUNCHD_CONFIG"
"OTC_LAUNCHD_DIR"
)
install_otc_service_script()
install(
FILES "${ASSETS_DIR}/services/launchd/com.sumologic.otelcol-sumo.plist"
FILES "${ASSETS_DIR}/services/launchd/${OTC_LAUNCHD_CONFIG}"
DESTINATION "${OTC_LAUNCHD_DIR}"
PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
GROUP_READ GROUP_WRITE
COMPONENT otelcol-sumo
)
endmacro()

# e.g. /usr/share/otelcol-sumo/otelcol-sumo.sh
macro(install_otc_service_script)
require_variables(
"ASSETS_DIR"
"OTC_SERVICE_SCRIPT"
"OTC_SHARE_DIR"
)
install(
FILES "${ASSETS_DIR}/${OTC_SERVICE_SCRIPT}"
DESTINATION "${OTC_SHARE_DIR}"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT otelcol-sumo
)
endmacro()
18 changes: 0 additions & 18 deletions install-script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ function setup_config_darwin() {
if [[ -n "${OPAMP_API_URL}" ]]; then
write_opamp_endpoint "${OPAMP_API_URL}"
fi

write_remote_config_launchd "${LAUNCHD_CONFIG}"
fi

if [[ "${EPHEMERAL}" == "true" ]]; then
Expand Down Expand Up @@ -749,22 +747,6 @@ function write_installation_token_launchd() {
fi
}

function write_remote_config_launchd() {
local file
readonly file="${1}"

if [[ ! -f "${file}" ]]; then
echo "The LaunchDaemon configuration file is missing: ${file}"
exit 1
fi

# Delete existing ProgramArguments
plutil_delete_key "${file}" "ProgramArguments"

# Create new ProgramArguments with --remote-config
plutil_create_key "${file}" "ProgramArguments" "json" "[ \"/usr/local/bin/otelcol-sumo\", \"--remote-config\", \"opamp:${CONFIG_PATH}\" ]"
}

# write sumologic ephemeral: true to user configuration file
function write_ephemeral_true() {
otelcol-config --enable-ephemeral
Expand Down
3 changes: 3 additions & 0 deletions settings/otc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ macro(set_otc_settings)
# File names
set(OTC_BINARY "otelcol-sumo")
set(OTC_CONFIG_BINARY "otelcol-config")
set(OTC_LAUNCHD_CONFIG "com.sumologic.otelcol-sumo.plist")
set(OTC_SERVICE_SCRIPT "otelcol-sumo.sh")
set(OTC_SUMOLOGIC_CONFIG "sumologic.yaml")
set(OTC_SYSTEMD_CONFIG "otelcol-sumo.service")
set(DOT_KEEP_FILE ".keep")
Expand All @@ -38,6 +40,7 @@ macro(set_otc_settings)
set(OTC_LAUNCHD_DIR "Library/LaunchDaemons")
set(OTC_SYSTEMD_DIR "lib/systemd/system")
set(OTC_LOG_DIR "var/log/otelcol-sumo")
set(OTC_SHARE_DIR "usr/share/otelcol-sumo")

# File paths
set(OTC_BIN_PATH "${OTC_BIN_DIR}/${OTC_BINARY}")
Expand Down

0 comments on commit e567275

Please sign in to comment.