cmdeploy: flag to disable postfix + dovecot for migration

This commit is contained in:
missytake
2024-10-16 11:21:09 +02:00
parent 737ab54bf2
commit 15f30d8841
3 changed files with 19 additions and 10 deletions

View File

@@ -479,10 +479,11 @@ def deploy_mtail(config):
)
def deploy_chatmail(config_path: Path) -> None:
def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
"""Deploy a chat-mail instance.
:param config_path: path to chatmail.ini
:param disable_mail: whether to disable postfix & dovecot
"""
config = read_config(config_path)
check_config(config)
@@ -624,19 +625,19 @@ def deploy_chatmail(config_path: Path) -> None:
# because it creates authentication socket
# required by Postfix.
systemd.service(
name="Start and enable Dovecot",
name="disable dovecot for now" if disable_mail else "Start and enable Dovecot",
service="dovecot.service",
running=True,
enabled=True,
restarted=dovecot_need_restart,
running=False if disable_mail else True,
enabled=False if disable_mail else True,
restarted=dovecot_need_restart if not disable_mail else False,
)
systemd.service(
name="Start and enable Postfix",
name="disable postfix for now" if disable_mail else "Start and enable Postfix",
service="postfix.service",
running=True,
enabled=True,
restarted=postfix_need_restart,
running=False if disable_mail else True,
enabled=False if disable_mail else True,
restarted=postfix_need_restart if not disable_mail else False,
)
systemd.service(

View File

@@ -52,6 +52,12 @@ def run_cmd_options(parser):
action="store_true",
help="don't actually modify the server",
)
parser.add_argument(
"--disable-mail",
dest="disable_mail",
action="store_true",
help="install/upgrade the server, but disable postfix & dovecot for now"
)
def run_cmd(args, out):
@@ -64,6 +70,7 @@ def run_cmd(args, out):
env = os.environ.copy()
env["CHATMAIL_INI"] = args.inipath
env["CHATMAIL_DISABLE_MAIL"] = "True" if args.disable_mail else ""
deploy_path = importlib.resources.files(__package__).joinpath("deploy.py").resolve()
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path} -y"

View File

@@ -11,8 +11,9 @@ def main():
"CHATMAIL_INI",
importlib.resources.files("cmdeploy").joinpath("../../../chatmail.ini"),
)
disable_mail = bool(os.environ.get('CHATMAIL_DISABLE_MAIL'))
deploy_chatmail(config_path)
deploy_chatmail(config_path, disable_mail)
if pyinfra.is_cli: