Skip to content

Commit

Permalink
feat(jans-linux-setup): status script optionally accepts service (#10010
Browse files Browse the repository at this point in the history
)

Signed-off-by: Mustafa Baser <[email protected]>
  • Loading branch information
devrimyatar authored Nov 1, 2024
1 parent 462d814 commit 88dc7a1
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions jans-linux-setup/jans_setup/static/scripts/jans_services_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Status:
RUNNING = 'Running'

_JANS_LOCK_SERVICE_ = 'jans-lock'
_KEYCLOAK_ = 'keycloak'
JANS_JETTY_DIR = '/opt/jans/jetty'

HEALTH_ENDPOINTS = {
Expand All @@ -22,7 +23,6 @@ class Status:
'jans-link': ['http://localhost:9091/jans-link/sys/health-check', []],
}


services_status = {}

def get_endpint_data(endpoint, status_code_only=False):
Expand Down Expand Up @@ -55,24 +55,35 @@ def check_jans_service_health(endpoint, status_code_only=False):

def get_service_status():

if os.path.exists(os.path.join(JANS_JETTY_DIR, _JANS_LOCK_SERVICE_)):
HEALTH_ENDPOINTS[_JANS_LOCK_SERVICE_] = ['http://localhost:8076/jans-lock/sys/health-check', []]
elif os.path.exists(os.path.join(JANS_JETTY_DIR, 'jans-auth/custom/libs/jans-lock-service.jar')):
HEALTH_ENDPOINTS['jans-auth'][1].append(_JANS_LOCK_SERVICE_)
else:
services_status[_JANS_LOCK_SERVICE_] = Status.NOT_PRESENT

service_list = list(HEALTH_ENDPOINTS.keys())
for jservice in HEALTH_ENDPOINTS:
service_list += HEALTH_ENDPOINTS[jservice][1]
service_list.append(_JANS_LOCK_SERVICE_)
service_list.append(_KEYCLOAK_)

check_services = [sys.argv[1]] if len(sys.argv) > 1 and sys.argv[1] in service_list else []

if (check_services and _JANS_LOCK_SERVICE_ in check_services) or not check_services:
if os.path.exists(os.path.join(JANS_JETTY_DIR, _JANS_LOCK_SERVICE_)):
HEALTH_ENDPOINTS[_JANS_LOCK_SERVICE_] = ['http://localhost:8076/jans-lock/sys/health-check', []]
elif os.path.exists(os.path.join(JANS_JETTY_DIR, 'jans-auth/custom/libs/jans-lock-service.jar')):
HEALTH_ENDPOINTS['jans-auth'][1].append(_JANS_LOCK_SERVICE_)
else:
services_status[_JANS_LOCK_SERVICE_] = Status.NOT_PRESENT

for jservice in HEALTH_ENDPOINTS:
if check_services and jservice not in check_services:
continue
if os.path.exists(os.path.join(JANS_JETTY_DIR, jservice)):
services_status[jservice] = check_jans_service_health(HEALTH_ENDPOINTS[jservice])
else:
services_status[jservice] = Status.NOT_PRESENT

if os.path.exists('/opt/keycloak'):
services_status['keycloak'] = check_jans_service_health(['http://localhost:8083/kc/admin/master/console/', []], True)
else:
services_status['keycloak'] = Status.NOT_PRESENT
if (check_services and _KEYCLOAK_ in check_services) or not check_services:
if os.path.exists('/opt/keycloak'):
services_status[_KEYCLOAK_] = check_jans_service_health(['http://localhost:8083/kc/admin/master/console/', []], True)
else:
services_status[_KEYCLOAK_] = Status.NOT_PRESENT

if __name__ == '__main__':
get_service_status()
Expand Down

0 comments on commit 88dc7a1

Please sign in to comment.