Mercurial > code > home > repos > infra
annotate sync.py @ 152:4f1f39f81bc1
fetch and install newer syncthing
author | drewp@bigasterisk.com |
---|---|
date | Sat, 11 Mar 2023 12:27:08 -0800 |
parents | 2065998876e4 |
children | 65412d39025e |
rev | line source |
---|---|
152 | 1 from pathlib import Path |
2 | |
14 | 3 from pyinfra import host |
152 | 4 from pyinfra.facts.server import Command |
5 from pyinfra.operations import apt, files, server, systemd | |
6 | |
7 | |
8 def host_running_version(user: str, v: str): | |
9 # if this command fails, we go in to error state and run nothing else #bugreport | |
10 out = host.get_fact(Command, f"runuser -u {user} syncthing serve --version || exit 0") | |
11 if out is None: | |
12 return False | |
13 _, sv, *_ = out.split() | |
14 return sv == v | |
15 | |
16 | |
17 def install_syncthing(user, version, os='linux', arch='amd64'): | |
18 tmpdir = Path('/tmp/syncthing_install') | |
19 dl_name = f'syncthing-{os}-{arch}-{version}' | |
20 url = f'https://github.com/syncthing/syncthing/releases/download/{version}/{dl_name}.tar.gz' | |
21 files.directory(tmpdir) | |
22 files.download(url, str(tmpdir / 'archive.tgz')) # bugreport | |
23 server.shell([f'cd {tmpdir}; aunpack archive.tgz']) | |
24 | |
25 systemd.service(service=f'syncthing@{user}', running=False) | |
26 | |
27 user_svc_template = '/lib/systemd/system/syncthing@.service' | |
28 server.shell([ | |
29 f'cp -a {tmpdir}/{dl_name}/{s} {d}' for s, d in [ | |
30 ('syncthing', '/usr/bin'), | |
31 #('etc/linux-systemd/user/syncthing.service', ''), # unused | |
32 ('etc/linux-systemd/system/syncthing@.service', user_svc_template), | |
33 ('etc/linux-systemd/system/syncthing-resume.service', '/etc/systemd/system/syncthing-resume.service'), | |
34 ] | |
35 ]) | |
36 files.link(f'/etc/systemd/system/multi-user.target.wants/syncthing@{user}.service', user_svc_template) | |
37 systemd.service(service=f'syncthing@{user}', enabled=True, restarted=True, daemon_reload=True) | |
38 | |
39 | |
40 # also see /my/serv/filesync/syncthing/deploy.yaml for the container one | |
41 version = 'v1.23.1' | |
14 | 42 |
92
a915000bad75
bang has a local (drewp) syncthing now
drewp@bigasterisk.com
parents:
23
diff
changeset
|
43 # primary instance is in k8s (/my/serv/filesync/syncthing); the rest are run with systemd. |
14 | 44 # Configs are in ~/.config/syncthing/ on each box |
146 | 45 if host.name in ['dash', 'dot', 'slash', 'plus', 'bang' ,'ditto']: |
152 | 46 apt.packages(packages=['syncthing'], present=False) |
47 user = 'ari' if host.name == 'dot' else 'drewp' | |
14 | 48 |
152 | 49 if not host_running_version(user, version): |
50 install_syncthing(user, version) | |
14 | 51 |
152 | 52 # something above has broken devnull #bugreport |
53 server.shell(['chmod a+w /dev/null']) | |
145 | 54 |
55 # also consider https://github.com/Martchus/syncthingtray tray status viewer on dtops |