Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2019 03:25
What would you like to do?
#!/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'\s*IO\w+Max=', line): break
else: continue
p_run, p_run_tmp = dst /, dst / ( + '.tmp')
with'w') as tmp:
for line in unit.strip().split('\n'):
m ='\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()}'
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