Exemple #1
0
def main():
    """Main"""

    global __zone, __logger, __time_to_stop

    # If it is Unix like.
    if os.name == "posix":
        process_name = "python3"
        process_title = "Zontromat"

        # Check if the process is already running.
        processes = find_proc(process_name, process_title)
        if len(processes) > 0:
            sys.exit(125)

        # Create process name.
        setproctitle.setproctitle(process_title)

    # Add signal handler.
    signal.signal(signal.SIGINT, interupt_handler)
    signal.signal(signal.SIGTERM, interupt_handler)

    settings = ApplicationSettings.get_instance()

    # Read settings content.
    settings.read()

    # Create log.
    crate_log_file()
    __logger = get_logger(__name__)

    # Wait for settings.
    if not settings.exists:
        settings.create_default()
        __logger.warning(
            "Creating default application settings file. Please edit before next start. ({})"
            .format(settings.path))
        sys.exit(0)

    # Create zone.
    __zone = Zone()

    # Initialize the zone.
    __zone.init()

    # Run the zone.
    __zone.run()