~ubuntu-repository-cache-charmers/ubuntu-repository-cache/layer-ubuntu-repository-cache

« back to all changes in this revision

Viewing changes to lib/ubuntu_repository_cache/apache.py

  • Committer: mergebot at canonical
  • Author(s): "Haw Loeung"
  • Date: 2021-02-19 09:11:59 UTC
  • mfrom: (308.1.13 ubuntu-repository-cache)
  • Revision ID: mergebot@juju-139df4-prod-is-toolbox-0.canonical.com-20210219091159-pw1o7sgg0r5gev05
Only reload/graceful apache2 when required - LP:1916084

Reviewed-on: https://code.launchpad.net/~hloeung/ubuntu-repository-cache/only-reload-apache2-when-needed-3/+merge/398328
Reviewed-by: Joel Sing <joel.sing@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
208
208
        start()
209
209
 
210
210
 
211
 
def configure_health_check():
212
 
    config = hookenv.config()
213
 
 
214
 
    LOG('Apache enable_healthcheck changed')
215
 
    if not config['enable_healthcheck']:
216
 
        subprocess.check_call(['a2dismod', 'cgi'])
217
 
        LOG('Disabled health check endpoint')
218
 
        return
219
 
 
220
 
    subprocess.check_call(['touch', HEALTH_CHECK_LOG])
221
 
    subprocess.check_call(['chown', HEALTH_CHECK_LOG_OWNER, HEALTH_CHECK_LOG])
222
 
    subprocess.check_call(['a2enmod', 'cgi'])
 
211
def configure_health_check(config=None):
 
212
    if not config:
 
213
        config = hookenv.config()
 
214
 
 
215
    restart_required = False
 
216
 
 
217
    if config.changed('enable_healthcheck'):
 
218
        LOG('Apache enable_healthcheck changed')
 
219
        if config['enable_healthcheck']:
 
220
            cmd = 'a2enmod'
 
221
            action = 'Enabled'
 
222
        else:
 
223
            cmd = 'a2dismod'
 
224
            action = 'Disabled'
 
225
 
 
226
        subprocess.check_call([cmd, 'cgi'])
 
227
        LOG('{} health check endpoint'.format(action))
 
228
        restart_required = True
 
229
 
 
230
    subprocess.call(['touch', HEALTH_CHECK_LOG])
 
231
    subprocess.call(['chown', HEALTH_CHECK_LOG_OWNER, HEALTH_CHECK_LOG])
223
232
 
224
233
    apache_path = unitdata.kv().get('apache-root')
225
234
    healthcheck_path = os.path.join(apache_path, 'health-check')
228
237
    with open('files/health_check.py', 'r') as f:
229
238
        content = f.read()
230
239
    host.write_file(path=healthcheck_script, content=content, perms=0o755)
231
 
    LOG('Enabled health check endpoint')
232
 
    start()
 
240
 
 
241
    return restart_required
233
242
 
234
243
 
235
244
@util.run_as_user('root')