From b0c67ad8cfc46d8721eb4409d08a05116b62b1ee Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Fri, 26 Apr 2024 14:14:27 +0200 Subject: [PATCH] Start conditionnaly import-email-to-piler just once after the installation --- .../actions/configure-module/80start_services | 1 + .../actions/configure-module/91import-email | 13 +++ imageroot/actions/get-configuration/20read | 3 - .../get-configuration/validate-output.json | 11 +-- .../actions/import-email-to-piler/50start | 10 --- imageroot/bin/expand-configuration | 1 + imageroot/bin/import-emails | 4 + imageroot/etc/state-include.conf | 1 + .../user/import-email-to-piler.service | 2 +- imageroot/systemd/user/piler.service | 1 - ui/src/views/Settings.vue | 82 ------------------- 11 files changed, 23 insertions(+), 106 deletions(-) create mode 100755 imageroot/actions/configure-module/91import-email delete mode 100755 imageroot/actions/import-email-to-piler/50start diff --git a/imageroot/actions/configure-module/80start_services b/imageroot/actions/configure-module/80start_services index 75522d9..b0bd09b 100755 --- a/imageroot/actions/configure-module/80start_services +++ b/imageroot/actions/configure-module/80start_services @@ -19,3 +19,4 @@ for ((i = 0; i < 60; i++)); do echo "Waiting for piler-app to be active..." sleep 1 done + diff --git a/imageroot/actions/configure-module/91import-email b/imageroot/actions/configure-module/91import-email new file mode 100755 index 0000000..f609ee6 --- /dev/null +++ b/imageroot/actions/configure-module/91import-email @@ -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 diff --git a/imageroot/actions/get-configuration/20read b/imageroot/actions/get-configuration/20read index 677099b..9c48fd5 100755 --- a/imageroot/actions/get-configuration/20read +++ b/imageroot/actions/get-configuration/20read @@ -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) diff --git a/imageroot/actions/get-configuration/validate-output.json b/imageroot/actions/get-configuration/validate-output.json index 1c09a2a..3bfefb5 100644 --- a/imageroot/actions/get-configuration/validate-output.json +++ b/imageroot/actions/get-configuration/validate-output.json @@ -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", @@ -21,8 +20,7 @@ "lets_encrypt", "mail_server", "is_default_password", - "import_email_is_running", - "piler_is_running" + "import_email_is_running" ], "properties": { "host": { @@ -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" } } } diff --git a/imageroot/actions/import-email-to-piler/50start b/imageroot/actions/import-email-to-piler/50start deleted file mode 100755 index b16c071..0000000 --- a/imageroot/actions/import-email-to-piler/50start +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2024 Nethesis S.r.l. -# SPDX-License-Identifier: GPL-3.0-or-later -# - -# If the control reaches this step, the service can be enabled and started - -systemctl --user start import-email-to-piler.service \ No newline at end of file diff --git a/imageroot/bin/expand-configuration b/imageroot/bin/expand-configuration index f925a94..0cd2b08 100755 --- a/imageroot/bin/expand-configuration +++ b/imageroot/bin/expand-configuration @@ -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) + diff --git a/imageroot/bin/import-emails b/imageroot/bin/import-emails index 5668aad..1078551 100755 --- a/imageroot/bin/import-emails +++ b/imageroot/bin/import-emails @@ -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') diff --git a/imageroot/etc/state-include.conf b/imageroot/etc/state-include.conf index 2efd57a..a22015f 100644 --- a/imageroot/etc/state-include.conf +++ b/imageroot/etc/state-include.conf @@ -4,6 +4,7 @@ # 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 diff --git a/imageroot/systemd/user/import-email-to-piler.service b/imageroot/systemd/user/import-email-to-piler.service index 6756f34..d8cf9bf 100644 --- a/imageroot/systemd/user/import-email-to-piler.service +++ b/imageroot/systemd/user/import-email-to-piler.service @@ -6,5 +6,5 @@ Description= import emails to piler [Service] -Type=simple ExecStart=/usr/local/bin/runagent import-emails +Type=simple diff --git a/imageroot/systemd/user/piler.service b/imageroot/systemd/user/piler.service index ba06813..d61e516 100644 --- a/imageroot/systemd/user/piler.service +++ b/imageroot/systemd/user/piler.service @@ -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 diff --git a/ui/src/views/Settings.vue b/ui/src/views/Settings.vue index 9811e00..cb47b9d 100644 --- a/ui/src/views/Settings.vue +++ b/ui/src/views/Settings.vue @@ -107,41 +107,6 @@ {{ $t("settings.choose_the_mail_server_to_use") }} - - - - - - -