예제 #1
0
파일: dedupv1.py 프로젝트: FinalF/dedupv1
    def on_stop():
        dirty_file = config.get("daemon.dirtyfile")

        if os.path.exists(dirty_file):
            dirty_data = DirtyFileData()
            content = open(dirty_file, "r").read()
            read_sized_message(dirty_data, content)
            if not dirty_data.stopped:
                raise Exception("dedupv1d stopped with errors")
        log_info(options, "\ndedupv1d stopped")
예제 #2
0
파일: dedupv1.py 프로젝트: FinalF/dedupv1
def system_status(monitor, options, config):
    """ function that determines the system status and prints it out
        on stdout
    """
    pid = is_running(config)
    if pid:
        if options.raw:
            print json.dumps({"state": "running"})
        else:
            log_info(options, "dedupv1d running (pid = %s)" % pid)
    else:
        if options.raw:
            print json.dumps({"state": "stopped"})
        else:
            log_info(options, "dedupv1d not running")
예제 #3
0
파일: dedupv1.py 프로젝트: FinalF/dedupv1
def unregister_groups_direct(options, config):
    """ unregisters the groups configured at SCST. This
	function bypasses the information given by the monitor. Therefore
	this function can be used to unregister the groups if dedupv1d is not
	available
    """
    try:
        for (group_name) in scst.get_scst_groups():
            try:
                if options.verbose:
                    log_info(options, "Remove group %s" % (group_name))
                for ip in scst.get_initiator_pattern_in_group(group_name):
                    scst.rm_initiator_pattern_from_group(ip, group_name)

                for device_name in scst.get_devices_in_group(group_name):
                    scst.rm_from_group(device_name, group_name)

                if group_name != "Default":
                    scst.rm_group(group_name)
            except scst.ScstException as e:
                log_error(options,  "Failed to remove group %s: %s" % (group_name, e))
    except scst.ScstException as e:
        log_error(options, "Failed to remove groups: %s" % (e))
예제 #4
0
파일: dedupv1.py 프로젝트: FinalF/dedupv1
def bootstrap_system(dedupv1_root, monitor, options, config):
    """ bootstraps the SCST system
    """
    if not check_root():
        log_error(options, "Permission denied")
        sys.exit(1)

    if is_running(config):
        if options.force:
            log_info(options, "Lock file exists. Forcing start")
            lock_filename = config.get("daemon.lockfile")
            if os.path.exists(lock_filename):
                os.unlink(lock_filename)
        else:
            raise Exception("dedupv1d running")

    daemon_user = config.get("daemon.user")
    daemon_group = config.get("daemon.group")
    daemon_port = config.get("iscsi.port", None)
    daemon_host = config.get("iscsi.host", None)

    check_iscsi = True
    no_iscsi = config.get("daemon.no-iscsi", "False")
    if no_iscsi == "True" or no_iscsi == "true":
        check_iscsi = False

    validate_dedupv1(dedupv1_root, daemon_user, daemon_group)
    scst.check_scst(group_name = daemon_group)
    scst.validate_scst(group_name = daemon_group)
    if check_iscsi:
        # In root mode, use the root group
        if not daemon_group:
            daemon_group = "root"
        iscsi_scst.start_iscsi(group_name = daemon_group,
                port = daemon_port,
                host = daemon_host)
        iscsi_scst.validate_iscsi()
예제 #5
0
파일: dedupv1.py 프로젝트: FinalF/dedupv1
def start_device(dedupv1_root, monitor, options, config, bypass = False):
    """ starts the dedupv1 daemon
    """
    def get_logging_output_file(logging_config_file):
        data = minidom.parse(logging_config_file)
        for ref in data.getElementsByTagName("param"):
                param_name = ref.getAttribute("name")
                if param_name == "filename":
                    return ref.getAttribute("value")
        return None

    def uses_log4cxx():
        return "LOGGING_LOG4CXX" in dir(cfg) and cfg.LOGGING_LOG4CXX

    if is_running(config):
        if options.force:
            log_info(options, "Lock file exists. Forcing start")
            lock_filename = config.get("daemon.lockfile")
            if os.path.exists(lock_filename):
                os.unlink(lock_filename)
        else:
            raise Exception("dedupv1d running")

    check_group = False
    daemon_user = config.get("daemon.user")
    daemon_group = config.get("daemon.group")
    check_iscsi = True
    no_iscsi = config.get("daemon.no-iscsi", "False")
    if no_iscsi == "True" or no_iscsi == "true":
        check_iscsi = False

    if check_root() and not daemon_user and not daemon_group:
        bootstrap_system(dedupv1_root, monitor, options, config)

    # check and start scst
    validate_dedupv1(dedupv1_root, daemon_user, daemon_group)
    scst.validate_scst(group_name = daemon_group)
    if check_iscsi:
        iscsi_scst.validate_iscsi()

    logging_config_file = None
    if uses_log4cxx():
        logging_config_file = config.get("logging")
        if logging_config_file:
            if not os.path.exists(logging_config_file):
                raise Exception("Logging configuration file %s doesn't exists" % logging_config_file)
            if not os.path.isabs(logging_config_file):
                raise Exception("Logging configuration file %s must be absolute" % logging_config_file)

            # We are trying to create to logging output file with the correct user/group data if possible
            logging_output_file = get_logging_output_file(logging_config_file)
            if logging_output_file and uses_log4cxx():
                if not os.path.exists(logging_output_file):
                    execute_cmd("touch %s" % logging_output_file)
                    if daemon_group:
                        execute_cmd("chgrp %s %s" % (daemon_group, logging_output_file))
                        execute_cmd("chmod g+w %s" % (logging_output_file))
    config.check_files()

    if not bypass:
        command = " ".join([os.path.join(dedupv1_root, "bin/dedupv1_starter"), sh_escape(options.configfile)])
    else:
        # bypassing dedupv1_starter. Must run as root
        command = " ".join([os.path.join(dedupv1_root, "bin/dedupv1d"), sh_escape(options.configfile)])

    if options.create:
        command = command + " --create"
    if options.force:
        command = command + " --force"
    if logging_config_file:
        command = command + " --logging \"" + logging_config_file + "\""
    execute_cmd(command, direct_output = True)

    # Here we are doing tricks with starting dots
    if not options.raw:
        print "dedupv1d starting",

    try:
        found_running = False
        i = 0
        while True:
            if not options.raw:
                sys.stdout.write(".")
                sys.stdout.flush()

            run_state = is_running(config, result_if_lockfile_missing = None)
            if run_state != None:
                if run_state and not found_running:
                    found_running = True
                    # Now we have seen the system running
                elif not run_state and found_running:
                    raise Exception("Failed to start dedupv1")
                elif run_state and found_running:
                    if check_connection(monitor):
                        break
                elif not run_state and not found_running:
                    if i > 4:
                        raise Exception("Failed to start dedupv1")
            else:
                # If the system has not written a valid pid for so long, something bad as happened
                if i > 4:
                    raise Exception("Failed to start dedupv1: Failed to check run state")
            time.sleep(2 * i) # backoff
            i = i + 1

        # Cleanup SCST state, e.g. after a crash
        unregister_users_direct(options, config)
        unregister_targets_direct(options, config)
        unregister_groups_direct(options, config)

        register_groups(monitor, options, config)
        register_targets(monitor, options, config)
        register_volumes(monitor, options, config)
        register_users(monitor, options)
        if not options.raw:
            print
            print "dedupv1d started"
    except Exception as e:
        print "dedupv1 start (partly) failed. Shutting down remaining components."

        monitor_exception_raised = False;
        try:
            monitor.read("status", [("change-state", "fast-stop")])
        except:
            monitor_exception_raised = True

        # Normally we use raise, but in this situation
        # We really want raise e, because we want that the original exception
        # is propagated and not any exception from monitor.read() that is here
        # only used as a kind of cleanup
        if monitor_exception_raised:
            raise e
        else:
            # no one destroyed the re-raise exception
            raise