%PDF- %PDF-
Direktori : /proc/3/root/opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/ |
Current File : //proc/3/root/opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/migrate.py |
#!/opt/imunify360/venv/bin/python3 """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see <https://www.imunify360.com/legal/eula> This module import peewee_migrate and apply migrations, for Imunify-AV it's entrypoint for service""" import os import sys from logging import getLogger from peewee import SqliteDatabase from peewee_migrate import migrator import defence360agent.internals.logger from defence360agent.application import app from defence360agent.application.settings import configure from defence360agent.contracts.config import Core from defence360agent.contracts.config import Model as Config from defence360agent.router import Router from defence360agent.subsys import systemd_notifier from defence360agent.utils import importer logger = getLogger(__name__) def apply_migrations(migrations_dirs): """Apply migrations: restructure db, config files, etc.""" logger.info("Applying database migrations...") systemd_notifier.notify(systemd_notifier.AgentState.MIGRATING) router = Router( SqliteDatabase(Config.PATH), migrations_dirs=migrations_dirs, logger=logger, ) # HACK: Migrator uses global unconfigurable LOGGER, # overrride it, to use our logging settings migrator.LOGGER = logger router.run() def _run(*, start_pkg="defence360agent", configure=configure): """Entry point for Imunify-AV service. Apply migrations, and then replace process with {start_pkg}.run module.""" os.umask(Core.FILE_UMASK) configure() defence360agent.internals.logger.reconfigure() systemd_notifier.notify(systemd_notifier.AgentState.READY) apply_migrations(app.MIGRATIONS_DIRS) logger.info("Starting main process...") systemd_notifier.notify(systemd_notifier.AgentState.STARTING) os.execv( sys.executable, [sys.executable, "-m", "{}.run".format(start_pkg)] + sys.argv[1:], ) def run(): """ Entry point for Imunify service, it is common for AV/IM360. """ av_configure = configure suitable_configure = importer.get( module="im360.application.settings", name="configure", default=av_configure, ) start_pkg = ( "defence360agent" if suitable_configure is av_configure else "im360" ) _run(start_pkg=start_pkg, configure=suitable_configure) if __name__ == "__main__": run()