~erik-lonroth/charm-haproxy/charmcraft_build

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: mergebot at canonical
  • Author(s): "Tiago Pasqualini da Silva"
  • Date: 2019-09-23 09:11:52 UTC
  • mfrom: (137.1.1 charm-haproxy)
  • Revision ID: mergebot@juju-139df4-prod-is-toolbox-0.canonical.com-20190923091152-ytboqe33ck9k9xmx
Added workload status to HAProxy charm

Reviewed-on: https://code.launchpad.net/~tiago.pasqualini/charm-haproxy/charm-haproxy/+merge/372796
Reviewed-by: Tom Haddon <tom.haddon@canonical.com>
Reviewed-by: Stuart Bishop <stuart.bishop@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    opened_ports,
30
30
    close_port,
31
31
    unit_get,
 
32
    status_set,
32
33
    INFO,
33
34
    DEBUG,
34
35
    )
963
964
# #############################################################################
964
965
def install_hook():
965
966
    # Run both during initial install and during upgrade-charm.
 
967
    status_set('maintenance', 'Installing apt packages')
 
968
 
966
969
    if not os.path.exists(default_haproxy_service_config_dir):
967
970
        os.mkdir(default_haproxy_service_config_dir, 0o600)
968
971
 
987
990
 
988
991
 
989
992
def config_changed():
 
993
    status_set('maintenance', 'Configuring HAProxy')
 
994
 
990
995
    config_data = config_get()
991
996
 
992
997
    ensure_package_status(service_affecting_packages,
1446
1451
# #############################################################################
1447
1452
 
1448
1453
 
 
1454
def assess_status():
 
1455
    '''Assess status of current unit'''
 
1456
    if(service_haproxy("status")):
 
1457
        status_set('active', 'Unit is ready')
 
1458
    else:
 
1459
        status_set('blocked', 'HAProxy is not running')
 
1460
 
 
1461
 
1449
1462
def main(hook_name):
1450
1463
    if hook_name == "install":
1451
1464
        install_hook()
1492
1505
        print("Unknown hook")
1493
1506
        sys.exit(1)
1494
1507
 
 
1508
    assess_status()
 
1509
 
1495
1510
 
1496
1511
if __name__ == "__main__":
1497
1512
    hook_name = os.path.basename(sys.argv[0])