sensu / sensu-omnibus

Build full-stack platform-specific Sensu packages
12 stars 16 forks source link

AIX: pre_rm script fails when installing bff package #241

Closed liudasbk closed 6 years ago

liudasbk commented 6 years ago

Installation of Sensu package on AIX fails on pre_rm script. Following command is used to install the package: installp -aYF -Q -d /var/tmp/sensu-1.1.2-1.powerpc.bff sensu

           +-----------------------------------------------------------------------------+
                         Installing Software...
           +-----------------------------------------------------------------------------+

           installp: APPLYING software for:
        sensu 1.1.2.1

           Failure occurred during pre_rm.
           Failure occurred during rminstal.
           Finished processing all filesets.  (Total time:  1 secs).

There is a function in sensu.pre_rm script to stop sensu-client. To ignore failure of stopsrc, when Sensu is not installed or not running, it sets +e flag, however looks like this is only valid within the function as the script fails because of non-zero return code of stop_sensu_services.

stop_sensu_services()
{
  set -e
  set +e
  stopsrc -s sensu-client > /dev/null 2>&1
}
% /bin/sh -x ./sensu.pre_rm; echo $?
+ set -e
+ + basename ./sensu.pre_rm
PROGNAME=sensu.pre_rm
+ stop_sensu_services
1

This is because set +e is in effect within the function and it does not exit after stopsrc fails, but it exits because function stop_sensu_services fails (non-zero return code and set -e is set for the script). Looks like this is different behavior than bash where set +e in function is global.

The simple fix would be changing stop_sensu_services for AIX to

stop_sensu_services()
{
  stopsrc -s sensu-client > /dev/null 2>&1 || true
}
% /bin/sh -x ./sensu.pre_rm; echo $?
+ set -e
+ + basename ./sensu.pre_rm
PROGNAME=sensu.pre_rm
+ stop_sensu_services
+ sleep 6
+ exit 0
0