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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ It supports Windows, Linux and macOS and runs on both python2 and python3.
* Can create a size-limited rotated logfile.
* Can send notification emails after each run or only for failures.
* Can run `scrub` after `sync`
* Can run `smart`. For this to work, you need [smartmontools](https://www.smartmontools.org/wiki/Download).
Most Linux distributions will have it installed installed by default.
* Windows users may install using the packaged .exe installer found at this link or
use [Chocolatey](https://chocolatey.org/) (i.e., `choco install smartmontools`).
* Mac OS users may install using the packaged .dmg installer found at this link or
use [Homebrew](https://brew.sh/) (i.e., `brew install smartmontools`).
* Linux users may check for smartmontools using `smartctl -V`, if not installed use
your distribution's package manager to install `smartmontools`
(e.g., `apt-get install smartmontools`, `yum install smartmontools`, etc.)

## Changelog
### v0.4 (17 Aug 2019)
Expand Down
2 changes: 2 additions & 0 deletions snapraid-runner.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ config = snapraid.conf
deletethreshold = 40
; if you want touch to be ran each time
touch = false
; prints a SMART report of all the disks of the array.
smart = true
Comment on lines +10 to +11
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer for this to be false. Otherwise the script will fail per default if the user doesn't have smartctrl. Also a note Make sure smartctl is in your PATH. in the comment would be helpful.


[logging]
; logfile to write to, leave empty to disable
Expand Down
17 changes: 14 additions & 3 deletions snapraid-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ def tee_thread():
return t


def snapraid_command(command, args={}, *, allow_statuscodes=[]):
def snapraid_command(command, args={}, *, allow_statuscodes=[], log_output = False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO log_ouput is not the right name for this. The output is always logged. It's just that if the user sets the email preference to short, stdout is not included in the email. increase_output_loglevel would be better. Also please follow pep8.

Suggested change
def snapraid_command(command, args={}, *, allow_statuscodes=[], log_output = False):
def snapraid_command(command, args={}, *, allow_statuscodes=[],
increase_output_loglevel=False):

"""
Run snapraid command
Raises subprocess.CalledProcessError if errorlevel != 0
"""
stdout_level = logging.INFO if log_output else logging.OUTPUT
stderr_level = logging.ERROR if log_output else logging.OUTERR
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change the loglevel of stderr here?

arguments = ["--conf", config["snapraid"]["config"]]
for (k, v) in args.items():
arguments.extend(["--" + k, str(v)])
Expand All @@ -61,8 +63,8 @@ def snapraid_command(command, args={}, *, allow_statuscodes=[]):
)
out = []
threads = [
tee_log(p.stdout, out, logging.OUTPUT),
tee_log(p.stderr, [], logging.OUTERR)]
tee_log(p.stdout, out, stdout_level),
tee_log(p.stderr, [], stderr_level)]
for t in threads:
t.join()
ret = p.wait()
Expand Down Expand Up @@ -163,6 +165,7 @@ 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["snapraid"]["smart"] = (config["snapraid"]["smart"].lower() == "true")

if args.scrub is not None:
config["scrub"]["enabled"] = args.scrub
Expand Down Expand Up @@ -257,6 +260,14 @@ def run():
logging.info("Running touch...")
snapraid_command("touch")
logging.info("*" * 60)
if config["snapraid"]["smart"]:
logging.info("Running smart...")
try:
snapraid_command("smart", log_output=True)
except subprocess.CalledProcessError as e:
logging.error(e)
finish(False)
logging.info("*" * 60)

logging.info("Running diff...")
diff_out = snapraid_command("diff", allow_statuscodes=[2])
Expand Down