Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for sysv on wazuh-indexer package scripts #554

Closed
Closed
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
13 changes: 8 additions & 5 deletions distribution/packages/src/common/scripts/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if [ "$STOP_REQUIRED" = "true" ]; then
if command -v systemctl >/dev/null; then
systemctl --no-reload stop wazuh-indexer.service

elif command -v service >/dev/null && service wazuh-indexer status >/dev/null 2>&1; then
service wazuh-indexer stop

elif [ -x /etc/init.d/wazuh-indexer ]; then
if command -v invoke-rc.d >/dev/null; then
invoke-rc.d wazuh-indexer stop
Expand All @@ -81,13 +84,13 @@ fi
if [ "$REMOVE_SERVICE" = "true" ]; then
if command -v systemctl >/dev/null; then
systemctl disable wazuh-indexer.service > /dev/null 2>&1 || true
fi

if command -v chkconfig >/dev/null; then
chkconfig --del wazuh-indexer 2> /dev/null || true
fi
# Check for SysV
elif command -v service > /dev/null 2>&1 && command -v chkconfig > /dev/null 2>&1; then
chkconfig wazuh-indexer off > /dev/null 2>&1
chkconfig --del wazuh-indexer > /dev/null 2>&1

if command -v update-rc.d >/dev/null; then
elif command -v update-rc.d >/dev/null; then
update-rc.d wazuh-indexer remove >/dev/null || true
fi
fi
Expand Down
35 changes: 29 additions & 6 deletions distribution/packages/src/deb/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,56 @@ chown -R wazuh-indexer:wazuh-indexer ${pid_dir}
chown -R wazuh-indexer:wazuh-indexer ${tmp_dir}

# Reload systemctl daemon
if command -v systemctl > /dev/null; then
if command -v systemctl >/dev/null 2>&1 && systemctl >/dev/null 2>&1; then
systemctl daemon-reload
fi

# Reload other configs
if command -v systemctl > /dev/null; then
systemctl restart systemd-sysctl.service || true
elif command -v sysctl > /dev/null; then
echo "Load configurations from /etc/sysctl.conf"
sysctl -p
fi

if command -v systemd-tmpfiles > /dev/null; then
systemd-tmpfiles --create wazuh-indexer.conf
else
echo "touch wazuh-indexer.conf"
touch wazuh-indexer.conf
fi

if [ -f $restart_service ]; then
rm -f $restart_service
echo "Restarting wazuh-indexer service..."
if command -v systemctl > /dev/null; then
systemctl restart wazuh-indexer.service > /dev/null 2>&1
# Check for SysV
elif command -v service > /dev/null 2>&1; then
service wazuh-indexer restart > /dev/null 2>&1
fi
exit 0
fi

# Messages
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable wazuh-indexer.service"
echo "### You can start wazuh-indexer service by executing"
echo " sudo systemctl start wazuh-indexer.service"
if command -v systemctl >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable wazuh-indexer.service"
echo "### You can start wazuh-indexer service by executing"
echo " sudo systemctl start wazuh-indexer.service"

elif command -v chkconfig >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig"
echo " sudo chkconfig --add wazuh-indexer"
echo "### You can start wazuh-indexer service by executing"
echo " sudo service wazuh-indexer start"

elif command -v update-rc.d >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig"
echo " sudo update-rc.d wazuh-indexer defaults 95 10"
echo "### You can start wazuh-indexer service by executing"
echo " sudo /etc/init.d/wazuh-indexer start"
fi

exit 0
8 changes: 8 additions & 0 deletions distribution/packages/src/deb/debian/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service
echo "Stop existing wazuh-indexer.service"
systemctl --no-reload stop wazuh-indexer.service
touch $restart_service
elif command -v service >/dev/null && service wazuh-indexer status >/dev/null 2>&1; then
echo "Stop existing wazuh-indexer"
service wazuh-indexer stop
touch $restart_service
fi

if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer-performance-analyzer.service >/dev/null; then
echo "Stop existing wazuh-indexer-performance-analyzer.service"
systemctl --no-reload stop wazuh-indexer-performance-analyzer.service
elif command -v service >/dev/null && service wazuh-indexer-performance-analyzer status >/dev/null 2>&1; then
echo "Stop existing wazuh-indexer-performance-analyzer"
service wazuh-indexer-performance-analyzer stop
fi

# Create user and group if they do not already exist.
Expand Down
9 changes: 9 additions & 0 deletions distribution/packages/src/deb/debian/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ case "$1" in
if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then
echo "Stop existing wazuh-indexer.service"
systemctl --no-reload stop wazuh-indexer.service
# Check for SysV
elif command -v service > /dev/null && service wazuh-indexer status >/dev/null 2>&1; then
echo "Stop existing wazuh-indexer"
service wazuh-indexer stop
fi

if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer-performance-analyzer.service >/dev/null; then
echo "Stop existing wazuh-indexer-performance-analyzer.service"
systemctl --no-reload stop wazuh-indexer-performance-analyzer.service
# Check for SysV
elif command -v service >/dev/null && service wazuh-indexer-performance-analyzer status >/dev/null 2>&1; then
echo "Stop existing wazuh-indexer-performance-analyzer"
service wazuh-indexer-performance-analyzer stop
fi
;;
failed-upgrade)
Expand Down
3 changes: 3 additions & 0 deletions distribution/packages/src/rpm/wazuh-indexer.cicd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ if [ $1 = 1 ];then # Install
# To pick up /usr/lib/sysctl.d/wazuh-indexer.conf
if command -v systemctl > /dev/null 2>&1; then
systemctl restart systemd-sysctl > /dev/null 2>&1 || true
elif command -v sysctl > /dev/null; then
# Load configurations from /etc/sysctl.conf
sysctl -p
fi

fi
Expand Down
64 changes: 58 additions & 6 deletions distribution/packages/src/rpm/wazuh-indexer.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,20 @@ if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/
echo "Stop existing %{name}.service"
systemctl --no-reload stop %{name}.service
touch %{tmp_dir}/wazuh-indexer.restart
# Check for SysV
elif command -v service > /dev/null 2>&1 && service %{name} status 2>/dev/null | grep "is running" > /dev/null 2>&1; then
echo "Stop existing %{name}"
service %{name} stop > /dev/null 2>&1
touch %{tmp_dir}/wazuh-indexer.restart
fi

if command -v systemctl >/dev/null && systemctl is-active %{name}-performance-analyzer.service >/dev/null; then
echo "Stop existing %{name}-performance-analyzer.service"
systemctl --no-reload stop %{name}-performance-analyzer.service
# Check for SysV
elif command -v service > /dev/null 2>&1 && service %{name}}-performance-analyzer status 2>/dev/null | grep "is running" > /dev/null 2>&1; then
echo "Stop existing %{name}-performance-analyzer"
service %{name}-performance-analyzer stop > /dev/null 2>&1
fi
# Create user and group if they do not already exist.
getent group %{name} > /dev/null 2>&1 || groupadd -r %{name}
Expand Down Expand Up @@ -199,10 +209,15 @@ fi
# Reload other configs
if command -v systemctl > /dev/null; then
systemctl restart systemd-sysctl.service || true
elif command -v sysctl > /dev/null; then
# Load configurations from /etc/sysctl.conf
sysctl -p
fi

if command -v systemd-tmpfiles > /dev/null; then
systemd-tmpfiles --create %{name}.conf
else
touch wazuh-indexer.conf
fi

if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then
Expand All @@ -211,26 +226,63 @@ if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then
echo "Restarting wazuh-indexer service..."
systemctl restart wazuh-indexer.service > /dev/null 2>&1
exit 0
# Check for SysV
elif command -v service > /dev/null 2>&1; then
echo "Restarting wazuh-indexer service..."
service wazuh-indexer restart > /dev/null 2>&1
exit 0
elif [ -x /etc/init.d/wazuh-indexer ]; then
if command -v invoke-rc.d >/dev/null; then
invoke-rc.d wazuh-indexer stop || true
invoke-rc.d wazuh-indexer start || true
exit 0
else
/etc/init.d/wazuh-indexer restart || true
exit 0
fi
fi
fi

# Messages
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable wazuh-indexer.service"
echo "### You can start wazuh-indexer service by executing"
echo " sudo systemctl start wazuh-indexer.service"
# Check for systemd presence
if command -v systemctl >/dev/null 2>&1; then
# Messages
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable wazuh-indexer.service"
echo "### You can start wazuh-indexer service by executing"
echo " sudo systemctl start wazuh-indexer.service"

elif command -v chkconfig >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig"
echo " sudo chkconfig --add wazuh-indexer"
echo "### You can start wazuh-indexer service by executing"
echo " sudo service wazuh-indexer start"

elif command -v update-rc.d >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig"
echo " sudo update-rc.d wazuh-indexer defaults 95 10"
echo "### You can start wazuh-indexer service by executing"
echo " sudo /etc/init.d/wazuh-indexer start"
fi
exit 0

%preun
set -e
if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/null; then
echo "Stop existing %{name}.service"
systemctl --no-reload stop %{name}.service
# Check for SysV
elif command -v service > /dev/null 2>&1 && service %{name} status 2>/dev/null | grep "is running" > /dev/null 2>&1; then
echo "Stop existing %{name}"
service %{name} stop > /dev/null 2>&1
fi
if command -v systemctl >/dev/null && systemctl is-active %{name}-performance-analyzer.service >/dev/null; then
echo "Stop existing %{name}-performance-analyzer.service"
systemctl --no-reload stop %{name}-performance-analyzer.service
# Check for SysV
elif command -v service > /dev/null 2>&1 && service %{name}}-performance-analyzer status 2>/dev/null | grep "is running" > /dev/null 2>&1; then
echo "Stop existing %{name}-performance-analyzer"
service %{name}-performance-analyzer stop > /dev/null 2>&1
fi
exit 0

Expand Down