Mercurial > code > home > repos > infra
annotate system.py @ 194:0d37dde619d0
zfs now serving from ditto, new pool is stor7
author | drewp@bigasterisk.com |
---|---|
date | Wed, 14 Jun 2023 17:00:13 -0700 |
parents | 522f26c8f691 |
children | 2595cf510c5d |
rev | line source |
---|---|
1 | 1 import os |
10
1fec9fe18a4e
more system.py cleanup; add pi /boot/config.txt
drewp@bigasterisk.com
parents:
6
diff
changeset
|
2 |
1 | 3 from pyinfra import host |
4 from pyinfra.facts.server import LinuxDistribution | |
12
15c5ce7c74b5
refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents:
10
diff
changeset
|
5 from pyinfra.operations import apt, files, server, systemd |
1 | 6 |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
7 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
1 | 8 |
9 TZ = 'America/Los_Angeles' | |
10 | |
12
15c5ce7c74b5
refactor, cleanup, split large deploys
drewp@bigasterisk.com
parents:
10
diff
changeset
|
11 |
91 | 12 def timezone(): |
13 files.link(path='/etc/localtime', target=f'/usr/share/zoneinfo/{TZ}') | |
14 files.replace(path='/etc/timezone', text='.*', replace=TZ) | |
138 | 15 |
1 | 16 |
91 | 17 def fstab(): |
18 fstab_file = f'files/fstab/{host.name}' | |
19 if os.path.exists(fstab_file): | |
20 files.put(src=fstab_file, dest='/etc/fstab') | |
1 | 21 |
91 | 22 def pi_tmpfs(): |
1 | 23 for line in [ |
24 'tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0', | |
25 'tmpfs /tmp tmpfs defaults,noatime 0 0', | |
26 ]: | |
27 files.line(path="/etc/fstab", line=line, replace=line) | |
28 | |
29 # stop SD card corruption (along with some mounts in fstab) | |
30 apt.packages(packages=['dphys-swapfile'], present=False) | |
31 | |
32 | |
3
61945df2a392
updates to work on recent raspbian installs
drewp@bigasterisk.com
parents:
2
diff
changeset
|
33 # don't try to get aufs-dkms on rpi-- https://github.com/docker/for-linux/issues/709 |
145 | 34 def podman_insecure_registry(): |
91 | 35 files.template(src='templates/kube/podman_registries.conf.j2', dest='/etc/containers/registries.conf.d/bang.conf') |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
36 |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
37 |
91 | 38 def no_sleep(): |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
39 server.shell(commands=['systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target']) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
40 |
91 | 41 def nfs_server(): |
34
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
42 apt.packages(packages=['nfs-kernel-server']) |
d4fb38f13c79
refactor dns and some other non-net setup
drewp@bigasterisk.com
parents:
12
diff
changeset
|
43 files.template(src='templates/bang_exports.j2', dest='/etc/exports') |
37
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
44 |
57 | 45 # sudo zfs set sharenfs="rw=10.5.0.0/16" stor6 |
46 | |
91 | 47 def smaller_journals(): |
37
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
48 files.line(name='shorter systemctl log window, for disk space', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
49 path='/etc/systemd/journald.conf', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
50 line='MaxFileSec', |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
51 replace="MaxFileSec=7day") |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
52 |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
53 for port in [80, 443]: |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
54 files.template(src="templates/webforward.service.j2", dest=f"/etc/systemd/system/web_forward_{port}.service", port=port) |
fbd0849dfdbd
redo networking to be much simpler. Uses systemd-networkd
drewp@bigasterisk.com
parents:
34
diff
changeset
|
55 systemd.service(service=f'web_forward_{port}', enabled=True, restarted=True) |
91 | 56 |
194
0d37dde619d0
zfs now serving from ditto, new pool is stor7
drewp@bigasterisk.com
parents:
155
diff
changeset
|
57 # todo move to k8s (and run on ditto, and record pool status too) |
118
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
58 def zfs_metrics(): |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
59 files.put(src='files/zfs_metrics/zfs_space_metrics.sh', dest='/opt/zfs_metrics/zfs_space_metrics.sh') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
60 files.put(src='files/zfs_metrics/zfs.mtail', dest='/opt/zfs_metrics/zfs.mtail') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
61 files.put(src='files/zfs_metrics/zfs_space_metrics.service', |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
62 dest=f'/etc/systemd/system/zfs_space_metrics.service') |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
63 systemd.service(service=f'zfs_space_metrics', enabled=True, restarted=True, daemon_reload=True) |
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
64 |
145 | 65 server.hostname(hostname=host.name) |
91 | 66 timezone() |
67 fstab() | |
68 | |
69 if not is_pi: | |
70 files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") | |
71 | |
72 if is_pi and host.name != 'pipe': | |
73 pi_tmpfs() | |
133 | 74 files.template(src='templates/boot_config.txt.j2', dest='/boot/config.txt') |
91 | 75 |
138 | 76 if not is_pi: |
145 | 77 podman_insecure_registry() |
91 | 78 |
146 | 79 if host.name in ['bang', 'pipe', 'ditto']: |
91 | 80 no_sleep() |
81 | |
194
0d37dde619d0
zfs now serving from ditto, new pool is stor7
drewp@bigasterisk.com
parents:
155
diff
changeset
|
82 if host.name in ['bang', 'ditto']: |
91 | 83 nfs_server() |
118
69058ad170be
watch output from `zfs list -o space` as metrics
drewp@bigasterisk.com
parents:
91
diff
changeset
|
84 zfs_metrics() |
91 | 85 |
86 if host.name == 'prime': | |
126
fe3ae7c95e65
collect all apt/sources.list into a central template
drewp@bigasterisk.com
parents:
118
diff
changeset
|
87 smaller_journals() |