django-systemd 0.2.3__tar.gz → 0.4.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.
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/test.yml +1 -1
- {django_systemd-0.2.3 → django_systemd-0.4.0}/PKG-INFO +3 -2
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/changelog.rst +16 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/howto.rst +4 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/settings.rst +27 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/tutorial.rst +10 -8
- {django_systemd-0.2.3 → django_systemd-0.4.0}/pyproject.toml +3 -2
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/__init__.py +1 -1
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/config.py +27 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/management/commands/systemd.py +54 -16
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/test_basics.py +16 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/test_command.py +80 -4
- {django_systemd-0.2.3 → django_systemd-0.4.0}/uv.lock +461 -397
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.codecov.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.gitattributes +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/CODEOWNERS +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/dependabot.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/bandit.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/dependabot-automerge.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/lint.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/release.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/scorecard.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/update_coc.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/workflows/zizmor.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.github/zizmor.yml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.gitignore +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.pre-commit-config.yaml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/.readthedocs.yaml +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/AGENTS.md +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/CODE_OF_CONDUCT.md +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/CONTRIBUTING.md +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/LICENSE +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/README.md +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/SECURITY.md +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/_static/style.css +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/command.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/conf.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/index.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/config.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/defines.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/index.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/protocol.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/signals.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/reference/systemd.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/doc/source/refs.rst +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/justfile +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/admin.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/apps.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/defines.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/management/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/management/commands/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/protocol.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/signals.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app1/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app1/systemd/app@.target +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app1/systemd/check.timer +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app1/systemd/web.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app2/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app2/systemd/app@.target +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app2/systemd/check.timer +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app2/systemd/web.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/__init__.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/bad name.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/broken.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/cleanup.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/cleanup.timer +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/my.app.timer +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/runtime.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/scoped.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/sub/web.service +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/apps/app3/systemd/web.socket +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/conftest.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/settings.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/test_protocol.py +0 -0
- {django_systemd-0.2.3 → django_systemd-0.4.0}/tests/urls.py +0 -0
|
@@ -287,7 +287,7 @@ jobs:
|
|
|
287
287
|
- run: ls -la *.coverage
|
|
288
288
|
- run: just coverage
|
|
289
289
|
- name: Upload coverage to Codecov
|
|
290
|
-
uses: codecov/codecov-action@
|
|
290
|
+
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5
|
|
291
291
|
with:
|
|
292
292
|
use_oidc: true
|
|
293
293
|
files: ./coverage.xml
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: django-systemd
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Ship renderable systemd unit templates with your apps and manage project services through the django admin.
|
|
5
5
|
Project-URL: Homepage, https://django-systemd.readthedocs.io
|
|
6
6
|
Project-URL: Documentation, https://django-systemd.readthedocs.io
|
|
@@ -34,8 +34,9 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
34
34
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
35
|
Requires-Python: <4.0,>=3.11
|
|
36
36
|
Requires-Dist: django-render-static>=3.5.0
|
|
37
|
-
Requires-Dist: django-typer>=
|
|
37
|
+
Requires-Dist: django-typer>=4
|
|
38
38
|
Requires-Dist: django<6.2,>=5.2
|
|
39
|
+
Requires-Dist: rich>=15.0.0
|
|
39
40
|
Description-Content-Type: text/markdown
|
|
40
41
|
|
|
41
42
|
# django-systemd
|
|
@@ -4,6 +4,22 @@
|
|
|
4
4
|
Change Log
|
|
5
5
|
==========
|
|
6
6
|
|
|
7
|
+
v0.4.0 (2026-10-05)
|
|
8
|
+
===================
|
|
9
|
+
|
|
10
|
+
* Added the :setting:`SYSTEMD_SOURCE_DIR` setting, a default for
|
|
11
|
+
``install --source`` so installs use pre-rendered units without the option.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
v0.3.0 (2026-10-05)
|
|
15
|
+
===================
|
|
16
|
+
|
|
17
|
+
* Added the :setting:`SYSTEMD_RENDER_DIR` setting to change the default
|
|
18
|
+
``render`` output directory from the current directory.
|
|
19
|
+
* ``list`` prints its table with Rich. Output that is not a terminal is never
|
|
20
|
+
wrapped, so piped rows keep one unit per line.
|
|
21
|
+
|
|
22
|
+
|
|
7
23
|
v0.2.3 (2026-09-30)
|
|
8
24
|
===================
|
|
9
25
|
|
|
@@ -203,6 +203,10 @@ Commit ``./units`` and install them on the host without rendering again:
|
|
|
203
203
|
|
|
204
204
|
django-admin systemd install --source ./units --enable
|
|
205
205
|
|
|
206
|
+
To make this the default, point :setting:`SYSTEMD_RENDER_DIR` and
|
|
207
|
+
:setting:`SYSTEMD_SOURCE_DIR` at the same directory; ``render`` then writes
|
|
208
|
+
there and ``install`` reads from there without either option.
|
|
209
|
+
|
|
206
210
|
``install`` is still a Django management command even with ``--source``, so
|
|
207
211
|
Django settings must still load successfully on the host.
|
|
208
212
|
|
|
@@ -162,3 +162,30 @@ early boot; ``install`` creates it with mode ``0755`` before the umask is
|
|
|
162
162
|
applied, if it does not exist.
|
|
163
163
|
|
|
164
164
|
Default: ``None``
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
``SYSTEMD_RENDER_DIR``
|
|
168
|
+
-----------------------
|
|
169
|
+
|
|
170
|
+
.. setting:: SYSTEMD_RENDER_DIR
|
|
171
|
+
|
|
172
|
+
The directory ``render`` writes unit files into when no output directory is
|
|
173
|
+
passed on the command line. A relative path is resolved against the current
|
|
174
|
+
directory. An explicit ``render`` argument always takes precedence.
|
|
175
|
+
|
|
176
|
+
Default: ``None`` (the current directory)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
``SYSTEMD_SOURCE_DIR``
|
|
180
|
+
-----------------------
|
|
181
|
+
|
|
182
|
+
.. setting:: SYSTEMD_SOURCE_DIR
|
|
183
|
+
|
|
184
|
+
A directory of pre-rendered unit files, such as one written by ``render`` and
|
|
185
|
+
committed to version control, that ``install`` uses instead of rendering units
|
|
186
|
+
when ``--source`` is not passed. A relative path is resolved against the current
|
|
187
|
+
directory. ``install --source`` takes precedence, and ``--context`` or
|
|
188
|
+
``--link-dir`` are errors while either is in effect, since nothing is rendered.
|
|
189
|
+
See :setting:`SYSTEMD_RENDER_DIR` for the matching ``render`` default.
|
|
190
|
+
|
|
191
|
+
Default: ``None`` (render units at install time)
|
|
@@ -233,10 +233,11 @@ directory:
|
|
|
233
233
|
|
|
234
234
|
.. code-block:: text
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
UNIT INSTALLED ENABLED ACTIVE SOURCE
|
|
237
|
+
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
238
|
+
mysite-web.service no - - /srv/mysite/deploy/systemd/mysite-web.service
|
|
239
|
+
mysite-dbcheck.service no - - /srv/mysite/deploy/systemd/mysite-dbcheck.service
|
|
240
|
+
mysite-dbcheck.timer no - - /srv/mysite/deploy/systemd/mysite-dbcheck.timer
|
|
240
241
|
|
|
241
242
|
Nothing is installed yet, so the state columns show ``-``. This command never
|
|
242
243
|
escalates and works anywhere, including a development machine without
|
|
@@ -329,10 +330,11 @@ Check the result:
|
|
|
329
330
|
|
|
330
331
|
.. code-block:: text
|
|
331
332
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
UNIT INSTALLED ENABLED ACTIVE SOURCE
|
|
334
|
+
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
335
|
+
mysite-web.service yes yes yes /srv/mysite/deploy/systemd/mysite-web.service
|
|
336
|
+
mysite-dbcheck.service yes yes no /srv/mysite/deploy/systemd/mysite-dbcheck.service
|
|
337
|
+
mysite-dbcheck.timer yes yes yes /srv/mysite/deploy/systemd/mysite-dbcheck.timer
|
|
336
338
|
|
|
337
339
|
The web service and the timer are active. The check service is not, which is
|
|
338
340
|
correct: a oneshot service is only active for the moment it runs. Its
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "django-systemd"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Ship renderable systemd unit templates with your apps and manage project services through the django admin."
|
|
9
9
|
requires-python = ">=3.11,<4.0"
|
|
10
10
|
authors = [
|
|
@@ -19,7 +19,8 @@ keywords = ["django", "CLI", "management", "Typer", "commands", "systemd", "serv
|
|
|
19
19
|
dependencies = [
|
|
20
20
|
"Django>=5.2,<6.2",
|
|
21
21
|
"django-render-static>=3.5.0",
|
|
22
|
-
"django-typer>=
|
|
22
|
+
"django-typer>=4",
|
|
23
|
+
"rich>=15.0.0",
|
|
23
24
|
]
|
|
24
25
|
classifiers = [
|
|
25
26
|
"Environment :: Console",
|
|
@@ -190,6 +190,33 @@ def link_dir() -> Path | None:
|
|
|
190
190
|
return path
|
|
191
191
|
|
|
192
192
|
|
|
193
|
+
def render_dir() -> Path | None:
|
|
194
|
+
"""
|
|
195
|
+
The ``SYSTEMD_RENDER_DIR`` setting: the default directory ``render`` writes
|
|
196
|
+
unit files into. A relative path is resolved against the current directory.
|
|
197
|
+
|
|
198
|
+
:return: A :class:`~pathlib.Path`, or ``None`` when unset.
|
|
199
|
+
"""
|
|
200
|
+
from django.conf import settings
|
|
201
|
+
|
|
202
|
+
value = getattr(settings, "SYSTEMD_RENDER_DIR", None)
|
|
203
|
+
return Path(value) if value else None
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def source_dir() -> Path | None:
|
|
207
|
+
"""
|
|
208
|
+
The ``SYSTEMD_SOURCE_DIR`` setting: the default directory ``install`` reads
|
|
209
|
+
pre-rendered unit files from instead of rendering them. A relative path is
|
|
210
|
+
resolved against the current directory.
|
|
211
|
+
|
|
212
|
+
:return: A :class:`~pathlib.Path`, or ``None`` when unset.
|
|
213
|
+
"""
|
|
214
|
+
from django.conf import settings
|
|
215
|
+
|
|
216
|
+
value = getattr(settings, "SYSTEMD_SOURCE_DIR", None)
|
|
217
|
+
return Path(value) if value else None
|
|
218
|
+
|
|
219
|
+
|
|
193
220
|
@cache
|
|
194
221
|
def template_engine_config() -> dict[str, t.Any]:
|
|
195
222
|
"""
|
{django_systemd-0.2.3 → django_systemd-0.4.0}/src/django_systemd/management/commands/systemd.py
RENAMED
|
@@ -33,6 +33,9 @@ from django.core.exceptions import ImproperlyConfigured
|
|
|
33
33
|
from django.core.management import CommandError
|
|
34
34
|
from django.template import TemplateDoesNotExist, TemplateSyntaxError
|
|
35
35
|
from django_typer.management import TyperCommand, command, initialize
|
|
36
|
+
from rich import box
|
|
37
|
+
from rich.console import Console
|
|
38
|
+
from rich.table import Table
|
|
36
39
|
|
|
37
40
|
from django_systemd.config import (
|
|
38
41
|
ServiceUnit,
|
|
@@ -40,7 +43,9 @@ from django_systemd.config import (
|
|
|
40
43
|
install_method,
|
|
41
44
|
link_dir,
|
|
42
45
|
project_units,
|
|
46
|
+
render_dir,
|
|
43
47
|
render_engine,
|
|
48
|
+
source_dir,
|
|
44
49
|
)
|
|
45
50
|
from django_systemd.config import scope as settings_scope
|
|
46
51
|
from django_systemd.defines import InstallMethod, SystemdScope, SystemdUnitType
|
|
@@ -106,6 +111,13 @@ def parse_context(pairs: list[str]) -> dict[str, str]:
|
|
|
106
111
|
return context
|
|
107
112
|
|
|
108
113
|
|
|
114
|
+
def _state(value: bool | None) -> str:
|
|
115
|
+
"""Rich markup for a yes/no unit state; ``None`` means it was not queried."""
|
|
116
|
+
if value is None:
|
|
117
|
+
return "[dim]-[/dim]"
|
|
118
|
+
return "[green]yes[/green]" if value else "[dim]no[/dim]"
|
|
119
|
+
|
|
120
|
+
|
|
109
121
|
class Command(TyperCommand):
|
|
110
122
|
"""
|
|
111
123
|
The ``systemd`` management command: list, render, install, uninstall,
|
|
@@ -256,24 +268,35 @@ class Command(TyperCommand):
|
|
|
256
268
|
if not self.units:
|
|
257
269
|
typer.echo("No systemd unit templates found.")
|
|
258
270
|
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
)
|
|
271
|
+
table = Table(box=box.SIMPLE_HEAD, header_style="bold")
|
|
272
|
+
table.add_column("UNIT", no_wrap=True)
|
|
273
|
+
table.add_column("INSTALLED")
|
|
274
|
+
table.add_column("ENABLED")
|
|
275
|
+
table.add_column("ACTIVE")
|
|
276
|
+
table.add_column("SOURCE", overflow="fold")
|
|
263
277
|
available = self.ctl.available
|
|
264
278
|
for unit in self.units:
|
|
265
279
|
installed = self.ctl.is_installed(unit.filename)
|
|
266
|
-
enabled = active =
|
|
280
|
+
enabled = active = None
|
|
267
281
|
if installed and available and not unit.instanceable:
|
|
268
282
|
try:
|
|
269
|
-
enabled =
|
|
270
|
-
active =
|
|
283
|
+
enabled = self.ctl.is_enabled(unit.filename)
|
|
284
|
+
active = self.ctl.is_active(unit.filename)
|
|
271
285
|
except subprocess.CalledProcessError as err:
|
|
272
286
|
raise CommandError(describe_failure(err)) from err
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
287
|
+
table.add_row(
|
|
288
|
+
unit.filename,
|
|
289
|
+
_state(installed),
|
|
290
|
+
_state(enabled),
|
|
291
|
+
_state(active),
|
|
292
|
+
str(unit.path),
|
|
276
293
|
)
|
|
294
|
+
console = Console()
|
|
295
|
+
if not console.is_terminal:
|
|
296
|
+
# Piped or captured output is read by tools, not people: never fold
|
|
297
|
+
# paths to a guessed width.
|
|
298
|
+
console = Console(width=max(console.width, 10_000))
|
|
299
|
+
console.print(table)
|
|
277
300
|
|
|
278
301
|
def _context(self, pairs: list[str] | None) -> dict[str, str]:
|
|
279
302
|
"""Parse --context overrides, refusing an override of the scope."""
|
|
@@ -288,13 +311,16 @@ class Command(TyperCommand):
|
|
|
288
311
|
output_dir: Annotated[
|
|
289
312
|
Path | None,
|
|
290
313
|
typer.Argument(
|
|
291
|
-
help="Directory to render unit files into. Defaults to the
|
|
314
|
+
help="Directory to render unit files into. Defaults to the "
|
|
315
|
+
"SYSTEMD_RENDER_DIR setting, or the current directory if unset."
|
|
292
316
|
),
|
|
293
317
|
] = None,
|
|
294
318
|
context: ContextOption = None,
|
|
295
319
|
) -> None:
|
|
296
320
|
"""Render this project's unit templates to a directory."""
|
|
297
|
-
rendered = self.render_units(
|
|
321
|
+
rendered = self.render_units(
|
|
322
|
+
output_dir or render_dir() or Path("."), self._context(context)
|
|
323
|
+
)
|
|
298
324
|
for _, path in rendered:
|
|
299
325
|
typer.echo(str(path))
|
|
300
326
|
|
|
@@ -344,7 +370,8 @@ class Command(TyperCommand):
|
|
|
344
370
|
Path | None,
|
|
345
371
|
typer.Option(
|
|
346
372
|
"--source",
|
|
347
|
-
help="Install pre-rendered unit files from this directory instead of
|
|
373
|
+
help="Install pre-rendered unit files from this directory instead of "
|
|
374
|
+
"rendering now. Defaults to the SYSTEMD_SOURCE_DIR setting.",
|
|
348
375
|
exists=True,
|
|
349
376
|
file_okay=False,
|
|
350
377
|
),
|
|
@@ -369,7 +396,8 @@ class Command(TyperCommand):
|
|
|
369
396
|
"""
|
|
370
397
|
Install this project's units into the unit directory.
|
|
371
398
|
|
|
372
|
-
Units are rendered first unless --source points at
|
|
399
|
+
Units are rendered first unless --source (or SYSTEMD_SOURCE_DIR) points at
|
|
400
|
+
pre-rendered files.
|
|
373
401
|
Running install again replaces the installed files, so this is also how
|
|
374
402
|
you update units after a deploy. With --method link, the rendered files
|
|
375
403
|
are kept in --link-dir and `systemctl link --force` places a symlink in
|
|
@@ -377,10 +405,20 @@ class Command(TyperCommand):
|
|
|
377
405
|
"""
|
|
378
406
|
if not self.units:
|
|
379
407
|
raise CommandError("No systemd unit templates found.")
|
|
408
|
+
if source is None:
|
|
409
|
+
source = self._setting(source_dir)
|
|
410
|
+
if source is not None and not source.is_dir():
|
|
411
|
+
raise CommandError(
|
|
412
|
+
f"SYSTEMD_SOURCE_DIR {source} does not exist or is not a directory."
|
|
413
|
+
)
|
|
380
414
|
if source is not None and context:
|
|
381
|
-
raise CommandError(
|
|
415
|
+
raise CommandError(
|
|
416
|
+
"--context has no effect with --source or SYSTEMD_SOURCE_DIR."
|
|
417
|
+
)
|
|
382
418
|
if source is not None and link_dir_option is not None:
|
|
383
|
-
raise CommandError(
|
|
419
|
+
raise CommandError(
|
|
420
|
+
"--link-dir has no effect with --source or SYSTEMD_SOURCE_DIR."
|
|
421
|
+
)
|
|
384
422
|
|
|
385
423
|
method = method or self._setting(install_method)
|
|
386
424
|
target_dir = link_dir_option or self._setting(link_dir)
|
|
@@ -18,8 +18,10 @@ from django_systemd.config import (
|
|
|
18
18
|
install_method,
|
|
19
19
|
link_dir,
|
|
20
20
|
project_units,
|
|
21
|
+
render_dir,
|
|
21
22
|
render_engine,
|
|
22
23
|
scope,
|
|
24
|
+
source_dir,
|
|
23
25
|
template_engine_config,
|
|
24
26
|
)
|
|
25
27
|
from django_systemd.defines import (
|
|
@@ -491,6 +493,20 @@ class TestInstallMethodSettings:
|
|
|
491
493
|
def test_defaults(self):
|
|
492
494
|
assert install_method() is InstallMethod.COPY
|
|
493
495
|
assert link_dir() is None
|
|
496
|
+
assert render_dir() is None
|
|
497
|
+
assert source_dir() is None
|
|
498
|
+
|
|
499
|
+
def test_source_dir_setting(self, tmp_path):
|
|
500
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(tmp_path)):
|
|
501
|
+
assert source_dir() == tmp_path
|
|
502
|
+
with override_settings(SYSTEMD_SOURCE_DIR=tmp_path):
|
|
503
|
+
assert source_dir() == tmp_path
|
|
504
|
+
|
|
505
|
+
def test_render_dir_setting(self, tmp_path):
|
|
506
|
+
with override_settings(SYSTEMD_RENDER_DIR=str(tmp_path)):
|
|
507
|
+
assert render_dir() == tmp_path
|
|
508
|
+
with override_settings(SYSTEMD_RENDER_DIR=tmp_path):
|
|
509
|
+
assert render_dir() == tmp_path
|
|
494
510
|
|
|
495
511
|
def test_link_settings(self, tmp_path):
|
|
496
512
|
with override_settings(
|
|
@@ -470,6 +470,57 @@ class TestLinkInstall:
|
|
|
470
470
|
"systemd", "install", "--method", "link", "--link-dir", str(target)
|
|
471
471
|
)
|
|
472
472
|
|
|
473
|
+
def test_link_from_source_dir_setting(self, fake_ctl, tmp_path):
|
|
474
|
+
source = tmp_path / "pre"
|
|
475
|
+
source.mkdir()
|
|
476
|
+
for name in ("web.service", "check.timer", "app@.target"):
|
|
477
|
+
(source / name).write_text("pre")
|
|
478
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(source)):
|
|
479
|
+
call_command("systemd", "install", "--method", "link")
|
|
480
|
+
assert (fake_ctl.unit_dir / "web.service").resolve() == (
|
|
481
|
+
source / "web.service"
|
|
482
|
+
).resolve()
|
|
483
|
+
|
|
484
|
+
def test_relative_source_dir_setting_is_relative_to_cwd(
|
|
485
|
+
self, fake_ctl, tmp_path, monkeypatch
|
|
486
|
+
):
|
|
487
|
+
monkeypatch.chdir(tmp_path)
|
|
488
|
+
(tmp_path / "pre").mkdir()
|
|
489
|
+
for name in ("web.service", "check.timer", "app@.target"):
|
|
490
|
+
(tmp_path / "pre" / name).write_text("pre")
|
|
491
|
+
with override_settings(SYSTEMD_SOURCE_DIR="pre"):
|
|
492
|
+
call_command("systemd", "install")
|
|
493
|
+
assert (fake_ctl.unit_dir / "web.service").read_text() == "pre"
|
|
494
|
+
|
|
495
|
+
def test_source_option_overrides_setting(self, fake_ctl, tmp_path):
|
|
496
|
+
source = tmp_path / "pre"
|
|
497
|
+
source.mkdir()
|
|
498
|
+
for name in ("web.service", "check.timer", "app@.target"):
|
|
499
|
+
(source / name).write_text("explicit")
|
|
500
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(tmp_path / "missing")):
|
|
501
|
+
call_command("systemd", "install", "--source", str(source))
|
|
502
|
+
assert (fake_ctl.unit_dir / "web.service").read_text() == "explicit"
|
|
503
|
+
|
|
504
|
+
def test_missing_source_dir_setting_is_a_command_error(self, fake_ctl, tmp_path):
|
|
505
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(tmp_path / "missing")):
|
|
506
|
+
with pytest.raises(CommandError, match="SYSTEMD_SOURCE_DIR"):
|
|
507
|
+
call_command("systemd", "install")
|
|
508
|
+
assert fake_ctl.calls == []
|
|
509
|
+
|
|
510
|
+
def test_link_dir_with_source_dir_setting_is_an_error(self, fake_ctl, tmp_path):
|
|
511
|
+
source = tmp_path / "pre"
|
|
512
|
+
source.mkdir()
|
|
513
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(source)):
|
|
514
|
+
with pytest.raises(CommandError, match="SYSTEMD_SOURCE_DIR"):
|
|
515
|
+
call_command("systemd", "install", "--link-dir", str(tmp_path / "r"))
|
|
516
|
+
|
|
517
|
+
def test_context_with_source_dir_setting_is_an_error(self, fake_ctl, tmp_path):
|
|
518
|
+
source = tmp_path / "pre"
|
|
519
|
+
source.mkdir()
|
|
520
|
+
with override_settings(SYSTEMD_SOURCE_DIR=str(source)):
|
|
521
|
+
with pytest.raises(CommandError, match="--context"):
|
|
522
|
+
call_command("systemd", "install", "-c", "venv=/x")
|
|
523
|
+
|
|
473
524
|
def test_link_dir_with_source_is_an_error(self, fake_ctl, tmp_path):
|
|
474
525
|
source = tmp_path / "pre"
|
|
475
526
|
source.mkdir()
|
|
@@ -622,7 +673,9 @@ class TestList:
|
|
|
622
673
|
call_command("systemd", "list")
|
|
623
674
|
out = capsys.readouterr().out
|
|
624
675
|
assert fake_ctl.calls == []
|
|
625
|
-
row = next(
|
|
676
|
+
row = next(
|
|
677
|
+
line for line in out.splitlines() if line.strip().startswith("web.service")
|
|
678
|
+
)
|
|
626
679
|
assert row.split()[1:4] == ["no", "-", "-"]
|
|
627
680
|
|
|
628
681
|
def test_installed_rows_show_state(self, fake_ctl, capsys):
|
|
@@ -631,7 +684,9 @@ class TestList:
|
|
|
631
684
|
fake_ctl.active.add("web.service")
|
|
632
685
|
call_command("systemd", "list")
|
|
633
686
|
out = capsys.readouterr().out
|
|
634
|
-
row = next(
|
|
687
|
+
row = next(
|
|
688
|
+
line for line in out.splitlines() if line.strip().startswith("web.service")
|
|
689
|
+
)
|
|
635
690
|
assert row.split()[1:4] == ["yes", "no", "yes"]
|
|
636
691
|
|
|
637
692
|
def test_instanceable_units_are_never_queried(self, fake_ctl, capsys):
|
|
@@ -639,7 +694,9 @@ class TestList:
|
|
|
639
694
|
(fake_ctl.unit_dir / "app@.target").write_text("x")
|
|
640
695
|
call_command("systemd", "list")
|
|
641
696
|
out = capsys.readouterr().out
|
|
642
|
-
row = next(
|
|
697
|
+
row = next(
|
|
698
|
+
line for line in out.splitlines() if line.strip().startswith("app@.target")
|
|
699
|
+
)
|
|
643
700
|
assert row.split()[1:4] == ["yes", "-", "-"]
|
|
644
701
|
assert fake_ctl.calls == []
|
|
645
702
|
|
|
@@ -658,7 +715,7 @@ class TestList:
|
|
|
658
715
|
row = next(
|
|
659
716
|
line
|
|
660
717
|
for line in capsys.readouterr().out.splitlines()
|
|
661
|
-
if line.startswith("web.service")
|
|
718
|
+
if line.strip().startswith("web.service")
|
|
662
719
|
)
|
|
663
720
|
assert row.split()[1:4] == ["yes", "-", "-"]
|
|
664
721
|
|
|
@@ -678,6 +735,25 @@ class TestRender:
|
|
|
678
735
|
call_command("systemd", "render")
|
|
679
736
|
assert (tmp_path / "web.service").is_file()
|
|
680
737
|
|
|
738
|
+
def test_default_dir_from_setting(self, fake_ctl, tmp_path, monkeypatch):
|
|
739
|
+
monkeypatch.chdir(tmp_path)
|
|
740
|
+
with override_settings(SYSTEMD_RENDER_DIR=str(tmp_path / "units")):
|
|
741
|
+
call_command("systemd", "render")
|
|
742
|
+
assert (tmp_path / "units" / "web.service").is_file()
|
|
743
|
+
assert not (tmp_path / "web.service").exists()
|
|
744
|
+
|
|
745
|
+
def test_relative_setting_is_relative_to_cwd(self, fake_ctl, tmp_path, monkeypatch):
|
|
746
|
+
monkeypatch.chdir(tmp_path)
|
|
747
|
+
with override_settings(SYSTEMD_RENDER_DIR="units"):
|
|
748
|
+
call_command("systemd", "render")
|
|
749
|
+
assert (tmp_path / "units" / "web.service").is_file()
|
|
750
|
+
|
|
751
|
+
def test_argument_overrides_setting(self, fake_ctl, tmp_path):
|
|
752
|
+
with override_settings(SYSTEMD_RENDER_DIR=str(tmp_path / "units")):
|
|
753
|
+
call_command("systemd", "render", str(tmp_path / "explicit"))
|
|
754
|
+
assert (tmp_path / "explicit" / "web.service").is_file()
|
|
755
|
+
assert not (tmp_path / "units").exists()
|
|
756
|
+
|
|
681
757
|
def test_highest_precedence_content(self, fake_ctl, tmp_path):
|
|
682
758
|
call_command("systemd", "render", str(tmp_path))
|
|
683
759
|
assert "app2 override" in (tmp_path / "web.service").read_text()
|