Last active
August 29, 2015 14:17
-
-
Save bcambel/001d80beaea11e2c3844 to your computer and use it in GitHub Desktop.
Compare the MD5 of 2 files
This file contains hidden or 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
| import socket | |
| import subprocess | |
| current = "/var/www/star-track/star-tracker.jar" | |
| latest = "/opt/star-track/release/star-tracker.jar" | |
| def get_md5(f): | |
| proc = subprocess.Popen(["md5sum", f],stdout=subprocess.PIPE) | |
| result_str = "" | |
| md5 = "" | |
| for line in iter(proc.stdout.readline, ''): | |
| result_str = line | |
| try: | |
| md5 = result_str.split(" ")[0] | |
| except: | |
| pass | |
| return md5 | |
| if __name__ == "__main__": | |
| machine = socket.gethostname() | |
| current_md5 = get_md5(current) | |
| latest_md5 = get_md5(latest) | |
| print machine, current_md5, latest_md5 | |
| if current_md5 != latest_md5: | |
| print "CHANGE TIME: {} != {}".format(current_md5, latest_md5) | |
| subprocess.call(["cp", latest, current]) | |
| subprocess.call(["supervisorctl", "restart", "prod_startrack"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment