Skip to content

Instantly share code, notes, and snippets.

@mk-fg
Created December 7, 2019 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk-fg/15ba22cb385dc6c9e2383a96e76d0eb2 to your computer and use it in GitHub Desktop.
Save mk-fg/15ba22cb385dc6c9e2383a96e76d0eb2 to your computer and use it in GitHub Desktop.
#!/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