Skip to content

Commit 8ff52c5

Browse files
fix: include missing init.d support
Signed-off-by: Patrick Stephens <pat@fluent.do>
1 parent e18d591 commit 8ff52c5

File tree

7 files changed

+119
-9
lines changed

7 files changed

+119
-9
lines changed

source/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ option(FLB_PREFER_SYSTEM_LIB_NGHTTP2 "Prefer the libnghttp2 system library"
250250
option(FLB_PREFER_SYSTEM_LIB_SQLITE "Prefer the libsqlite3 system library" ${FLB_PREFER_SYSTEM_LIBS})
251251
option(FLB_PREFER_SYSTEM_LIB_ZSTD "Prefer the libzstd system library" ${FLB_PREFER_SYSTEM_LIBS})
252252

253+
# Enable support for CentOS 6 init scripts
254+
option(FLB_CPACK_SYSVINIT "Enable creation of SysV init scripts after installation" No)
255+
253256
# Enable all features
254257
if(FLB_ALL)
255258
# Global
@@ -1480,10 +1483,16 @@ set(CPACK_RPM_PACKAGE_GROUP "System/Daemons")
14801483
set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
14811484

14821485
# Pre/Post install scripts for RPM
1483-
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-pre-install.sh")
1484-
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-post-install.sh")
1485-
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-pre-uninstall.sh")
1486-
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-post-uninstall.sh")
1486+
if(FLB_CPACK_SYSVINIT)
1487+
# Primarily for legacy (CentOS 6/AL 1) support and workarounds
1488+
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cpack/sysv-init-install.sh)
1489+
set(CPACK_RPM_PACKAGE_REQUIRES_POST "initscripts")
1490+
else()
1491+
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-pre-install.sh")
1492+
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-post-install.sh")
1493+
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-pre-uninstall.sh")
1494+
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack/scripts/rpm-post-uninstall.sh")
1495+
endif(FLB_CPACK_SYSVINIT)
14871496

14881497
# Exclude documentation from RPM
14891498
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
chmod a+x /etc/init.d/fluentdo-agent
3+
chkconfig --add fluentdo-agent

source/init/az2-systemd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EnvironmentFile=-/etc/sysconfig/@FLB_OUT_NAME@
1212
EnvironmentFile=-/etc/default/@FLB_OUT_NAME@
1313
EnvironmentFile=-/etc/sysconfig/fluent-bit
1414
EnvironmentFile=-/etc/default/fluent-bit
15-
ExecStart=/opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluentdo-agent.conf
15+
ExecStart=/opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluent-bit.conf
1616
ExecReload=/bin/kill -HUP $MAINPID
1717
Restart=always
1818

source/init/systemd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ EnvironmentFile=-/etc/sysconfig/@FLB_OUT_NAME@
1010
EnvironmentFile=-/etc/default/@FLB_OUT_NAME@
1111
EnvironmentFile=-/etc/sysconfig/fluent-bit
1212
EnvironmentFile=-/etc/default/fluent-bit
13-
ExecStart=/opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluentdo-agent.conf
13+
ExecStart=/opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluent-bit.conf
1414
ExecReload=/bin/kill -HUP $MAINPID
1515
# Allow for infinite restarts
1616
Restart=on-failure

source/init/sysvinit.in

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: fluentdo-agent
4+
# Required-Start: $local_fs $network $named $time $syslog
5+
# Required-Stop: $local_fs $network $named $time $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Description: Init script for FluentDo Agent.
9+
### END INIT INFO
10+
11+
# Adapted from https://github.com/wyhasany/sysvinit-service-generator
12+
# MIT licence: https://github.com/wyhasany/sysvinit-service-generator/blob/master/LICENSE
13+
14+
NAME=fluentdo-agent
15+
SCRIPT="/opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluent-bit.conf"
16+
RUNAS=root
17+
18+
PIDFILE=/var/run/$NAME.pid
19+
LOGFILE=/var/log/$NAME.log
20+
21+
start() {
22+
if [ -f $PIDFILE ] && [ -s $PIDFILE ] && kill -0 "$(cat "$PIDFILE")"; then
23+
echo 'Service already running' >&2
24+
return 1
25+
fi
26+
echo 'Starting service...' >&2
27+
CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
28+
su -c "$CMD" $RUNAS > "$PIDFILE"
29+
# Try with this command line instead of above if not workable
30+
# su -s /bin/sh $RUNAS -c "$CMD" > "$PIDFILE"
31+
32+
sleep 2
33+
PID=$(cat $PIDFILE)
34+
if pgrep -u $RUNAS -f $NAME > /dev/null
35+
then
36+
echo "$NAME is now running, the PID is $PID"
37+
else
38+
echo ''
39+
echo "Error! Could not start $NAME!"
40+
fi
41+
}
42+
43+
stop() {
44+
if [ ! -f "$PIDFILE" ] ; then
45+
echo 'Service not running' >&2
46+
return 1
47+
else
48+
PID="$(cat "$PIDFILE")"
49+
# Here, we're checking if the process command line matches our service's command
50+
if ! ps -p "$PID" -o args= | grep -q "^$SCRIPT$"; then
51+
echo 'Service not running (or PID mismatch)' >&2
52+
echo 'Removing PID file...' >&2
53+
rm -f "$PIDFILE"
54+
return 1
55+
else
56+
echo "Stopping service, the PID is $PID..." >&2
57+
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
58+
echo 'Service stopped' >&2
59+
fi
60+
fi
61+
}
62+
63+
status() {
64+
printf "" "Checking $NAME..."
65+
if [ ! -f "$PIDFILE" ]; then
66+
printf "%s\n" "Service not running"
67+
else
68+
PID=$(cat $PIDFILE)
69+
if ps -p "$PID" -o args= | grep -q "^$SCRIPT$"; then
70+
echo "Running, the PID is $PID"
71+
else
72+
printf "%s\n" "The process appears to be dead but pidfile still exists"
73+
fi
74+
fi
75+
}
76+
77+
case "$1" in
78+
start)
79+
start
80+
;;
81+
stop)
82+
stop
83+
;;
84+
status)
85+
status
86+
;;
87+
restart)
88+
stop
89+
start
90+
;;
91+
*)
92+
echo "Usage: $0 {start|stop|status|restart}"
93+
esac

source/init/upstart.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ start on runlevel [2345]
77
stop on runlevel [!2345]
88

99
respawn
10-
exec /opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluentdo-agent.conf
10+
exec /opt/fluentdo-agent/bin/fluentdo-agent -c /etc/fluentdo-agent/fluent-bit.conf

source/src/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,13 @@ if(FLB_BINARY)
654654
)
655655
install(FILES ${FLB_UPSTART_SCRIPT} COMPONENT binary DESTINATION /etc/init)
656656
install(DIRECTORY DESTINATION COMPONENT binary ${FLB_INSTALL_CONFDIR})
657-
else()
658-
# FIXME: should we support Sysv init script ?
657+
elseif( FLB_CPACK_SYSVINIT )
658+
set(FLB_INIT_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}" )
659+
configure_file(
660+
"${PROJECT_SOURCE_DIR}/init/sysvinit.in"
661+
${PROJECT_SOURCE_DIR}
662+
)
663+
install(FILES ${FLB_INIT_SCRIPT} COMPONENT binary DESTINATION /etc/init/)
659664
endif()
660665

661666
if(FLB_SYSTEM_WINDOWS)

0 commit comments

Comments
 (0)