Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions snapraid-runner.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ deletethreshold = 40
; if you want touch to be ran each time
touch = false

[wait]
enabled = false
delay = 60
maxdelays = 9

[waitfiles]
file-1 = wait-for.file
file-2 = also-wait-for.file

[logging]
; logfile to write to, leave empty to disable
file = snapraid.log
Expand Down
29 changes: 28 additions & 1 deletion snapraid-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ 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", "wait", "waitfiles"]
config = dict((x, defaultdict(lambda: "")) for x in sections)
for section in parser.sections():
for (k, v) in parser.items(section):
config[section][k] = v.strip()

int_options = [
("snapraid", "deletethreshold"), ("logging", "maxsize"),
("wait", "delay"), ("wait", "maxdelays"),
("scrub", "percentage"), ("scrub", "older-than"), ("email", "maxsize"),
]
for section, option in int_options:
Expand All @@ -163,10 +164,14 @@ def load_config(args):
config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true")
config["email"]["short"] = (config["email"]["short"].lower() == "true")
config["snapraid"]["touch"] = (config["snapraid"]["touch"].lower() == "true")
config["wait"]["enabled"] = (config["wait"]["enabled"].lower() == "true")

if args.scrub is not None:
config["scrub"]["enabled"] = args.scrub

if args.ignorediff is not None:
config["snapraid"]["deletethreshold"] = -1


def setup_logger():
log_format = logging.Formatter(
Expand Down Expand Up @@ -210,6 +215,9 @@ def main():
parser.add_argument("--no-scrub", action='store_false',
dest='scrub', default=None,
help="Do not scrub (overrides config)")
parser.add_argument("--ignore-diff-threshold", action='store_true',
dest='ignorediff', default=None,
help="Sync if diff threshold exceeded (overrides config)")
args = parser.parse_args()

if not os.path.exists(args.conf):
Expand Down Expand Up @@ -253,6 +261,25 @@ def run():
config["snapraid"]["config"])
finish(False)

if config["wait"]["enabled"]:
wait_delays = 0

while wait_delays <= config["wait"]["maxdelays"]:
wait = False
for key, path in config["waitfiles"].items():
if os.path.isfile(path):
logging.info("Waiting for {}...".format(key))

time.sleep(config["wait"]["delay"])
wait_delays += 1
wait = True
break
if not wait:
break
else:
logging.error("Timed out waiting for {}".format(key))
finish(False);

if config["snapraid"]["touch"]:
logging.info("Running touch...")
snapraid_command("touch")
Expand Down