11
sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
13
from charmhelpers.core.hookenv import (
19
from charmhelpers.fetch import (
28
BASEPATH = '/opt/logstash'
31
@hooks.hook('install')
33
log('Installing logstash')
34
packages = ['openjdk-7-jre-headless', 'curl', 'redis-server']
35
apt_update(fatal=True)
36
apt_install(packages, fatal=True)
37
# Place default redis template
44
# TODO : Add flat file support
46
# Fetch the logstash binary
47
filename = config('logstash-source').split('/')[-1]
48
with open('/tmp/{}'.format(filename), 'wb') as handle:
49
response = requests.get(config('logstash-source'), stream=True)
51
for block in response.iter_content(1024):
56
with open('/tmp/{}'.format(filename), 'r') as handle:
61
if sha.hexdigest() != str(config('logstash-sum')):
62
raise ValueError("Provided SUM does not match downloaded sum")
64
log("Verified {} with SHA1 sum of {}".format(filename,
68
def create_skeleton():
69
dirs = ['bin', 'conf.d', 'data']
71
dr = '{}/{}'.format(BASEPATH, d)
72
if not os.path.exists(dr):
77
files = os.listdir('files/conf/')
79
shutil.copy(f, '{}/conf.d/'.format(BASEPATH))
84
pwd.getpwnam('logstash')
86
subprocess.call(['useradd', 'logstash'])
88
if __name__ == "__main__":
89
# execute a hook based on the name the program is called by
90
hooks.execute(sys.argv)