This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os, sys, glob, re, pathlib as pl | |
src = pl.Path('/etc/systemd/system') | |
dst = pl.Path('/run/systemd/system') | |
for p in map(pl.Path, glob.glob(str(src / '*.slice'))): | |
unit = p.read_text() | |
for line in unit.splitlines(): | |
if re.search(r'\s*IO\w+Max=', line): break | |
else: continue | |
p_run, p_run_tmp = dst / p.name, dst / (p.name + '.tmp') | |
try: | |
with p_run_tmp.open('w') as tmp: | |
for line in unit.strip().split('\n'): | |
m = re.search(r'\s*(IO\w+Max)\s*=\s*(/dev/\S+)\s+(\S.*)$', line) | |
if m: | |
key, dev, limit = m.groups() | |
try: dev = pl.Path(dev).resolve(strict=True).stat().st_rdev | |
except OSError: pass | |
else: line = f'{key}={os.major(dev)}:{os.minor(dev)} {limit.strip()}' | |
tmp.write(f'{line}\n') | |
except: p_run_tmp.unlink(missing_ok=True) | |
else: p_run_tmp.rename(p_run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment