Created
April 25, 2012 08:22
-
-
Save davidstrauss/2488169 to your computer and use it in GitHub Desktop.
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/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