Skip to content

Commit

Permalink
Fix typo on debian prerm
Browse files Browse the repository at this point in the history
Ensure the init.d script is always executable

Improve validations
  • Loading branch information
QU3B1M committed Jan 8, 2025
1 parent f4cf658 commit c5996a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion distribution/packages/src/common/init.d/wazuh-indexer
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ start() {
cd $OPENSEARCH_HOME || exit
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
if command -v systemctl; then
if command -v daemon; then
daemon --user wazuh-indexer --pidfile $pidfile $exec -p $pidfile -d
else
runuser wazuh-indexer --shell="/bin/bash" --command="$exec -p $pidfile -d"
Expand Down
19 changes: 9 additions & 10 deletions distribution/packages/src/deb/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ chown -R wazuh-indexer:wazuh-indexer ${data_dir}
chown -R wazuh-indexer:wazuh-indexer ${pid_dir}
chown -R wazuh-indexer:wazuh-indexer ${tmp_dir}

# Check if the script is executed on upgrade
is_upgrade=false
if [ -n "$2" ]; then
is_upgrade=true
fi

export OPENSEARCH_PATH_CONF=${OPENSEARCH_PATH_CONF:-${config_dir}}
# Apply Performance Analyzer settings, as per https://github.com/opensearch-project/opensearch-build/blob/2.18.0/scripts/pkg/build_templates/current/opensearch/deb/debian/postinst#L28-L37
if ! grep -q '## OpenSearch Performance Analyzer' "$OPENSEARCH_PATH_CONF/jvm.options"; then
Expand Down Expand Up @@ -66,18 +60,23 @@ if command -v systemd-tmpfiles > /dev/null 2>&1 && systemctl > /dev/null 2>&1; t
systemd-tmpfiles --create wazuh-indexer.conf > /dev/null 2>&1
fi

# Check if its upgrade and restart service
if [ "$is_upgrade" = true ]; then
if command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then
# Ensure the script is executable
chmod +x /etc/init.d/wazuh-indexer > /dev/null 2>&1
fi

# Check if the script is executed on upgrade
if [ -n "$2" ]; then
if [ -f $restart_service ]; then
echo "Restarting wazuh-indexer service after upgrade"
rm -f $restart_service
if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then
systemctl restart wazuh-indexer.service > /dev/null 2>&1
elif command -v service > /dev/null 2>&1; then
service wazuh-indexer restart > /dev/null 2>&1
elif command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then
/etc/init.d/wazuh-indexer restart > /dev/null 2>&1
fi
rm -f $restart_service
else
echo "### NOT restarting wazuh-indexer service after upgrade"
echo "### You can start wazuh-indexer service by executing"
Expand All @@ -102,7 +101,7 @@ else
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 2>&1; then
elif command -v update-rc.d > /dev/null 2>&1 && command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then
echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using update-rc.d"
echo " sudo update-rc.d wazuh-indexer defaults 95 10"
echo "### You can start wazuh-indexer service by executing"
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/deb/debian/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case "$1" in
;;
remove)
echo "Running Wazuh Indexer Pre-Removal Script"
# Stop existin wazuh-indexer.service
# Stop existing wazuh-indexer.service
if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1 && systemctl is-active wazuh-indexer.service > /dev/null 2>&1; then
echo "Stop existing wazuh-indexer.service"
systemctl --no-reload stop wazuh-indexer.service > /dev/null 2>&1
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/rpm/wazuh-indexer.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ fi

if [ $1 = 2 ]; then
if [ -f %{restart_service} ]; then
rm -f %{restart_service}
echo "Restarting wazuh-indexer service after upgrade"
rm -f %{restart_service}
if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then
systemctl restart wazuh-indexer.service > /dev/null 2>&1
elif command -v service > /dev/null 2>&1; then
Expand Down

0 comments on commit c5996a4

Please sign in to comment.