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

Check Installation status for mail and ejabberd #101

Closed
wants to merge 9 commits into from
33 changes: 32 additions & 1 deletion api/migration/read
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
import subprocess
import simplejson
import json
import os
import fcntl, errno

Expand Down Expand Up @@ -240,12 +241,42 @@ def list_apps():
apps.append(get_account_provider_info())
return apps

# Function to check if 'mail' is installed on a given node
def is_mail_installed_on_node(module_data, node_id):
for module in module_data:
if module.get("id") == "mail":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
return True
return False

# Function to check if 'ejabberd' is installed on a given node
def is_ejabberd_installed_on_node(module_data, node_id):
for module in module_data:
if module.get("id") == "ejabberd":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
return True
return False

def get_cluster_status():
bash_command = "/usr/sbin/ns8-action cluster get-cluster-status null"
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
return simplejson.loads(output)

output = json.loads(output.decode('utf-8'))

with open("/var/lib/nethserver/nethserver-ns8-migration/list-modules.json", "r") as file:
module_data = json.load(file)

for node in output["data"]["output"]["nodes"]:
node_id = node["id"]
mail_installed = is_mail_installed_on_node(module_data, node_id)
ejabberd_installed = is_ejabberd_installed_on_node(module_data, node_id)
node["mail_installed"] = mail_installed
node["ejabberd_installed"] = ejabberd_installed

return simplejson.loads(json.dumps(output))

def check_user_domains():
dump = subprocess.Popen(('echo \'{"action": "dump"}\' | /usr/libexec/nethserver/api/system-accounts-provider/read'), stdout=subprocess.PIPE, shell = True)
Expand Down
5 changes: 5 additions & 0 deletions api/migration/update
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ elif [[ "$action" == "abort" ]]; then
if [ -f '/etc/e-smith/events/actions/nethserver-getmail-conf' ]; then
/usr/sbin/ns8-abort nethserver-mail-getmail &> /dev/null
fi
elif [[ "${app_id}" == "nethserver-nethvoice14" ]]; then
# we remove nethvoice-proxy if we have installed it
if [[ -f '/var/lib/nethserver/nethserver-ns8-migration/nethvoice-proxy/bind.env' ]]; then
/usr/sbin/ns8-abort nethvoice-proxy &> /dev/null
fi
fi
/usr/sbin/ns8-abort "${app_id}" &> /dev/null
elif [[ "$action" == "toggle-skip" ]]; then
Expand Down
9 changes: 9 additions & 0 deletions root/usr/sbin/ns8-join
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ else:
account_provider_domain = ""
account_provider_external = ""

# call list-modules to update the list of modules ans save it as a file
list_modules_response = call(api_endpoint, "list-modules", payload['token'], None, False)
if list_modules_response['data']['exit_code'] != 0:
print("Task list-modules has failed:", list_modules_response, file=sys.stderr)
subprocess.run(['/usr/sbin/ns8-leave']) # leave the cluster, we failed to connect to the external domain
sys.exit(1)
with open('/var/lib/nethserver/nethserver-ns8-migration/list-modules.json', 'w') as fp:
json.dump(list_modules_response['data']['output'], fp)

with open('/var/lib/nethserver/nethserver-ns8-migration/environment', 'a') as fp:
fp.write(f"USER_DOMAIN={account_provider_domain}\n")
fp.write(f"ACCOUNT_PROVIDER_EXTERNAL={account_provider_external}\n")
3 changes: 3 additions & 0 deletions root/usr/sbin/ns8-leave
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fi
# clean up agent state directory
find /var/lib/nethserver/nethserver-ns8-migration -type f -not -name index.html | xargs -- rm -vf

# remove the list-modules.json file
rm -f /var/lib/nethserver/nethserver-ns8-migration/list-modules.json

# signal event
/sbin/e-smith/signal-event nethserver-ns8-migration-save
# write log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@

set -e

# read list-modules.json
JSON_FILE="/var/lib/nethserver/nethserver-ns8-migration/list-modules.json"

# Check if nethvoice-proxy > 0 on the node
is_installed=$(jq -r --argjson node_id "$MODULE_NODE_ID" '
.[] | select(.id == "nethvoice-proxy") | .install_destinations[] | select(.node_id == $node_id) | .instances > 0
' "$JSON_FILE")

# if not installed in the node, install first nethvoice-proxy
if [[ "$is_installed" == "false" ]]; then
ns8-bind-app nethvoice-proxy
fi


ns8-bind-app nethserver-nethvoice14

for pid in $(jobs -p); do
wait "${pid}"
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#


set -e

ns8-bind-app nethvoice-proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is included by ns8-bind-app
MODULE_VOLUMES=""
MODULE_IMAGE_URL="nethvoice-proxy"
3 changes: 2 additions & 1 deletion ui/public/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"error_unauthorized": "Access denied. Please verify your credentials.",
"error_certificate_verify_failed": "Certificate verification failed. You can deselect 'TLS validation' to skip this check, if necessary",
"error_no_route_to_host": "Connection to NS8 cluster failed. Please check the IP address or the fully qualified domain name",
"error_port_connection_error": "NS8 cannot connect to the NS7 LDAP service. Ensure that LDAP ports (e.g. 389, 636 of slapd service) are open and accessible from the green zone."
"error_port_connection_error": "NS8 cannot connect to the NS7 LDAP service. Ensure that LDAP ports (e.g. 389, 636 of slapd service) are open and accessible from the green zone.",
"already_installed_on_this_node": "Already installed on this node"
},
"validation": {
"leader_node_empty": "Leader node is required",
Expand Down
46 changes: 43 additions & 3 deletions ui/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,10 @@
v-for="node in clusterNodes"
v-bind:key="node.id"
:value="node.id"
:disabled="!node.online"
:disabled="!node.online || node.mail_installed"
>
{{ getNodeLabel(node) }}
<span v-if="node.mail_installed">{{ getNodeLabel(node) }} {{ $t('dashboard.already_installed_on_this_node') }}</span>
<span v-else>{{ getNodeLabel(node) }}</span>
</option>
</select>
</div>
Expand Down Expand Up @@ -630,6 +631,35 @@
</div>
</div>
</template>
<template v-else-if="currentApp.id === 'nethserver-ejabberd'">
<!-- node selection for email apps -->
<div class="form-group">
<label class="col-sm-5 control-label" for="ejabberd-node">
{{
$t("dashboard.destination_node", {
app: currentApp.name
})
}}
</label>
<div class="col-sm-6">
<select
v-model="appNode"
class="combobox form-control"
id="ejabberd-node"
>
<option
v-for="node in clusterNodes"
v-bind:key="node.id"
:value="node.id"
:disabled="!node.online || node.ejabberd_installed"
>
<span v-if="node.ejabberd_installed">{{ getNodeLabel(node) }} {{ $t('dashboard.already_installed_on_this_node') }}</span>
<span v-else>{{ getNodeLabel(node) }}</span>
</option>
</select>
</div>
</div>
</template>
<template v-else>
<!-- node selection for app-->
<div class="form-group">
Expand Down Expand Up @@ -677,7 +707,7 @@
type="button"
class="btn btn-primary"
@click="startMigrationFromModal"
:disabled="loading.getClusterStatus || !!error.getClusterStatus"
:disabled="loading.getClusterStatus || !!error.getClusterStatus || isSaveDisabled "
>
{{ $t("dashboard.start_migration") }}
</button>
Expand Down Expand Up @@ -1195,6 +1225,16 @@ export default {
};
},
computed: {
isSaveDisabled() {
if (this.currentApp && this.currentApp.id === 'nethserver-mail') {
const selectedNode = this.clusterNodes.find(node => node.id === this.emailNode);
return selectedNode ? selectedNode.mail_installed : false;
} else if (this.currentApp && this.currentApp.id === 'nethserver-ejabberd') {
const selectedNode = this.clusterNodes.find(node => node.id === this.appNode);
return selectedNode ? selectedNode.ejabberd_installed : false;
}
return false;
},
accountProviderApp() {
return this.apps.find((app) => app.id === "account-provider");
},
Expand Down