Skip to content

Instantly share code, notes, and snippets.

@davidstrauss
Created April 25, 2012 08:22
Show Gist options
  • Save davidstrauss/2488169 to your computer and use it in GitHub Desktop.
Save davidstrauss/2488169 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import subprocess
import sys
import fcntl
if sys.argv[1] == "is-wrapped":
print("Yes, this is the wrapped version with locking.")
sys.exit(0)
REAL_SYSTEMCTL = "/bin/systemctl"
# Determine the necessary lock type.
op = fcntl.LOCK_SH
if sys.argv[1].startswith("daemon-"):
op = fcntl.LOCK_EX
# Acquire the lock.
fd = open('/tmp/daemon-reload-lock', 'w')
fcntl.flock(fd, op)
# Call the real systemctl with the same arguments.
args = [REAL_SYSTEMCTL] + sys.argv[1:]
code = subprocess.call(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
sys.exit(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment