|
26 | 26 | import pkg.no_site_packages |
27 | 27 | import pkg.smf as smf |
28 | 28 | import pkg.client.pkgdefs as pkgdefs |
| 29 | +import bemgmt |
29 | 30 | import smf_include |
30 | 31 | import os |
31 | 32 | import subprocess |
@@ -121,8 +122,7 @@ def start(): |
121 | 122 | pkg_status = subprocess.call(cmd) |
122 | 123 | if pkg_status != pkgdefs.EXIT_LOCKED: |
123 | 124 | break |
124 | | - print('Image locked, sleeping for {0} seconds'.format(wait_secs), |
125 | | - flush=True) |
| 125 | + print(f'Image locked, sleeping for {wait_secs} seconds', flush=True) |
126 | 126 | time.sleep(wait_secs) |
127 | 127 |
|
128 | 128 | if pkg_status == pkgdefs.EXIT_NOP: |
@@ -154,15 +154,24 @@ def start(): |
154 | 154 | new_be_activated = pkgplan['activate-be'] |
155 | 155 | if new_be_created and new_be_activated and auto_reboot: |
156 | 156 | if check_before_reboot: |
157 | | - print('Running reboot-check-hook {0}'.format(reboot_hook)) |
| 157 | + print(f'Running reboot-check-hook {reboot_hook}') |
158 | 158 | exitcode, output = subprocess.getstatusoutput(reboot_hook) |
159 | 159 | if exitcode != 0: |
| 160 | + print(output) |
| 161 | + bename = pkgplan['be-name'] |
| 162 | + print(f'Reboot Hook failed {exitcode}, removing {bename}') |
| 163 | + # Remove the BE as a future auto-update may create the same BE. |
| 164 | + # Leaving it risks it becoming stale and surprising the |
| 165 | + # admin on a manual reboot. |
| 166 | + try: |
| 167 | + bemgmt.BEManager().destroy(bename) |
| 168 | + except bemgmt.be_errors.BeMgmtError as e: |
| 169 | + print(f"BE destroy failed: {e}") |
| 170 | + pass |
160 | 171 | message = f'Reboot Hook failed {exitcode}, see service log' |
161 | 172 | smf_include.smf_method_exit(smf_include.SMF_EXIT_DEGRADED, |
162 | 173 | 'reboot-check-hook-failed', |
163 | 174 | message) |
164 | | - print('Reboot hook output follows:') |
165 | | - print(output) |
166 | 175 |
|
167 | 176 | print('Reboot after auto update') |
168 | 177 | msg = myfmri + ' : automatic reboot after update' |
|
0 commit comments