diff --git a/snapraid-runner.conf.example b/snapraid-runner.conf.example index dce416f..db59284 100644 --- a/snapraid-runner.conf.example +++ b/snapraid-runner.conf.example @@ -39,3 +39,7 @@ password = enabled = false percentage = 12 older-than = 10 + +[smart] +; set to true to run smart after sync and scrub +enabled = false diff --git a/snapraid-runner.py b/snapraid-runner.py index 5ea96b5..2ec5b0c 100644 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -52,9 +52,14 @@ def snapraid_command(command, args={}, ignore_errors=False): stdout=subprocess.PIPE, stderr=subprocess.PIPE) out = [] - threads = [ - tee_log(p.stdout, out, logging.OUTPUT), - tee_log(p.stderr, [], logging.OUTERR)] + if command == 'smart': + threads = [ + tee_log(p.stdout, out, logging.SMART), + tee_log(p.stderr, [], logging.OUTERR)] + else: + threads = [ + tee_log(p.stdout, out, logging.OUTPUT), + tee_log(p.stderr, [], logging.OUTERR)] for t in threads: t.join() ret = p.wait() @@ -132,7 +137,7 @@ def load_config(args): global config parser = ConfigParser.RawConfigParser() parser.read(args.conf) - sections = ["snapraid", "logging", "email", "smtp", "scrub"] + sections = ["snapraid", "logging", "email", "smtp", "scrub", "smart"] config = dict((x, defaultdict(lambda: "")) for x in sections) for section in parser.sections(): for (k, v) in parser.items(section): @@ -150,6 +155,7 @@ def load_config(args): config["smtp"]["ssl"] = (config["smtp"]["ssl"].lower() == "true") config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true") + config["smart"]["enabled"] = (config["smart"]["enabled"].lower() == "true") config["email"]["short"] = (config["email"]["short"].lower() == "true") config["snapraid"]["touch"] = (config["snapraid"]["touch"].lower() == "true") @@ -165,6 +171,8 @@ def setup_logger(): logging.addLevelName(logging.OUTPUT, "OUTPUT") logging.OUTERR = 25 logging.addLevelName(logging.OUTERR, "OUTERR") + logging.SMART = 26 + logging.addLevelName(logging.SMART, "SMART") root_logger.setLevel(logging.OUTPUT) console_logger = logging.StreamHandler(sys.stdout) console_logger.setFormatter(log_format) @@ -288,6 +296,15 @@ def run(): finish(False) logging.info("*" * 60) + if config["smart"]["enabled"]: + logging.info("Running SMART...") + try: + snapraid_command("smart") + except subprocess.CalledProcessError as e: + logging.error(e) + finish(False) + logging.info("*" * 60) + logging.info("All done") finish(True)