EnterpriseDB / barman

Barman - Backup and Recovery Manager for PostgreSQL
https://www.pgbarman.org/
GNU General Public License v3.0
2.14k stars 193 forks source link

Fix receive-wal command exiting with status 0 on errors #977

Closed gustabowill closed 3 months ago

gustabowill commented 3 months ago

Fixes #539 where some errors of the receive-wal command were exiting with a status of zero, indicating success. The referenced issue reports an error when using the --reset option, but the same also occurs with another error when you execute it without the flag and a receive-wal process is already running. This commit fixes both.

In the code, it was just a matter of using the proper logging type and the rest is already handled. Now both errors exit with a status different than zero:

[gustavo@localhost ~]$ barman receive-wal --reset pg17_server
ERROR: Unable to reset the status of receive-wal for server pg17_server. Process is still running
[gustavo@localhost ~]$ echo $?
1
[gustavo@localhost ~]$ barman receive-wal pg17_server
Starting receive-wal for server pg17_server
ERROR: Another receive-wal process is already running for server pg17_server.
[gustavo@localhost ~]$ echo $?
1

References: BAR-230 Closes: #539

barthisrael commented 3 months ago

This is working fine. I'm receiving the expected exit codes in all cases, i.e. 1 on errors, 0 otherwise:

$ barman receive-wal pg17 --reset
ERROR: Unable to reset the status of receive-wal for server pg17. Process is still running

$ echo $?
1

$ barman receive-wal pg17 --create-slot
Creating physical replication slot 'barman_pg17' on server 'pg17'
ERROR: Replication slot 'barman_pg17' already exists

$ echo $?
1

$ barman receive-wal pg17 --drop-slot
Dropping physical replication slot 'barman_pg17' on server 'pg17'
ERROR: Cannot drop replication slot 'barman_pg17' on server 'pg17' because it is in use.

$ echo $?
1

$ barman receive-wal pg17
Starting receive-wal for server pg17
ERROR: Another receive-wal process is already running for server pg17.

$ echo $?
1

$ barman receive-wal pg17 --stop
Stopped process receive-wal(490962)

$ echo $?
0

$ barman receive-wal pg17 --stop
ERROR: Termination of receive-wal failed: no such process for server pg17

$ echo $?
1