示例#1
0
def autostart_service():
    '''
    Attempt to restart the service if it is not running.
    '''
    kafka = Kafka()

    if kafka.is_running():
        hookenv.status_set('active', 'ready')
        return

    for i in range(3):
        hookenv.status_set(
            'maintenance',
            'attempting to restart kafka, '
            'attempt: {}'.format(i+1)
        )
        kafka.restart()
        if kafka.is_running():
            hookenv.status_set('active', 'ready')
            return

    hookenv.status_set('blocked', 'failed to start kafka; check syslog')
示例#2
0
def restart():
    hookenv.status_set('maintenance', 'Rolling restart')
    kafka = Kafka()
    if not kafka.is_running():
        kafka.start()
    else:
        kafka.restart()
    hookenv.open_port(hookenv.config()['port'])
    # set app version string for juju status output
    kafka_version = kafka.version()
    hookenv.application_version_set(kafka_version)
    hookenv.status_set('active', 'ready')
    set_state('kafka.started')