From 6fdf57b7039dc7029394258c2d64050e0e1c057d Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Sat, 20 Mar 2021 09:20:02 +0100 Subject: [PATCH] Prevent daemons to start at installation on debian like systems. --- modoboa_installer/package.py | 16 ++++++++++++++++ run.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/modoboa_installer/package.py b/modoboa_installer/package.py index a734207..8aa764f 100644 --- a/modoboa_installer/package.py +++ b/modoboa_installer/package.py @@ -16,6 +16,12 @@ class Package(object): """Empty method.""" pass + def prepare_system(self): + pass + + def restore_system(self): + pass + class DEBPackage(Package): """DEB based operations.""" @@ -25,6 +31,16 @@ class DEBPackage(Package): def __init__(self, dist_name): super(DEBPackage, self).__init__(dist_name) self.index_updated = False + self.policy_file = "/usr/sbin/policy-rc.d" + + def prepare_system(self): + """Make sure services don't start at installation.""" + with open(self.policy_file, "w") as fp: + fp.write("exit 101\n") + utils.exec_cmd("chmod +x {}".format(self.policy_file)) + + def restore_system(self): + utils.exec_cmd("rm -f {}".format(self.policy_file)) def update(self): """Update local cache.""" diff --git a/run.py b/run.py index 50ae6dd..fa5b8ff 100755 --- a/run.py +++ b/run.py @@ -112,6 +112,7 @@ def main(input_args): "The process can be long, feel free to take a coffee " "and come back later ;)", utils.BLUE) utils.printcolor("Starting...", utils.GREEN) + package.backend.prepare_system() package.backend.install_many(["sudo", "wget"]) ssl_backend = ssl.get_backend(config) if ssl_backend and not args.upgrade: @@ -126,6 +127,7 @@ def main(input_args): scripts.install("postfix", config, args.upgrade) scripts.install("dovecot", config, args.upgrade) system.restart_service("cron") + package.backend.restore_system() utils.printcolor( "Congratulations! You can enjoy Modoboa at https://{} (admin:password)" .format(config.get("general", "hostname")),