rackerlabs / auter

Automatic updates for RHEL, Debian, and their derivatives, with the ability to run pre/post hooks & reboot afterwards.
Apache License 2.0
67 stars 18 forks source link

rackerlabs/auter#236 include pre/post script completion status in auter log file. #239

Closed rhodesn closed 2 years ago

rhodesn commented 4 years ago

This commit adds a status line to last-{prep,apply}-* files containing return codes from the pre/post scripts.

It also includes a tidy up of variable names and how writing to the log file is handled.

A new option --ignore-script-failure has been added to continue an auter run even if a pre/post script returns non-zero.

rhodesn commented 4 years ago

Possible output:

[root@29535d0859b5 auter]# cat /var/lib/auter/last-prep-output-default
2020-10-21 11:58:51
STATUS:FAILED:/etc/auter/pre-prep.d/01-pre-prep.sh:1
Last metadata expiration check: 7:49:01 ago on Wed Oct 21 04:09:51 2020.
Dependencies resolved.
================================================================================
 Package                       Architecture Version            Repository  Size
================================================================================
Upgrading:
 zsh-syntax-highlighting       noarch       0.7.1-1.el8        epel        45 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 45 k
DNF will only download packages for the transaction.
Downloading Packages:
zsh-syntax-highlighting-0.7.1-1.el8.noarch.rpm  526 kB/s |  45 kB     00:00
--------------------------------------------------------------------------------
Total                                            75 kB/s |  45 kB     00:00
Complete!
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Failed to set locale, defaulting to C.UTF-8
STATUS:SUCCESS:Package download complete:1
STATUS:SUCCESS:/etc/auter/post-prep.d/01-post-prep.sh:0
STATUS:SUCCESS:/etc/auter/post-prep.d/02-post-prep.sh:0
STATUS:SUCCESS:/etc/auter/post-prep.d/03-post-prep.sh:0
STATUS:SUCCESS:/etc/auter/post-prep.d/04-post-prep.sh:0
STATUS:SUCCESS:/etc/auter/post-prep.d/05-post-prep.sh:0

[root@29535d0859b5 auter]# cat /var/lib/auter/last-apply-output-default
2020-10-21 11:58:57
STATUS:FAILED:/etc/auter/pre-apply.d/01-pre-apply.sh:1
STATUS:FAILED:/etc/auter/pre-apply.d/02-pre-apply.sh:1
STATUS:FAILED:/etc/auter/pre-apply.d/03-pre-apply.sh:1
STATUS:FAILED:/etc/auter/pre-apply.d/04-pre-apply.sh:1
STATUS:FAILED:/etc/auter/pre-apply.d/05-pre-apply.sh:1
Last metadata expiration check: 7:49:08 ago on Wed Oct 21 04:09:51 2020.
Dependencies resolved.
================================================================================
 Package                       Architecture Version            Repository  Size
================================================================================
Upgrading:
 zsh-syntax-highlighting       noarch       0.7.1-1.el8        epel        45 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total size: 45 k
Downloading Packages:
[SKIPPED] zsh-syntax-highlighting-0.7.1-1.el8.noarch.rpm: Already downloaded
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Upgrading        : zsh-syntax-highlighting-0.7.1-1.el8.noarch             1/2
  Cleanup          : zsh-syntax-highlighting-0.7.1-1.el7.noarch             2/2
  Verifying        : zsh-syntax-highlighting-0.7.1-1.el8.noarch             1/2
  Verifying        : zsh-syntax-highlighting-0.7.1-1.el7.noarch             2/2

Upgraded:
  zsh-syntax-highlighting-0.7.1-1.el8.noarch

Complete!
Failed to set locale, defaulting to C.UTF-8
STATUS:SUCCESS:Package updates applied:1
STATUS:FAILED:/etc/auter/post-apply.d/01-post-apply.sh:1
STATUS:FAILED:/etc/auter/post-apply.d/02-post-apply.sh:1
STATUS:FAILED:/etc/auter/post-apply.d/03-post-apply.sh:1
STATUS:FAILED:/etc/auter/post-apply.d/04-post-apply.sh:1
STATUS:FAILED:/etc/auter/post-apply.d/05-post-apply.sh:1
[root@29535d0859b5 auter]#
rhodesn commented 4 years ago

@mark-hyde does the above fit your needs?

mark-hyde commented 4 years ago

Hi Nick, Thanks for this, I'll take a look and see how the new output would interact with existing scripts I have.

mark-hyde commented 4 years ago

I was wondering if you could change the format slightly so we can distinguish between the phases in the initial field e.g.

2020-10-21 11:58:57
PRE_APPLY:SUCCESS:/etc/auter/pre-apply.d/01-pre-apply.sh:0
PRE_APPLY:FAILED:/etc/auter/pre-apply.d/02-pre-apply.sh:1
PRE_APPLY:SUCCESS:/etc/auter/pre-apply.d/03-pre-apply.sh:0
PRE_APPLY:FAILED:/etc/auter/pre-apply.d/04-pre-apply.sh:1
PRE_APPLY:FAILED:/etc/auter/pre-apply.d/05-pre-apply.sh:1
Last metadata expiration check: 7:49:08 ago on Wed Oct 21 04:09:51 2020.
Dependencies resolved.

...
...
Last metadata expiration check: 7:49:08 ago on Wed Oct 21 04:09:51 2020.
Dependencies resolved.
 set locale, defaulting to C.UTF-8
STATUS:SUCCESS:Package updates applied:1
POST_APPLY:SUCCESS:/etc/auter/post-apply.d/01-post-apply.sh:0
POST_APPLY:FAILED:/etc/auter/post-apply.d/02-post-apply.sh:1
POST_APPLY:FAILED:/etc/auter/post-apply.d/03-post-apply.sh:1
POST_APPLY:FAILED:/etc/auter/post-apply.d/04-post-apply.sh:1
POST_APPLY:FAILED:/etc/auter/post-apply.d/05-post-apply.sh:1

This would mean that any existing scripts which grep for e.g. ^STATUS:.*$ would succeed as before, and we could more easily look for specific hook tags when summarising the various phase statuses?

Let me know though if this is too tricky or scope creep!!

mark-hyde commented 4 years ago

I added a PR against your branch in your clone with some ideas for that. https://github.com/nrhodes91/auter/pull/1

reaperzn commented 2 years ago

Hello all, just a quick note on the code here, not sure if it is still a relevant PR and if this is being used or not but please see the coding guidelines on https://github.com/rackerlabs/auter/blob/master/HACKING.md especially with regards to variable names in caps. If this has changed, please could that HACKING.md file also be updated.

Not sure who from RS is still maintaining this package.

mark-hyde commented 2 years ago

There's not anyone officially maintaining it from RS side as far as I know unless @nrhodes91 passed it on to someone other than me. It is still used in places though so would be good to keep it going as it still works as well as it always did.

Does this PR just need the variables changing to upper case before it can be merged with devel?