10
subprocess.check_call(['juju-log', '-l', 'INFO', msg])
15
output = subprocess.check_output(['config-get', '--format=json'])
16
return json.loads(output)
19
def _mkdir(dirname, owner="root", group="root", mode=0700):
20
subprocess.check_call(
21
['install', '-o', owner, '-g', group, '-m', oct(mode), '-d', dirname])
25
pkgs = [x for x in config['packages'].split(' ') if x]
26
pkgs.append('python-pip') # required for restish?
28
juju_info('installing apt packages...')
29
subprocess.check_call(['apt-get', 'install', '-y', 'q'] + pkgs)
31
juju_info('installing restish...')
32
restish = 'restish==%s' % config['restish_version']
33
subprocess.check_call(['pip', 'install', restish])
35
juju_info('grabbing service from bzr...')
36
args = ['bzr', 'branch']
37
rev = config['revno'].strip()
39
args.extend(['-r', rev])
40
args.append(config['branch'])
41
args.append(config['install_root'])
42
_mkdir(config['install_root'])
43
subprocess.check_call(args)
48
conf = '/etc/init/%s.sh' % service
49
if os.path.exists(conf):
51
subprocess.check_call(['service', 'restart', service])
52
except subprocess.CalledProcessError:
53
# if it wasn't running, restart fails, so just try to start
54
subprocess.check_call(['service', 'start', service])
59
conf = '/etc/init/%s.sh' % service
60
if os.path.exists(conf):
61
subprocess.check_call(['service', 'stop', service])
65
hook = os.path.basename(sys.argv[0])
66
juju_info("Running hook: %s" % hook)
68
hook_py = hook.replace('-', '_')
70
if hook_py not in funcs:
71
print("Unknown hook: %s" % hook)
75
return funcs[hook_py](config)
78
if __name__ == '__main__':