Skip to content

Commit

Permalink
Start conditionnaly import-email-to-piler just once after the install…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
stephdl committed Apr 26, 2024
1 parent e660182 commit 5e8cc0a
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 107 deletions.
1 change: 1 addition & 0 deletions imageroot/actions/configure-module/80start_services
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ for ((i = 0; i < 60; i++)); do
echo "Waiting for piler-app to be active..."
sleep 1
done

13 changes: 13 additions & 0 deletions imageroot/actions/configure-module/91import-email
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

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

# This script is used to start the import-email-to-piler.service
if [[ -f 'sync2pilerdone' ]]; then
echo "## sync2pilerdone file is found, mail already migrated, exiting"
exit 0
fi
systemctl --user start import-email-to-piler.service
3 changes: 0 additions & 3 deletions imageroot/actions/get-configuration/20read
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@ config['is_default_password'] = True if is_found_admin or is_found_auditor else
import_running = subprocess.run(['systemctl', '--user', 'is-active', "import-email-to-piler.service"], capture_output=True, text=True)
config['import_email_is_running'] = True if import_running.stdout.strip() == 'active' else False

piler_running = subprocess.run(['systemctl', '--user', 'is-active', "piler-app.service"], capture_output=True, text=True)
config['piler_is_running'] = True if piler_running.stdout.strip() == 'active' else False

# Dump the configuratio to stdout
json.dump(config, fp=sys.stdout)
11 changes: 2 additions & 9 deletions imageroot/actions/get-configuration/validate-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"lets_encrypt": true,
"mail_server": "xxxxxxxxxxxxxxxxxxxxxxxxx",
"is_default_password": false,
"import_email_is_running": false,
"piler_is_running": true
"import_email_is_running": false
}
],
"type": "object",
Expand All @@ -21,8 +20,7 @@
"lets_encrypt",
"mail_server",
"is_default_password",
"import_email_is_running",
"piler_is_running"
"import_email_is_running"
],
"properties": {
"host": {
Expand Down Expand Up @@ -54,11 +52,6 @@
"type": "boolean",
"title": "Import email is running",
"description": "True if the import email is running"
},
"piler_is_running": {
"type": "boolean",
"title": "Piler is running",
"description": "True if the piler is running"
}
}
}
10 changes: 0 additions & 10 deletions imageroot/actions/import-email-to-piler/50start

This file was deleted.

1 change: 1 addition & 0 deletions imageroot/bin/expand-configuration
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ template = jenv.get_template('config-site.php')
output = template.render(json.loads(json_properties))
with open("piler_etc/config-site.php","w") as f:
f.write(output)

4 changes: 4 additions & 0 deletions imageroot/bin/import-emails
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ if providers:
except Exception as e:
print(f"### Error to import {user} to {os.environ['MODULE_ID']}: {e}", file=sys.stderr)
continue

# write file to avoid re-importing: sync2pilerdone
with open('sync2pilerdone', 'w') as f:
f.write('done')
3 changes: 2 additions & 1 deletion imageroot/etc/state-include.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Restic --files-from: https://restic.readthedocs.io/en/stable/040_backup.html#including-files
#
state/piler.sql
state/sync2pilerdone
volumes/mysql-conf.d
volumes/piler_manticore
volumes/piler_store
volumes/piler_etc
volumes/piler_etc
2 changes: 1 addition & 1 deletion imageroot/systemd/user/import-email-to-piler.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
Description= import emails to piler

[Service]
Type=simple
ExecStart=/usr/local/bin/runagent import-emails
Type=simple
1 change: 0 additions & 1 deletion imageroot/systemd/user/piler.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Description=Podman piler.service
Requires=mariadb-app.service piler-app.service memcached-app.service
Before=mariadb-app.service piler-app.service memcached-app.service

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=-%S/state/environment
Expand Down
82 changes: 0 additions & 82 deletions ui/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,6 @@
{{ $t("settings.choose_the_mail_server_to_use") }}
</template>
</NsComboBox>
<cv-accordion ref="accordion" class="maxwidth mg-bottom">
<cv-accordion-item :open="toggleAccordion[0]">
<template slot="title">{{ $t("settings.advanced") }}</template>
<template slot="content">
<cv-row>
<cv-column>
<cv-row>
<cv-column class="label mg-bottom-md">
<span>{{
$t(
"settings.import_old_emails_to_piler_description"
)
}}</span>
</cv-column>
</cv-row>
<NsButton
v-if="piler_is_running"
kind="secondary"
class="mg-bottom-md"
:icon="Play20"
:disabled="
loading.getConfiguration ||
import_email_is_running ||
loading.configureModule
"
@click="importEmailToPiler"
>
{{ $t("settings.import_email_to_piler") }}
</NsButton>
</cv-column>
</cv-row></template
>
</cv-accordion-item>
</cv-accordion>

<cv-row v-if="error.importEmailToPiler">
<cv-column>
<NsInlineNotification
Expand Down Expand Up @@ -212,7 +177,6 @@ export default {
mail_server: "",
mail_server_URL: [],
import_email_is_running: false,
piler_is_running: false,
is_default_password: false,
isLetsEncryptEnabled: false,
isHttpToHttpsEnabled: false,
Expand Down Expand Up @@ -249,51 +213,6 @@ export default {
next();
},
methods: {
async importEmailToPiler() {
this.loading.getConfiguration = true;
this.error.getConfiguration = "";
const taskAction = "import-email-to-piler";
const eventId = this.getUuid();

// register to task error
this.core.$root.$once(
`${taskAction}-aborted-${eventId}`,
this.importEmailToPilerAborted
);

// register to task completion
this.core.$root.$once(
`${taskAction}-completed-${eventId}`,
this.importEmailToPilerCompleted
);

const res = await to(
this.createModuleTaskForApp(this.instanceName, {
action: taskAction,
extra: {
title: this.$t("action." + taskAction),
isNotificationHidden: true,
eventId,
},
})
);
const err = res[0];

if (err) {
console.error(`error creating task ${taskAction}`, err);
this.errorimportEmailToPiler = this.getErrorMessage(err);
this.loading.importEmailToPiler = false;
return;
}
},
importEmailToPilerAborted(taskResult, taskContext) {
console.error(`${taskContext.action} aborted`, taskResult);
this.error.importEmailToPiler = this.$t("error.generic_error");
this.loading.importEmailToPiler = false;
},
importEmailToPilerCompleted() {
this.getConfiguration();
},
async getConfiguration() {
this.loading.getConfiguration = true;
this.error.getConfiguration = "";
Expand Down Expand Up @@ -348,7 +267,6 @@ export default {
this.mail_server_URL = config.mail_server_URL;
this.is_default_password = config.is_default_password;
this.import_email_is_running = config.import_email_is_running;
this.piler_is_running = config.piler_is_running;
this.loading.getConfiguration = false;
this.focusElement("host");
},
Expand Down

0 comments on commit 5e8cc0a

Please sign in to comment.