"""
 *
 * This file is part of rasdaman community.
 *
 * Rasdaman community 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.
 *
 * Rasdaman community 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 rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2003 - 2016 Peter Baumann / rasdaman GmbH.
 *
 * For more information please see <http://www.rasdaman.org>
 * or contact Peter Baumann via <baumann@rasdaman.com>.
 *
"""
import atexit

from config_manager import ConfigManager
from util.executor import Executor
from util.history import History
from util.distrowrapper import DistroWrapper
from util.servicemgr import RasdamanLocalService, TomcatService, PostgresService, RasdamanService
import util.log

history = History(ConfigManager.history_file)
util.log.history = history
executor = Executor(history)

linux_distro = DistroWrapper()
rasdaman_service = RasdamanLocalService(executor)
rasdaman_system_service = RasdamanService(executor)
tomcat_service = TomcatService(executor)
postgres_service = PostgresService(executor)


def at_exit():
    """
    Executed before the script finishes. We write the execution history to a file
    """
    history.write_history()


atexit.register(at_exit)
