Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions cmdeploy/src/cmdeploy/cmdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,24 @@ def run_cmd(args, out):
try:
retcode = out.check_call(cmd, env=env)
if retcode == 0:
if not args.disable_mail:
if not args.disable_mail and not args.dry_run:
print("\nYou can try out the relay by talking to this echo bot: ")
sshexec = SSHExec(args.config.mail_domain, verbose=args.verbose)
print(
sshexec(
call=remote.rshell.shell,
kwargs=dict(command="cat /var/lib/echobot/invite-link.txt"),
echobot_cmd = "cat /var/lib/echobot/invite-link.txt"
if ssh_host in ["localhost", "@local", "@docker"]:
result = (
subprocess.check_output(echobot_cmd, shell=True)
.decode()
.strip()
)
print(result)
else:
echo_sshexec = get_sshexec(ssh_host, verbose=args.verbose)
print(
echo_sshexec(
call=remote.rshell.shell,
kwargs=dict(command=echobot_cmd),
)
Comment on lines +114 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echobot_cmd = "cat /var/lib/echobot/invite-link.txt"
if ssh_host in ["localhost", "@local", "@docker"]:
result = (
subprocess.check_output(echobot_cmd, shell=True)
.decode()
.strip()
)
print(result)
else:
echo_sshexec = get_sshexec(ssh_host, verbose=args.verbose)
print(
echo_sshexec(
call=remote.rshell.shell,
kwargs=dict(command=echobot_cmd),
)
invite_path = "/var/lib/echobot/invite-link.txt"
if ssh_host in ["localhost", "@local", "@docker"]:
with open(invite_path) as f:
print(f.readline())
else:
echo_sshexec = get_sshexec(ssh_host, verbose=args.verbose)
print(
echo_sshexec(
call=remote.rshell.shell,
kwargs=dict(command=f"cat {invite_path}"),
)

Thanks for the fix, just stumbled upon it ourselves. We don't even have to open a subprocess if we're on the same machine :) let's just do it in python.

Copy link

@j4n j4n Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually too fast now and requires a time.sleep (5 seconds works for me) before the file exists. (Somewhat related to #641).

Suggested change
echobot_cmd = "cat /var/lib/echobot/invite-link.txt"
if ssh_host in ["localhost", "@local", "@docker"]:
result = (
subprocess.check_output(echobot_cmd, shell=True)
.decode()
.strip()
)
print(result)
else:
echo_sshexec = get_sshexec(ssh_host, verbose=args.verbose)
print(
echo_sshexec(
call=remote.rshell.shell,
kwargs=dict(command=echobot_cmd),
)
invite_path = Path("/var/lib/echobot/invite-link.txt")
if ssh_host in ["localhost", "@local", "@docker"]:
sleep(5) # wait a bit for echobot to settle down
with invite_path.open() as f:
print(f.readline())
else:
sshexec = SSHExec(args.config.mail_domain, verbose=args.verbose)
print(
localexec(
call=remote.rshell.shell,
kwargs=dict(command=f"cat {invite_path}"),
)
)

(still needs the from time import sleep at the top)

Copy link
Contributor

@hpk42 hpk42 Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep(5) is a questionable hack to avoid. Why is it that "cmdeploy run" finishes but echobot is not running? Is it possible to write a final "deployer" that waits e.g. for echobot to be up? Not sure if that's easily possible with pyinfra (or a systemctl command).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "systemctl is-active --wait echobot.service" or something similar could ensure that "cmdeploy run" returns only after echobot runs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemctl is-active --wait echobot.service will only wait if state is initializing or starting, and we have either failed or active with active not necessarily meaning that configuration worked :/ I'll try something with Requires=: #746

Maybe we should move this question out of this PR.

)
)
out.green("Deploy completed, call `cmdeploy dns` next.")
elif not remote_data["acme_account_url"]:
out.red("Deploy completed but letsencrypt not configured")
Expand Down