|
| 1 | +import os |
| 2 | + |
| 3 | +from octoprint_mrbeam.migration.migration_base import ( |
| 4 | + MigrationBaseClass, |
| 5 | +) |
| 6 | + |
| 7 | + |
| 8 | +class Mig003EnableLogrotateBuster(MigrationBaseClass): |
| 9 | + """ |
| 10 | + This migration should add logrotate for the buster image and change the lorotate for the legacy image |
| 11 | + """ |
| 12 | + |
| 13 | + MIGRATE_LOGROTATE_FOLDER = "files/migrate_logrotate/" |
| 14 | + BEAMOS_VERSION_LOW = "0.14.0" |
| 15 | + BEAMOS_VERSION_HIGH = "0.18.2" |
| 16 | + |
| 17 | + def __init__(self, plugin): |
| 18 | + super(Mig003EnableLogrotateBuster, self).__init__(plugin) |
| 19 | + |
| 20 | + @property |
| 21 | + def id(self): |
| 22 | + return "003" |
| 23 | + |
| 24 | + def _run(self): |
| 25 | + self._logger.debug("delete wrong iobeam logrotate") |
| 26 | + self.exec_cmd("sudo rm /etc/logrotate.d/iobeam.logrotate", optional=True) |
| 27 | + |
| 28 | + logrotates = [ |
| 29 | + "analytics", |
| 30 | + "iobeam", |
| 31 | + "mount_manager", |
| 32 | + "mrb_check", |
| 33 | + "mrbeam_ledstrips", |
| 34 | + "netconnectd", |
| 35 | + ] |
| 36 | + for logrotate in logrotates: |
| 37 | + self._logger.debug("enable logrotate of " + logrotate) |
| 38 | + src = os.path.join( |
| 39 | + __package_path__, self.MIGRATE_LOGROTATE_FOLDER, logrotate |
| 40 | + ) |
| 41 | + dst = os.path.join("/etc/logrotate.d/" + logrotate) |
| 42 | + self.exec_cmd("sudo cp {src} {dst}".format(src=src, dst=dst)) |
| 43 | + |
| 44 | + self._logger.debug( |
| 45 | + "restarting logrotate in order for the changed config to take effect" |
| 46 | + ) |
| 47 | + |
| 48 | + # needs to be optional for legacy image, as this is returning 1 instead of 0 |
| 49 | + self.exec_cmd("sudo logrotate /etc/logrotate.conf", optional=True) |
| 50 | + super(Mig003EnableLogrotateBuster, self)._run() |
| 51 | + |
| 52 | + def _rollback(self): |
| 53 | + # no rollback needed |
| 54 | + super(Mig003EnableLogrotateBuster, self)._rollback() |
0 commit comments