moat-link-save 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- moat_link_save-0.1.0/LICENSE.txt +14 -0
- moat_link_save-0.1.0/Makefile +23 -0
- moat_link_save-0.1.0/PKG-INFO +170 -0
- moat_link_save-0.1.0/README.md +141 -0
- moat_link_save-0.1.0/debian/.gitignore +6 -0
- moat_link_save-0.1.0/debian/changelog +6 -0
- moat_link_save-0.1.0/debian/control +24 -0
- moat_link_save-0.1.0/debian/py3dist-overrides +1 -0
- moat_link_save-0.1.0/debian/rules +8 -0
- moat_link_save-0.1.0/pyproject.toml +46 -0
- moat_link_save-0.1.0/setup.cfg +4 -0
- moat_link_save-0.1.0/src/moat/link/save/__init__.py +49 -0
- moat_link_save-0.1.0/src/moat/link/save/_cfg.yaml +39 -0
- moat_link_save-0.1.0/src/moat/link/save/_main.py +361 -0
- moat_link_save-0.1.0/src/moat/link/save/_schema.yaml +46 -0
- moat_link_save-0.1.0/src/moat/link/save/_server_if.py +25 -0
- moat_link_save-0.1.0/src/moat/link/save/cfg.py +151 -0
- moat_link_save-0.1.0/src/moat/link/save/file.py +216 -0
- moat_link_save-0.1.0/src/moat/link/save/keep.py +207 -0
- moat_link_save-0.1.0/src/moat/link/save/saver.py +624 -0
- moat_link_save-0.1.0/src/moat/link/save/source.py +947 -0
- moat_link_save-0.1.0/src/moat/link/save/writer.py +198 -0
- moat_link_save-0.1.0/src/moat_link_save.egg-info/PKG-INFO +170 -0
- moat_link_save-0.1.0/src/moat_link_save.egg-info/SOURCES.txt +29 -0
- moat_link_save-0.1.0/src/moat_link_save.egg-info/dependency_links.txt +1 -0
- moat_link_save-0.1.0/src/moat_link_save.egg-info/requires.txt +10 -0
- moat_link_save-0.1.0/src/moat_link_save.egg-info/top_level.txt +1 -0
- moat_link_save-0.1.0/systemd/moat-link-save-snap.service +24 -0
- moat_link_save-0.1.0/systemd/moat-link-save-snap.timer +9 -0
- moat_link_save-0.1.0/systemd/moat-link-save.service +28 -0
- moat_link_save-0.1.0/systemd/moat-link-save@.service +35 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
The code in this repository, and all MoaT submodules it refers to,
|
|
2
|
+
is part of the MoaT project.
|
|
3
|
+
|
|
4
|
+
Unless a submodule's LICENSE.txt states otherwise, all included files are
|
|
5
|
+
licensed under the LGPL V3, as published by the FSF at
|
|
6
|
+
https://www.gnu.org/licenses/lgpl-3.0.html .
|
|
7
|
+
|
|
8
|
+
In addition to the LGPL's terms, the author(s) respectfully ask all users of
|
|
9
|
+
this code to contribute any bug fixes or enhancements. Also, please link back to
|
|
10
|
+
https://M-o-a-T.org.
|
|
11
|
+
|
|
12
|
+
Thank you.
|
|
13
|
+
|
|
14
|
+
Copyright © 2021 ff.: the MoaT contributor(s), as per the git changelog(s).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/make -f
|
|
2
|
+
|
|
3
|
+
PACKAGE = moat-link-save
|
|
4
|
+
MAKEINCL ?= $(shell python3 -mmoat src path)/make/py
|
|
5
|
+
|
|
6
|
+
install: installscript installsystemd
|
|
7
|
+
|
|
8
|
+
installsystemd:
|
|
9
|
+
mkdir -p $(PREFIX)/usr/lib/systemd/system
|
|
10
|
+
cp systemd/*.service $(PREFIX)/usr/lib/systemd/system/
|
|
11
|
+
cp systemd/*.timer $(PREFIX)/usr/lib/systemd/system/
|
|
12
|
+
|
|
13
|
+
installscript:
|
|
14
|
+
|
|
15
|
+
ifneq ($(wildcard $(MAKEINCL)),)
|
|
16
|
+
include $(MAKEINCL)
|
|
17
|
+
# availabe via http://github.com/smurfix/sourcemgr
|
|
18
|
+
|
|
19
|
+
else
|
|
20
|
+
%:
|
|
21
|
+
@echo "Please fix 'python3 -mmoat src path'."
|
|
22
|
+
@exit 1
|
|
23
|
+
endif
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moat-link-save
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Save MoaT-Link state to files: the format, rotation, and a remote recorder
|
|
5
|
+
Author-email: Matthias Urlichs <matthias@urlichs.de>
|
|
6
|
+
Project-URL: homepage, https://m-o-a-t.org
|
|
7
|
+
Project-URL: repository, https://github.com/M-o-a-T/moat
|
|
8
|
+
Keywords: MoaT
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Framework :: AsyncIO
|
|
12
|
+
Classifier: Framework :: Trio
|
|
13
|
+
Classifier: Framework :: AnyIO
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE.txt
|
|
18
|
+
Requires-Dist: anyio~=4.2
|
|
19
|
+
Requires-Dist: asyncclick~=8.3
|
|
20
|
+
Requires-Dist: attrs
|
|
21
|
+
Requires-Dist: ruyaml
|
|
22
|
+
Requires-Dist: moat-util~=0.64.13
|
|
23
|
+
Requires-Dist: moat-lib-codec~=0.4.22
|
|
24
|
+
Requires-Dist: moat-lib-config~=0.2.6
|
|
25
|
+
Requires-Dist: moat-lib-path~=0.4.4
|
|
26
|
+
Requires-Dist: moat-lib-broadcast~=0.1.6
|
|
27
|
+
Requires-Dist: moat-link~=0.13.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# The MoaT-Link state saver
|
|
31
|
+
|
|
32
|
+
% start synopsis
|
|
33
|
+
% start main
|
|
34
|
+
|
|
35
|
+
Saving MoaT-Link state to files: the file format, rotation, and
|
|
36
|
+
retention — shared by the MoaT-Link server and the remote recorder
|
|
37
|
+
(``moat link save run``).
|
|
38
|
+
|
|
39
|
+
% end synopsis
|
|
40
|
+
|
|
41
|
+
## Overview
|
|
42
|
+
|
|
43
|
+
A MoaT-Link server records its state — full snapshots plus incremental
|
|
44
|
+
updates — to a series of files, so that a crashed server (or cluster)
|
|
45
|
+
can restore the last-known state. This package implements that
|
|
46
|
+
functionality once; the server uses it in-process, and the
|
|
47
|
+
``moat link save`` recorder uses it from a separate process, monitoring
|
|
48
|
+
either a MoaT-Link server or the MQTT backend directly.
|
|
49
|
+
|
|
50
|
+
## The recorder
|
|
51
|
+
|
|
52
|
+
Run ``moat link save run`` to write the same state files from a separate
|
|
53
|
+
process, possibly on another host:
|
|
54
|
+
|
|
55
|
+
* ``source: server`` — connect to a MoaT-Link server as a client.
|
|
56
|
+
* ``source: backend`` — subscribe on the MQTT backend directly; no
|
|
57
|
+
server needed.
|
|
58
|
+
|
|
59
|
+
Periodically the recorder rotates to a fresh file over a *new*
|
|
60
|
+
connection, writing a complete snapshot first, so that no update is
|
|
61
|
+
lost across the handover.
|
|
62
|
+
|
|
63
|
+
The command runs until stopped (SIGTERM); all files get their trailer,
|
|
64
|
+
no update is lost. Options override ``link.save``:
|
|
65
|
+
|
|
66
|
+
``-b, --backend``
|
|
67
|
+
Record from the MQTT backend, not a server. Only retained data is
|
|
68
|
+
recorded — the retained-message replay *is* the snapshot.
|
|
69
|
+
``-d, --dir DIR``
|
|
70
|
+
The directory to store the state files in.
|
|
71
|
+
``-n, --name PATTERN``
|
|
72
|
+
The strftime pattern for the file names (default:
|
|
73
|
+
``link.save.name``, e.g. ``%Y-%m/%d/%H-%M.moat``).
|
|
74
|
+
``-i, --interval SEC``
|
|
75
|
+
The rotation interval, seconds.
|
|
76
|
+
``-r, --rewrite N``
|
|
77
|
+
Every *n*-th file is a full snapshot; the others are incremental.
|
|
78
|
+
``--incr / --no-incr``
|
|
79
|
+
Record incremental update tails between full snapshots (default:
|
|
80
|
+
on; off writes stand-alone snapshots only).
|
|
81
|
+
``--run / --no-run``
|
|
82
|
+
Also record ``run.*`` (ephemeral) data.
|
|
83
|
+
``-p, --prefix PATH``
|
|
84
|
+
Only record this subtree of the link root.
|
|
85
|
+
|
|
86
|
+
### Runtime reconfiguration
|
|
87
|
+
|
|
88
|
+
``moat link save cfg`` shows — and, with ``-s`` arguments,
|
|
89
|
+
updates — a running *server's* save configuration (the ``s.cfg``
|
|
90
|
+
command; the global ``moat link -s NAME`` picks the server):
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
moat link save cfg # show the effective config
|
|
94
|
+
moat link save cfg -s interval 600 -s dir /var/lib/moat/link/new
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The server combines the changes with its current configuration and
|
|
98
|
+
rotates its saver onto the result — a full rotation, so updates
|
|
99
|
+
published during the change are not lost. An empty ``dir`` stops
|
|
100
|
+
saving (the current file is flushed and closed). The ``-s`` values
|
|
101
|
+
follow the standard MoaT conventions (``moat --help``): ``600`` is a
|
|
102
|
+
number, ``/path`` a string, ``=t``/``=f`` true/false, ``~text`` a
|
|
103
|
+
literal string.
|
|
104
|
+
|
|
105
|
+
Runtime changes are not persisted: a server restart re-reads its
|
|
106
|
+
configuration file.
|
|
107
|
+
|
|
108
|
+
### One-shot snapshots
|
|
109
|
+
|
|
110
|
+
``moat link save snap FILE`` writes a single full snapshot — a
|
|
111
|
+
backup, or triggered from a systemd timer unit:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
moat link save snap /var/lib/moat/link/snapshot/$(date +%F).moat
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
FILE may contain strftime patterns (``%Y-%m-%d.moat``), expanded
|
|
118
|
+
per ``link.save.use_local_time`` — the default (``false``) uses UTC,
|
|
119
|
+
so east of UTC the daily timer's file carries the previous day's
|
|
120
|
+
date; that is not wrong, but worth knowing when looking for a
|
|
121
|
+
backup. Alternatively, ``--dir DIR --name PATTERN`` names the
|
|
122
|
+
target by the same strftime rules — DIR/PATTERN expanded — so a
|
|
123
|
+
timer's command reads like the recorder's configuration; exactly
|
|
124
|
+
one of the FILE argument or ``--name`` must be given. The file has
|
|
125
|
+
the same format as the recorder's full files; a server can load it
|
|
126
|
+
(``moat link server --load``) — or restore a whole tree of them with
|
|
127
|
+
``moat link server --load-dir DIR``. The options are those of ``run``
|
|
128
|
+
that make sense for a one-shot snapshot: ``-b``, ``-d``/``-n``
|
|
129
|
+
(see above), ``-p``, ``--run`` and ``-t`` (fail if the snapshot
|
|
130
|
+
takes longer than this, seconds).
|
|
131
|
+
|
|
132
|
+
### systemd units
|
|
133
|
+
|
|
134
|
+
The moat-link-save package ships service units for both commands:
|
|
135
|
+
|
|
136
|
+
* ``moat-link-save.service`` — runs ``moat link save run`` as a
|
|
137
|
+
service (``Type=notify``, restarted on failure); enable it for
|
|
138
|
+
continuous recording on a host without a local server.
|
|
139
|
+
* ``moat-link-save@.service`` — the same, for a named configuration
|
|
140
|
+
(``systemctl start moat-link-save@NAME`` uses
|
|
141
|
+
``/etc/moat/moat-NAME.yaml``, like ``moat-link-server@``); each
|
|
142
|
+
instance records to its own ``StateDirectory``, passed as ``-d`` —
|
|
143
|
+
so two recorders never share a tree.
|
|
144
|
+
* ``moat-link-save-snap.service`` — a oneshot unit that runs
|
|
145
|
+
``moat link save snap`` with a dated file name pattern; start it
|
|
146
|
+
manually (before maintenance) or via…
|
|
147
|
+
* ``moat-link-save-snap.timer`` — the matching daily timer
|
|
148
|
+
(``OnCalendar=daily``, persistent).
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
The defaults are at ``link.save`` in the configuration; a server
|
|
153
|
+
overrides them at ``link.server.save``, the recorder at
|
|
154
|
+
``link.save.source`` (and its own command line). See the savefile
|
|
155
|
+
documentation for the file format, rotation, and the ``keep``
|
|
156
|
+
retention policy.
|
|
157
|
+
|
|
158
|
+
The recorder's default directory is ``/var/lib/moat/link/record`` —
|
|
159
|
+
*not* the server's ``/var/lib/moat/link/data``: a recorder writing
|
|
160
|
+
to the same tree would interleave its files with the server's, and
|
|
161
|
+
each one's ``keep`` cleanup would delete the other's files. The
|
|
162
|
+
service units create their directories via ``StateDirectory=``
|
|
163
|
+
(``record`` for ``run``, ``record-NAME`` — passed to the recorder
|
|
164
|
+
as ``-d`` — for a named instance, ``snapshot`` for the timer).
|
|
165
|
+
|
|
166
|
+
% end main
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
This project is licensed under the same terms as MoaT.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# The MoaT-Link state saver
|
|
2
|
+
|
|
3
|
+
% start synopsis
|
|
4
|
+
% start main
|
|
5
|
+
|
|
6
|
+
Saving MoaT-Link state to files: the file format, rotation, and
|
|
7
|
+
retention — shared by the MoaT-Link server and the remote recorder
|
|
8
|
+
(``moat link save run``).
|
|
9
|
+
|
|
10
|
+
% end synopsis
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
A MoaT-Link server records its state — full snapshots plus incremental
|
|
15
|
+
updates — to a series of files, so that a crashed server (or cluster)
|
|
16
|
+
can restore the last-known state. This package implements that
|
|
17
|
+
functionality once; the server uses it in-process, and the
|
|
18
|
+
``moat link save`` recorder uses it from a separate process, monitoring
|
|
19
|
+
either a MoaT-Link server or the MQTT backend directly.
|
|
20
|
+
|
|
21
|
+
## The recorder
|
|
22
|
+
|
|
23
|
+
Run ``moat link save run`` to write the same state files from a separate
|
|
24
|
+
process, possibly on another host:
|
|
25
|
+
|
|
26
|
+
* ``source: server`` — connect to a MoaT-Link server as a client.
|
|
27
|
+
* ``source: backend`` — subscribe on the MQTT backend directly; no
|
|
28
|
+
server needed.
|
|
29
|
+
|
|
30
|
+
Periodically the recorder rotates to a fresh file over a *new*
|
|
31
|
+
connection, writing a complete snapshot first, so that no update is
|
|
32
|
+
lost across the handover.
|
|
33
|
+
|
|
34
|
+
The command runs until stopped (SIGTERM); all files get their trailer,
|
|
35
|
+
no update is lost. Options override ``link.save``:
|
|
36
|
+
|
|
37
|
+
``-b, --backend``
|
|
38
|
+
Record from the MQTT backend, not a server. Only retained data is
|
|
39
|
+
recorded — the retained-message replay *is* the snapshot.
|
|
40
|
+
``-d, --dir DIR``
|
|
41
|
+
The directory to store the state files in.
|
|
42
|
+
``-n, --name PATTERN``
|
|
43
|
+
The strftime pattern for the file names (default:
|
|
44
|
+
``link.save.name``, e.g. ``%Y-%m/%d/%H-%M.moat``).
|
|
45
|
+
``-i, --interval SEC``
|
|
46
|
+
The rotation interval, seconds.
|
|
47
|
+
``-r, --rewrite N``
|
|
48
|
+
Every *n*-th file is a full snapshot; the others are incremental.
|
|
49
|
+
``--incr / --no-incr``
|
|
50
|
+
Record incremental update tails between full snapshots (default:
|
|
51
|
+
on; off writes stand-alone snapshots only).
|
|
52
|
+
``--run / --no-run``
|
|
53
|
+
Also record ``run.*`` (ephemeral) data.
|
|
54
|
+
``-p, --prefix PATH``
|
|
55
|
+
Only record this subtree of the link root.
|
|
56
|
+
|
|
57
|
+
### Runtime reconfiguration
|
|
58
|
+
|
|
59
|
+
``moat link save cfg`` shows — and, with ``-s`` arguments,
|
|
60
|
+
updates — a running *server's* save configuration (the ``s.cfg``
|
|
61
|
+
command; the global ``moat link -s NAME`` picks the server):
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
moat link save cfg # show the effective config
|
|
65
|
+
moat link save cfg -s interval 600 -s dir /var/lib/moat/link/new
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The server combines the changes with its current configuration and
|
|
69
|
+
rotates its saver onto the result — a full rotation, so updates
|
|
70
|
+
published during the change are not lost. An empty ``dir`` stops
|
|
71
|
+
saving (the current file is flushed and closed). The ``-s`` values
|
|
72
|
+
follow the standard MoaT conventions (``moat --help``): ``600`` is a
|
|
73
|
+
number, ``/path`` a string, ``=t``/``=f`` true/false, ``~text`` a
|
|
74
|
+
literal string.
|
|
75
|
+
|
|
76
|
+
Runtime changes are not persisted: a server restart re-reads its
|
|
77
|
+
configuration file.
|
|
78
|
+
|
|
79
|
+
### One-shot snapshots
|
|
80
|
+
|
|
81
|
+
``moat link save snap FILE`` writes a single full snapshot — a
|
|
82
|
+
backup, or triggered from a systemd timer unit:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
moat link save snap /var/lib/moat/link/snapshot/$(date +%F).moat
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
FILE may contain strftime patterns (``%Y-%m-%d.moat``), expanded
|
|
89
|
+
per ``link.save.use_local_time`` — the default (``false``) uses UTC,
|
|
90
|
+
so east of UTC the daily timer's file carries the previous day's
|
|
91
|
+
date; that is not wrong, but worth knowing when looking for a
|
|
92
|
+
backup. Alternatively, ``--dir DIR --name PATTERN`` names the
|
|
93
|
+
target by the same strftime rules — DIR/PATTERN expanded — so a
|
|
94
|
+
timer's command reads like the recorder's configuration; exactly
|
|
95
|
+
one of the FILE argument or ``--name`` must be given. The file has
|
|
96
|
+
the same format as the recorder's full files; a server can load it
|
|
97
|
+
(``moat link server --load``) — or restore a whole tree of them with
|
|
98
|
+
``moat link server --load-dir DIR``. The options are those of ``run``
|
|
99
|
+
that make sense for a one-shot snapshot: ``-b``, ``-d``/``-n``
|
|
100
|
+
(see above), ``-p``, ``--run`` and ``-t`` (fail if the snapshot
|
|
101
|
+
takes longer than this, seconds).
|
|
102
|
+
|
|
103
|
+
### systemd units
|
|
104
|
+
|
|
105
|
+
The moat-link-save package ships service units for both commands:
|
|
106
|
+
|
|
107
|
+
* ``moat-link-save.service`` — runs ``moat link save run`` as a
|
|
108
|
+
service (``Type=notify``, restarted on failure); enable it for
|
|
109
|
+
continuous recording on a host without a local server.
|
|
110
|
+
* ``moat-link-save@.service`` — the same, for a named configuration
|
|
111
|
+
(``systemctl start moat-link-save@NAME`` uses
|
|
112
|
+
``/etc/moat/moat-NAME.yaml``, like ``moat-link-server@``); each
|
|
113
|
+
instance records to its own ``StateDirectory``, passed as ``-d`` —
|
|
114
|
+
so two recorders never share a tree.
|
|
115
|
+
* ``moat-link-save-snap.service`` — a oneshot unit that runs
|
|
116
|
+
``moat link save snap`` with a dated file name pattern; start it
|
|
117
|
+
manually (before maintenance) or via…
|
|
118
|
+
* ``moat-link-save-snap.timer`` — the matching daily timer
|
|
119
|
+
(``OnCalendar=daily``, persistent).
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
The defaults are at ``link.save`` in the configuration; a server
|
|
124
|
+
overrides them at ``link.server.save``, the recorder at
|
|
125
|
+
``link.save.source`` (and its own command line). See the savefile
|
|
126
|
+
documentation for the file format, rotation, and the ``keep``
|
|
127
|
+
retention policy.
|
|
128
|
+
|
|
129
|
+
The recorder's default directory is ``/var/lib/moat/link/record`` —
|
|
130
|
+
*not* the server's ``/var/lib/moat/link/data``: a recorder writing
|
|
131
|
+
to the same tree would interleave its files with the server's, and
|
|
132
|
+
each one's ``keep`` cleanup would delete the other's files. The
|
|
133
|
+
service units create their directories via ``StateDirectory=``
|
|
134
|
+
(``record`` for ``run``, ``record-NAME`` — passed to the recorder
|
|
135
|
+
as ``-d`` — for a named instance, ``snapshot`` for the timer).
|
|
136
|
+
|
|
137
|
+
% end main
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
This project is licensed under the same terms as MoaT.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Source: moat-link-save
|
|
2
|
+
Maintainer: Matthias Urlichs <matthias@urlichs.de>
|
|
3
|
+
Section: python
|
|
4
|
+
Priority: optional
|
|
5
|
+
Build-Depends: dh-python, python3-all, debhelper (>= 13), debhelper-compat (= 13),
|
|
6
|
+
python3-setuptools,
|
|
7
|
+
python3-wheel,
|
|
8
|
+
Standards-Version: 3.9.6
|
|
9
|
+
Homepage: https://github.com/smurfix/moat
|
|
10
|
+
|
|
11
|
+
Package: moat-link-save
|
|
12
|
+
Architecture: all
|
|
13
|
+
Depends: ${misc:Depends}, ${python3:Depends},
|
|
14
|
+
moat-util,
|
|
15
|
+
moat-link,
|
|
16
|
+
systemd (>= 241),
|
|
17
|
+
Recommends:
|
|
18
|
+
python3-trio (>= 0.22),
|
|
19
|
+
Description: Save MoaT-Link state to files
|
|
20
|
+
This package implements writing, rotating, and cleaning up the state
|
|
21
|
+
files that a MoaT-Link server — or a separate recorder process
|
|
22
|
+
("moat link save run") — persists.
|
|
23
|
+
.
|
|
24
|
+
Part of the MoaT ecosystem for distributed home automation.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
moat_link moat-link
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = [ "setuptools", "wheel",]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
classifiers = [
|
|
7
|
+
"Intended Audience :: Developers",
|
|
8
|
+
"Programming Language :: Python :: 3",
|
|
9
|
+
"Framework :: AsyncIO",
|
|
10
|
+
"Framework :: Trio",
|
|
11
|
+
"Framework :: AnyIO",
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"anyio ~= 4.2",
|
|
16
|
+
"asyncclick ~= 8.3",
|
|
17
|
+
"attrs",
|
|
18
|
+
"ruyaml",
|
|
19
|
+
"moat-util ~= 0.64.13",
|
|
20
|
+
"moat-lib-codec ~= 0.4.22",
|
|
21
|
+
"moat-lib-config ~= 0.2.6",
|
|
22
|
+
"moat-lib-path ~= 0.4.4",
|
|
23
|
+
"moat-lib-broadcast ~= 0.1.6",
|
|
24
|
+
"moat-link ~= 0.13.0",
|
|
25
|
+
]
|
|
26
|
+
version = "0.1.0"
|
|
27
|
+
keywords = [ "MoaT",]
|
|
28
|
+
requires-python = ">=3.8"
|
|
29
|
+
name = "moat-link-save"
|
|
30
|
+
description = "Save MoaT-Link state to files: the format, rotation, and a remote recorder"
|
|
31
|
+
readme = "README.md"
|
|
32
|
+
|
|
33
|
+
[[project.authors]]
|
|
34
|
+
name = "Matthias Urlichs"
|
|
35
|
+
email = "matthias@urlichs.de"
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
homepage = "https://m-o-a-t.org"
|
|
39
|
+
repository = "https://github.com/M-o-a-T/moat"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools]
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.package-data]
|
|
46
|
+
"*" = ["*.yaml"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Saving MoaT-Link state to files.
|
|
3
|
+
|
|
4
|
+
This package implements writing, rotating, and cleaning up the state
|
|
5
|
+
files that a MoaT-Link server — or a separate recorder process
|
|
6
|
+
(``moat link save run``) — persists.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from importlib.metadata import version
|
|
15
|
+
|
|
16
|
+
_version = version("moat.link.save")
|
|
17
|
+
_version_tuple = tuple(int(x) for x in _version.split("."))
|
|
18
|
+
|
|
19
|
+
except Exception: # pragma: no cover
|
|
20
|
+
_version = "0.0.1"
|
|
21
|
+
_version_tuple = (0, 0, 1)
|
|
22
|
+
|
|
23
|
+
from moat.lib.config import register as _register
|
|
24
|
+
|
|
25
|
+
from .cfg import SaveCfg as SaveCfg
|
|
26
|
+
from .file import BadFile as BadFile
|
|
27
|
+
from .file import StateFileInfo as StateFileInfo
|
|
28
|
+
from .file import name_for_file as name_for_file
|
|
29
|
+
from .file import read_state_header as read_state_header
|
|
30
|
+
from .file import read_state_trailer as read_state_trailer
|
|
31
|
+
from .file import tag_check as tag_check
|
|
32
|
+
from .keep import cleanup_state_files as cleanup_state_files
|
|
33
|
+
from .keep import collect_state_files as collect_state_files
|
|
34
|
+
from .keep import unlink_state_file as unlink_state_file
|
|
35
|
+
|
|
36
|
+
_register(__name__)
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"BadFile",
|
|
40
|
+
"SaveCfg",
|
|
41
|
+
"StateFileInfo",
|
|
42
|
+
"cleanup_state_files",
|
|
43
|
+
"collect_state_files",
|
|
44
|
+
"name_for_file",
|
|
45
|
+
"read_state_header",
|
|
46
|
+
"read_state_trailer",
|
|
47
|
+
"tag_check",
|
|
48
|
+
"unlink_state_file",
|
|
49
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# The recorder's own defaults. The server overrides them with its own
|
|
2
|
+
# ``save.dir`` (the server needs its own directory — a recorder writing
|
|
3
|
+
# to the same directory would corrupt the files).
|
|
4
|
+
dir: "/var/lib/moat/link/record"
|
|
5
|
+
name: "%Y-%m/%d/%H-%M.moat"
|
|
6
|
+
interval: 1000
|
|
7
|
+
rewrite: 5
|
|
8
|
+
errors: 10 # unlink error files ZZ
|
|
9
|
+
use_local_time: false
|
|
10
|
+
incremental: true
|
|
11
|
+
# False: only save snapshots
|
|
12
|
+
keep:
|
|
13
|
+
- 10
|
|
14
|
+
- 1 day
|
|
15
|
+
- 10
|
|
16
|
+
run: false
|
|
17
|
+
# Also record run.* data — ephemeral by design (state, ping,
|
|
18
|
+
# registrations), though some of it may be retained
|
|
19
|
+
source: null
|
|
20
|
+
# Where a recorder takes its data from: "server" or "backend".
|
|
21
|
+
# Not used by the server (which reads its own state).
|
|
22
|
+
load_dir: null
|
|
23
|
+
# Directory to restore the server's startup state from; the default
|
|
24
|
+
# (null) restores from ``dir``. Server-only: the recorder never
|
|
25
|
+
# restores, and a running server ignores changes to it (it only
|
|
26
|
+
# applies at startup).
|
|
27
|
+
replay:
|
|
28
|
+
# Backend-recorder tunables for detecting the end of the retained-
|
|
29
|
+
# message replay: no recorded message for `quiet` seconds (the
|
|
30
|
+
# burst is over), or the rate dropped well below its peak for
|
|
31
|
+
# `quiet` seconds while the recent messages are live (fresh
|
|
32
|
+
# timestamps within `skew` of the wall clock, and/or not marked
|
|
33
|
+
# retained), or the `max` bound passed. `first` bounds the wait for
|
|
34
|
+
# the first message (an empty subtree costs `first`, not `max`).
|
|
35
|
+
first: 5
|
|
36
|
+
quiet: 0.5
|
|
37
|
+
frac: 0.1
|
|
38
|
+
skew: 1.0
|
|
39
|
+
max: 30
|