@@ -15,7 +15,8 @@ LTCOMMAND = xfs_scrub
INSTALL_SCRUB = install-scrub
XFS_SCRUB_ALL_PROG = xfs_scrub_all
XFS_SCRUB_FAIL_PROG = xfs_scrub_fail
-XFS_SCRUB_ARGS = -b -n
+XFS_SCRUB_ARGS = -n
+XFS_SCRUB_SERVICE_ARGS = -b
ifeq ($(HAVE_SYSTEMD),yes)
INSTALL_SCRUB += install-systemd
SYSTEMD_SERVICES=\
@@ -113,6 +114,7 @@ xfs_scrub_all: xfs_scrub_all.in $(builddefs)
$(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
-e "s|@scrub_svcname@|$(scrub_svcname)|g" \
-e "s|@pkg_version@|$(PKG_VERSION)|g" \
+ -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \
-e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" < $< > $@
$(Q)chmod a+x $@
@@ -132,6 +134,7 @@ install: $(INSTALL_SCRUB)
%.service: %.service.in $(builddefs)
@echo " [SED] $@"
$(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
+ -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \
-e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" \
-e "s|@pkg_libexec_dir@|$(PKG_LIBEXEC_DIR)|g" \
< $< > $@
@@ -22,7 +22,7 @@ RequiresMountsFor=%f
[Service]
Type=oneshot
Environment=SERVICE_MODE=1
-ExecStart=@sbindir@/xfs_scrub @scrub_args@ -M /tmp/scrub/ %f
+ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ @scrub_args@ -M /tmp/scrub/ %f
SyslogIdentifier=%N
# Run scrub with minimal CPU and IO priority so that nothing else will starve.
@@ -162,9 +162,10 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
if terminate:
return
- # Try it the systemd way
+ # Run per-mount systemd xfs_scrub service only if we ourselves
+ # are running as a systemd service.
unitname = path_to_serviceunit(path)
- if unitname is not None:
+ if unitname is not None and 'SERVICE_MODE' in os.environ:
ret = systemctl_start(unitname, killfuncs)
if ret == 0 or ret == 1:
print("Scrubbing %s done, (err=%d)" % (mnt, ret))
@@ -175,8 +176,12 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
if terminate:
return
- # Invoke xfs_scrub manually
+ # Invoke xfs_scrub manually if we're running in the foreground.
+ # We also permit this if we're running as a cronjob where
+ # systemd services are unavailable.
cmd = ['@sbindir@/xfs_scrub']
+ if 'SERVICE_MODE' in os.environ:
+ cmd += '@scrub_service_args@'.split()
cmd += '@scrub_args@'.split()
cmd += [mnt]
ret = run_killable(cmd, None, killfuncs)