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 11 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")
9 changes: 9 additions & 0 deletions imageroot/actions/create-module/10amend-role
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/bash

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

# we want to delegate the role list-modules to the accountprovider
/usr/local/agent/bin/redis-exec SADD "${AGENT_ID}/roles/accountprovider" "list-modules"
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()

# Get the list of modules that have the realm in the list of modules
with agent.redis_connect(use_replica=True) as rdb:
modules_set = set()
for key, value in rdb.hscan_iter("cluster/module_domains"):
# Iterate over the value and push each keys into modules_set
for element in value.split():
if element.lower() == realm:
# remove string numbers from the key sogo1 -> sogo
modules_set.add(key.rstrip('0123456789'))

# Parse the response and compare the id with the modules_set
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)
18 changes: 18 additions & 0 deletions imageroot/events/module-domain-changed/10reload_services
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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)
if not os.environ["REALM"].lower() in [domain.lower() for domain in event["domains"]]:
sys.exit(0)

agent.run_helper('systemctl', '--user', 'try-reload-or-restart', 'api-moduled.service').check_returncode()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
ExecStartPre=runagent write-user-portal-config