Skip to content

Commit

Permalink
Chronial/snapraid-runner Issue Chronial#3: Add support for smart co…
Browse files Browse the repository at this point in the history
…mmand
  • Loading branch information
k3vmcd committed Sep 24, 2017
1 parent 9a37017 commit 0edb4f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions snapraid-runner.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 21 additions & 4 deletions snapraid-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0edb4f1

Please sign in to comment.