Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to manage Samba DC service based on domain change event #39

Merged
merged 14 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ images=()

repobase="${REPOBASE:-ghcr.io/nethserver}"
reponame="ubuntu-samba"
user_manager_version=v0.6.0
user_manager_version=v0.7.0

container="ubuntu-working-container"
# Prepare a local Ubuntu-based samba image
Expand Down
5 changes: 1 addition & 4 deletions imageroot/actions/configure-module/80start_amld
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,5 @@ trx.publish(agent_id + '/event/service-users-admin-changed', json.dumps({
}))
trx.execute()

# Write domain in config.json file for the UI
with open(f'{agent_install_dir}/api-moduled/public/config.json', 'w+') as f:
json.dump({"domain": domain}, f)

# we write api-moduled/public/config.json when the service starts
agent.run_helper("systemctl", "-T", "--user", "enable", "--now", "api-moduled.service")
40 changes: 40 additions & 0 deletions imageroot/bin/write-user-portal-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import sys
import json
import agent
import agent.tasks
import os
import json


agent_install_dir = os.environ['AGENT_INSTALL_DIR']
# realm is mandatory we do not need to test it
realm = os.environ["REALM"].lower()

with agent.redis_connect(use_replica=True) as rdb:
modules_set = set()
# Generate the set of image ids of modules bound to us (Samba domain)
for key, value in rdb.hscan_iter("cluster/module_domains"):
# Iterate over the value and push each keys into modules_set
# check if our realm matches
if realm in value.split():
# remove string numbers from the key sogo1 -> sogo
modules_set.add(key.rstrip('0123456789'))

# Translate the image identifiers in module_set into human readable strings
response = agent.tasks.run(agent_id='cluster', action='list-modules', data=None)
names_set=set()
for item in response['output']:
if item.get('id') in modules_set:
names_set.add(item.get('name'))

# Write modules set to a JSON file
data = {"domain": realm, "services": list(names_set)}

with open(f'{agent_install_dir}/api-moduled/public/config.json', 'w') as file:
json.dump(data, file)
19 changes: 19 additions & 0 deletions imageroot/events/module-domain-changed/10reload_services
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#
import os
import sys
import json
import agent



event = json.load(sys.stdin)
domain = os.environ["REALM"].lower()
if not domain in event["domains"]:
sys.exit(0)

agent.run_helper('write-user-portal-config')
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
ExecStartPre=runagent write-user-portal-config