Closed davidcr01 closed 6 months ago
The approach on this issue is to separate the print of the output of the commands and the exit status of the command. To perform this, the following code has been replaced:
From
eval "systemctl start ${1}.service ${debug}"
if [ "${PIPESTATUS[0]}" != 0 ]; then
...
fi
To
service_output=$(eval "systemctl start ${1}.service 2>&1")
e_code="${PIPESTATUS[0]}"
eval "echo \${service_output} ${debug}"
if [ "${e_code}" != 0 ]; then
...
fi
The following code shows the proof of concept of the workaround:
> service_output=$(eval "systemctl status foo 2>&1")
> e_code=$? # same as PIPESTATUS
> echo $service_output
Unit foo.service could not be found.
> echo $e_code
4
After some testing, the print of the output must be modified in order not to print blank lines. It should be taken into account that the systemctl start|restart
command sometimes does not print anything. Because of this, the print of the output should be conditional:
[ -n "$service_output" ] && eval "echo \${service_output} ${debug}"
This command checks if the output is not empty. If it's not, it is printed.
An AIO installation has been performed to test the changes:
Description
In https://github.com/wazuh/wazuh-packages/pull/2861/checks?check_run_id=22354205611, we have observed that the installation didn't stopped when the Wazuh manager service fails:
This must be related to the
debug
variable used in thesystemctl start
command:If the verbose option is used, the output is redirected to a file, which makes the
PIPESTATUS[0]
be always0
. We need to improve this.Validation