Skip to content

Instantly share code, notes, and snippets.

@gdvalle
Last active January 4, 2016 15:29
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 gdvalle/8640893 to your computer and use it in GitHub Desktop.
Save gdvalle/8640893 to your computer and use it in GitHub Desktop.
murmur upgrade script
#!/usr/bin/env python
import argparse
import urllib
import os
import tarfile
import subprocess
import logging
logging.basicConfig(format='%(asctime)s: %(message)s', level=logging.DEBUG)
parser = argparse.ArgumentParser(description="Upgrade Murmur server.")
parser.add_argument('url', help='Murmur snapshot URL')
parser.add_argument('--path',
default='/opt/murmur',
metavar='/opt/murmur',
help='Murmur path')
parser.add_argument('--restart', help='Run service murmur restart',
default=False,
action="store_true")
args = parser.parse_args()
savepath = '/tmp/'
filename = args.url.split('/')[-1]
EXCLUDE_FILES = ['murmur.sqlite', 'murmur.ini']
def murmur_files(members):
for tarinfo in members:
if tarinfo.name in EXCLUDE_FILES:
pass
else:
yield tarinfo
logging.info('Downloading ' + args.url)
urllib.urlretrieve(args.url, savepath + filename)
logging.info('Saved to ' + savepath + filename)
if not os.path.exists(args.path):
os.makedirs(args.path)
if args.restart:
logging.info('Stopping murmur')
subprocess.call(['service' ,'murmur', 'stop'])
# If the init script is broken...
#subprocess.call(['pkill', 'murmur'])
logging.info('Extracting to ' + args.path)
with tarfile.open(savepath + filename, 'r:bz2') as tar:
for member in tar.getmembers():
try:
firstdir
except:
firstdir = member.name
continue
member.name = member.name.replace(firstdir + '/', '')
print(member.name)
if member.name not in EXCLUDE_FILES:
tar.extract(member, path=args.path)
os.remove(savepath + filename)
if args.restart:
logging.info('Starting murmur')
subprocess.call(['service' ,'murmur', 'start'])
logging.info('Done')
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 syntax=python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment