52
59
host.service_restart('apache2')
62
@contextlib.contextmanager
64
'''enforce exclusive access to the file to support concurrent updates'''
65
with open(json_status_file(), 'r+') as f:
67
fcntl.lockf(f, fcntl.LOCK_EX)
75
fcntl.lockf(f, fcntl.LOCK_UN)
55
78
@hooks.hook('json_status-relation-joined')
56
79
@hooks.hook('json_status-relation-changed')
57
80
def json_status_relation_joined():
58
81
url = charmhelpers.core.hookenv.relation_get('status-url')
59
82
unit = charmhelpers.core.hookenv.remote_unit()
83
proxy_base = 'json_status-' + unit
60
84
log('status URL is: %s' % url)
62
rid = charmhelpers.core.hookenv.relation_id().replace(':', '_')
65
if os.path.exists(json_status_file):
66
data = json.load(open(json_status_file))
68
'url': '/' + rid + '/',
72
with open(json_status_file, 'w') as f:
78
@hooks.hook('json_status-relation-broken')
79
def json_status_relation_broken():
80
if not os.path.exists(json_status_file):
86
with status_urls() as data:
88
'url': '/' + proxy_base + '/',
91
_add_proxy(proxy_base, url)
94
@hooks.hook('json_status-relation-departed')
95
def json_status_relation_departed():
96
if not os.path.exists(json_status_file()):
83
data = json.load(open(json_status_file))
84
rid = charmhelpers.core.hookenv.relation_id()
87
with open(json_status_file, 'w') as f:
99
unit = charmhelpers.core.hookenv.remote_unit()
101
with status_urls() as data:
95
if not os.path.exists(health_path):
97
if not os.path.exists(json_status_file):
98
with open(json_status_file, 'w') as f:
109
if not os.path.exists(health_path()):
110
os.mkdir(health_path())
111
if not os.path.exists(json_status_file()):
112
with open(json_status_file(), 'w') as f:
102
116
def _conf_file():
103
# apache can't use a ":" in the Include directive so change it to a dash
104
relation = 'juju-' + charmhelpers.core.hookenv.relation_id() + '.conf'
105
return os.path.join(proxy_confs, relation.replace(':', '-'))
117
unit = charmhelpers.core.hookenv.remote_unit().replace('/', '_')
118
relation = charmhelpers.core.hookenv.relation_type()
119
return os.path.join(proxy_confs, 'juju-' + relation + '-' + unit + '.conf')
108
122
@hooks.hook('proxy_logs-relation-joined')
109
123
def proxy_logs_relation_joined():
110
name, _ = charmhelpers.core.hookenv.remote_unit().split('/')
124
name = charmhelpers.core.hookenv.remote_unit()
111
125
addr = charmhelpers.core.hookenv.relation_get('private-address')
113
127
_add_proxy('logs-' + name, 'http://' + addr + '/')
116
@hooks.hook('proxy_logs-relation-broken')
117
def proxy_logs_relation_broken():
130
@hooks.hook('proxy_logs-relation-departed')
131
def proxy_logs_relation_departed():
121
135
if __name__ == "__main__":
122
hooks.execute(sys.argv)
b'\\ No newline at end of file'
136
hooks.execute(sys.argv)