Skip to content

Commit

Permalink
systemd: build: Add sethostname workaround for AmazonLinux2 due to co…
Browse files Browse the repository at this point in the history
…reos/bugs#1272

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Jan 17, 2025
1 parent e9a2f87 commit 2c5a0af
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(FLB_LINUX_ON_AARCH64 On)
add_definitions(-DFLB_LINUX_ON_AARCH64)
endif()

find_program(CAT_EXEC cat)
if (CAT_EXEC)
set(RELEASE_FILE "/etc/system-release")
if (EXISTS ${RELEASE_FILE})
execute_process(COMMAND ${CAT_EXEC} ${RELEASE_FILE}
OUTPUT_VARIABLE CAT_SYSTEM_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "##### cat /etc/system-release -- OK")

if (CAT_SYSTEM_RELEASE STREQUAL "Amazon Linux release 2 (Karoo)")
set(FLB_AMAZON_LINUX2 On)
add_definitions(-DFLB_AMAZON_LINUX2)
endif()
endif()
endif()
endif()

# Update CFLAGS
Expand Down
12 changes: 12 additions & 0 deletions init/az2-sethostname.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Set Hostname Workaround coreos/bugs#1272
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "/usr/bin/hostnamectl set-hostname $(curl -s http://169.254.169.254/latest/meta-data/hostname)"

[Install]
WantedBy=multi-user.target
17 changes: 17 additions & 0 deletions init/az2-systemd.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=@FLB_PROG_NAME@
Documentation=https://docs.fluentbit.io/manual/
Requires=network.target
After=network.target
Requires=sethostname.service
After=sethostname.service

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/@FLB_OUT_NAME@
EnvironmentFile=-/etc/default/@FLB_OUT_NAME@
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/@FLB_OUT_NAME@ -c /@CMAKE_INSTALL_SYSCONFDIR@/@FLB_OUT_NAME@/@[email protected]
Restart=always

[Install]
WantedBy=multi-user.target
31 changes: 24 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,30 @@ if(FLB_BINARY)
endif()

if(SYSTEMD_UNITDIR)
set(FLB_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.service")
configure_file(
"${PROJECT_SOURCE_DIR}/init/systemd.in"
${FLB_SYSTEMD_SCRIPT}
)
install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
if (FLB_AMAZON_LINUX2)
set(FLB_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.service")
configure_file(
"${PROJECT_SOURCE_DIR}/init/az2-systemd.in"
${FLB_SYSTEMD_SCRIPT}
)
install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
set(FLB_HOSTNAME_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/sethostname.service")
configure_file(
"${PROJECT_SOURCE_DIR}/init/az2-sethostname.in"
${FLB_HOSTNAME_SYSTEMD_SCRIPT}
)
install(FILES ${FLB_HOSTNAME_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
else()
set(FLB_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.service")
configure_file(
"${PROJECT_SOURCE_DIR}/init/systemd.in"
${FLB_SYSTEMD_SCRIPT}
)
install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
endif()
elseif(IS_DIRECTORY /usr/share/upstart)
set(FLB_UPSTART_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.conf")
configure_file(
Expand Down

0 comments on commit 2c5a0af

Please sign in to comment.