diff --git a/imageroot/actions/configure-module/70ldap b/imageroot/actions/configure-module/70ldap deleted file mode 100755 index ac9ddaf..0000000 --- a/imageroot/actions/configure-module/70ldap +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2021 Nethesis S.r.l. -# http://www.nethesis.it - nethserver@nethesis.it -# -# This script is part of NethServer. -# -# NethServer is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, -# or any later version. -# -# NethServer is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with NethServer. If not, see COPYING. -# - -domain=$(cat config.json | jq -r '.domain // empty') - -if [ "x$domain" != "x" ]; then - setup-ldap "$domain" -fi diff --git a/imageroot/bin/setup-ldap b/imageroot/bin/setup-ldap index 7b3a1b3..9d6722a 100755 --- a/imageroot/bin/setup-ldap +++ b/imageroot/bin/setup-ldap @@ -30,6 +30,7 @@ import sys import agent import subprocess from agent.ldapproxy import Ldapproxy +import json # Execute occ command # It returns the process exit code and output @@ -41,11 +42,10 @@ def occ(args): def set_ldap(k, v): return occ(["ldap:set-config", "s01", k, v]) -if len(sys.argv) < 2: - print("setup-ldap: no argument given", file=sys.stderr) - sys.exit(1) +with open('config.json', 'r') as cf: + config = json.loads(cf.read()) +cdomain = config.get("domain") -cdomain = sys.argv[1] commands = [] if not cdomain: diff --git a/imageroot/events/user-domain-changed/20configure_ldap b/imageroot/events/user-domain-changed/20configure_ldap new file mode 100755 index 0000000..90a041f --- /dev/null +++ b/imageroot/events/user-domain-changed/20configure_ldap @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json +import sys +import agent +import os + +event = json.load(sys.stdin) + +config = agent.read_envfile("config.env") +nextcloud_domain = config.get('NEXTCLOUD_DOMAIN', '') + +if event.get('domain') != nextcloud_domain: + exit(0) + +agent.run_helper('systemctl', '--user', '-T', 'try-restart', 'nextcloud.service').check_returncode() diff --git a/imageroot/systemd/user/nextcloud-app.service b/imageroot/systemd/user/nextcloud-app.service index 114a820..d0e3252 100644 --- a/imageroot/systemd/user/nextcloud-app.service +++ b/imageroot/systemd/user/nextcloud-app.service @@ -13,6 +13,7 @@ ExecStartPre=/bin/rm -f %t/nextcloud-app.pid %t/nextcloud-app.ctr-id ExecStartPre=-runagent discover-smarthost ExecStartPost=runagent wait-startup ExecStartPost=runagent setup-smtp +ExecStartPost=runagent setup-ldap ExecStart=/usr/bin/podman run --conmon-pidfile %t/nextcloud-app.pid --cidfile %t/nextcloud-app.ctr-id --cgroups=no-conmon --pod-id-file %t/nextcloud.pod-id --replace -d --name nextcloud-app --env-file=%S/state/config.env --env-file=%S/state/smarthost.env -v nextcloud-app-data:/var/www/html -v %S/state/zzz_nethserver.conf:/usr/local/etc/php-fpm.d/zzz_nethserver.conf:z ${NEXTCLOUD_APP_IMAGE} ExecStop=/usr/bin/podman stop --ignore --cidfile %t/nextcloud-app.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/nextcloud-app.ctr-id