|
| 1 | +import os |
| 2 | + |
| 3 | +from leapp.actors import Actor |
| 4 | +from leapp.libraries.stdlib import run, CalledProcessError |
| 5 | +from leapp.reporting import Report, create_report |
| 6 | +from leapp.tags import FirstBootPhaseTag, IPUWorkflowTag |
| 7 | +from leapp.libraries.common.cllaunch import run_on_cloudlinux |
| 8 | +from leapp.models import InstalledControlPanel |
| 9 | + |
| 10 | +from leapp.libraries.common.detectcontrolpanel import DIRECTADMIN_NAME |
| 11 | + |
| 12 | + |
| 13 | +class UpdateDirectAdmin(Actor): |
| 14 | + """ |
| 15 | + Automatically rebuild directadmin. |
| 16 | + """ |
| 17 | + |
| 18 | + name = 'update_directadmin' |
| 19 | + consumes = (InstalledControlPanel,) |
| 20 | + produces = (Report,) |
| 21 | + tags = (FirstBootPhaseTag, IPUWorkflowTag) |
| 22 | + |
| 23 | + @run_on_cloudlinux |
| 24 | + def process(self): |
| 25 | + panel = next(self.consume(InstalledControlPanel), None) |
| 26 | + if panel is None: |
| 27 | + raise StopActorExecutionError(message=("Missing information about the installed web panel.")) |
| 28 | + |
| 29 | + if panel.name != DIRECTADMIN_NAME: |
| 30 | + self.log.debug('DirectAdmin not detected, skip rebuilding') |
| 31 | + return |
| 32 | + |
| 33 | + try: |
| 34 | + run(['/bin/da', 'build', 'all'], checked=True) |
| 35 | + self.log.info('DirectAdmin update was successful') |
| 36 | + except CalledProcessError as e: |
| 37 | + self.log.error( |
| 38 | + 'Command "da build all" finished with exit code {}, ' |
| 39 | + 'the system might be unstable.\n' |
| 40 | + 'Check /usr/local/directadmin/custombuild/custombuild.log, ' |
| 41 | + 'rerun "da build all" after fixing the issues. ' |
| 42 | + 'Contact DirectAdmin support for help.'.format(e.exit_code) |
| 43 | + ) |
0 commit comments