Skip to content

Commit af27254

Browse files
committed
Restart iroh-relay if the binary is updated
1 parent 7725a73 commit af27254

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

cmdeploy/src/cmdeploy/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from chatmaild.config import Config, read_config
1414
from pyinfra import facts, host, logger
1515
from pyinfra.api import FactBase
16-
from pyinfra.facts.files import File
16+
from pyinfra.facts.files import File, Sha256File
1717
from pyinfra.facts.server import Sysctl
1818
from pyinfra.facts.systemd import SystemdEnabled
1919
from pyinfra.operations import apt, files, pip, server, systemd
@@ -569,16 +569,19 @@ def deploy_iroh_relay(config) -> None:
569569
packages=["curl"],
570570
)
571571

572-
server.shell(
573-
name="Download iroh-relay",
574-
commands=[
575-
f"(echo '{sha256sum} /usr/local/bin/iroh-relay' | sha256sum -c) || (curl -L {url} | gunzip | tar -x -f - ./iroh-relay -O >/usr/local/bin/iroh-relay.new && (echo '{sha256sum} /usr/local/bin/iroh-relay.new' | sha256sum -c) && mv /usr/local/bin/iroh-relay.new /usr/local/bin/iroh-relay)",
576-
"chmod 755 /usr/local/bin/iroh-relay",
577-
],
578-
)
579-
580572
need_restart = False
581573

574+
existing_sha256sum = host.get_fact(Sha256File, "/usr/local/bin/iroh-relay")
575+
if existing_sha256sum != sha256sum:
576+
server.shell(
577+
name="Download iroh-relay",
578+
commands=[
579+
f"(curl -L {url} | gunzip | tar -x -f - ./iroh-relay -O >/usr/local/bin/iroh-relay.new && (echo '{sha256sum} /usr/local/bin/iroh-relay.new' | sha256sum -c) && mv /usr/local/bin/iroh-relay.new /usr/local/bin/iroh-relay)",
580+
"chmod 755 /usr/local/bin/iroh-relay",
581+
],
582+
)
583+
need_restart = True
584+
582585
systemd_unit = files.put(
583586
name="Upload iroh-relay systemd unit",
584587
src=importlib.resources.files(__package__).joinpath("iroh-relay.service"),

0 commit comments

Comments
 (0)