utilifex 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.
- utilifex-0.1.0/.gitignore +17 -0
- utilifex-0.1.0/LICENSE +21 -0
- utilifex-0.1.0/PKG-INFO +208 -0
- utilifex-0.1.0/README.md +163 -0
- utilifex-0.1.0/VERSION +1 -0
- utilifex-0.1.0/lib/bash/args.sh +362 -0
- utilifex-0.1.0/lib/bash/dryrun.sh +64 -0
- utilifex-0.1.0/lib/bash/files.sh +282 -0
- utilifex-0.1.0/lib/bash/git.sh +66 -0
- utilifex-0.1.0/lib/bash/headers.sh +94 -0
- utilifex-0.1.0/lib/bash/json.sh +358 -0
- utilifex-0.1.0/lib/bash/log.sh +202 -0
- utilifex-0.1.0/lib/bash/portable.sh +333 -0
- utilifex-0.1.0/lib/bash/sampling.sh +45 -0
- utilifex-0.1.0/lib/bash/targets.sh +188 -0
- utilifex-0.1.0/lib/bash/template.sh +144 -0
- utilifex-0.1.0/lib/bash/traps.sh +163 -0
- utilifex-0.1.0/pyproject.toml +234 -0
- utilifex-0.1.0/src/utilifex/__init__.py +15 -0
- utilifex-0.1.0/src/utilifex/cli.py +457 -0
- utilifex-0.1.0/src/utilifex/conditions.py +46 -0
- utilifex-0.1.0/src/utilifex/config_check.py +184 -0
- utilifex-0.1.0/src/utilifex/deps.py +378 -0
- utilifex-0.1.0/src/utilifex/files.py +233 -0
- utilifex-0.1.0/src/utilifex/headers.py +155 -0
- utilifex-0.1.0/src/utilifex/job/__init__.py +6 -0
- utilifex-0.1.0/src/utilifex/job/admission.py +268 -0
- utilifex-0.1.0/src/utilifex/job/cli.py +203 -0
- utilifex-0.1.0/src/utilifex/job/errors.py +22 -0
- utilifex-0.1.0/src/utilifex/job/ledger.py +81 -0
- utilifex-0.1.0/src/utilifex/job/locks.py +156 -0
- utilifex-0.1.0/src/utilifex/job/memory.py +33 -0
- utilifex-0.1.0/src/utilifex/job/runner.py +341 -0
- utilifex-0.1.0/src/utilifex/job/sizing.py +84 -0
- utilifex-0.1.0/src/utilifex/job/supervise.py +80 -0
- utilifex-0.1.0/src/utilifex/log.py +167 -0
- utilifex-0.1.0/src/utilifex/portable.py +184 -0
- utilifex-0.1.0/src/utilifex/proc.py +111 -0
- utilifex-0.1.0/src/utilifex/redirects.py +81 -0
- utilifex-0.1.0/src/utilifex/report.py +267 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# What building, testing and documenting this repository creates in the clone.
|
|
2
|
+
|
|
3
|
+
# The environment `uv sync` makes.
|
|
4
|
+
.venv/
|
|
5
|
+
# Python's bytecode caches.
|
|
6
|
+
__pycache__/
|
|
7
|
+
# pytest's and ruff's caches.
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
# Coverage data (pytest-cov, one file per process) and the report CI's coverage job writes.
|
|
11
|
+
.coverage
|
|
12
|
+
.coverage.*
|
|
13
|
+
coverage.xml
|
|
14
|
+
# `uv build`.
|
|
15
|
+
dist/
|
|
16
|
+
# `mkdocs build`.
|
|
17
|
+
site/
|
utilifex-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mahdi Shafiei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
utilifex-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: utilifex
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The utilifex-job command and the Python support library of the utilifex toolkit; its shell and Python scripts are installed from a clone.
|
|
5
|
+
Project-URL: Changelog, https://github.com/avitai/utilifex/blob/main/CHANGELOG.md
|
|
6
|
+
Project-URL: Documentation, https://utilifex.readthedocs.io
|
|
7
|
+
Project-URL: Issues, https://github.com/avitai/utilifex/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/avitai/utilifex
|
|
9
|
+
Author-email: Mahdi Shafiei <mahdi@avitai.bio>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: bash,cli,devops,scripts,sysadmin,toolkit
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
25
|
+
Classifier: Topic :: System :: Systems Administration
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: click>=8.0
|
|
28
|
+
Requires-Dist: psutil>=6.0
|
|
29
|
+
Requires-Dist: pyyaml>=6.0
|
|
30
|
+
Requires-Dist: typer<0.26,>=0.12
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: bandit>=1.7; extra == 'dev'
|
|
33
|
+
Requires-Dist: deptry>=0.25; extra == 'dev'
|
|
34
|
+
Requires-Dist: interrogate>=1.7; extra == 'dev'
|
|
35
|
+
Requires-Dist: pre-commit>=3.7; extra == 'dev'
|
|
36
|
+
Requires-Dist: pyright>=1.1.380; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-timeout>=2.3; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
40
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
41
|
+
Requires-Dist: shellcheck-py>=0.10.0.1; extra == 'dev'
|
|
42
|
+
Provides-Extra: docs
|
|
43
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# utilifex
|
|
47
|
+
|
|
48
|
+
[](https://github.com/avitai/utilifex/actions/workflows/ci.yml)
|
|
49
|
+
[](https://github.com/avitai/utilifex/blob/main/LICENSE)
|
|
50
|
+
[](https://github.com/avitai/utilifex/blob/main/.pre-commit-config.yaml)
|
|
51
|
+
[](https://www.conventionalcommits.org)
|
|
52
|
+
|
|
53
|
+
Shell and Python scripts for the jobs a Linux or macOS machine needs done (backups, database checks, certificate, SSH and firewall audits, journal and disk cleanup, Git housekeeping), each with its tests and a guide to choosing and using it. It is for system administrators and developers who run servers or workstations and want scripts that check their input before they act, offer a dry run, and exit non-zero when they could not do their job.
|
|
54
|
+
|
|
55
|
+
[Documentation](https://github.com/avitai/utilifex/blob/main/docs/index.md) | [Recipes](https://github.com/avitai/utilifex/tree/main/docs/recipes) | [Style guide](https://github.com/avitai/utilifex/blob/main/docs/style.md) | [Changelog](https://github.com/avitai/utilifex/blob/main/CHANGELOG.md) | [Issues](https://github.com/avitai/utilifex/issues) | [Contributing](https://github.com/avitai/utilifex/blob/main/docs/development/contributing.md)
|
|
56
|
+
|
|
57
|
+
> **Status: before 1.0.** The scripts, their options and the installed command names can still change, and every such change is listed in `CHANGELOG.md` marked **Breaking** ([what you can rely on](https://github.com/avitai/utilifex/blob/main/docs/maintainers.md#compatibility-what-a-user-can-rely-on-before-10)). The [changelog](https://github.com/avitai/utilifex/blob/main/CHANGELOG.md) lists each release and what it ships. The scripts are installed from a clone; the package on PyPI, `utilifex`, holds the job tool and the Python support library only (see Install below).
|
|
58
|
+
|
|
59
|
+
**Every script carries a release status: of the fifty, thirty-five are released and fifteen are held.** A held script is not ready to rely on, for the reason its header gives: it stays in the repository, tested, says it is held whenever it runs, and the installer leaves it out unless asked; the [per-category indices](https://github.com/avitai/utilifex/tree/main/docs/per-category) list which is which, and why each held one is held.
|
|
60
|
+
|
|
61
|
+
## What it is
|
|
62
|
+
|
|
63
|
+
Fifty scripts in thirteen categories, written to one set of conventions and installed as commands named `utilifex-<category>-<name>`. Each category has its scripts, a guide and tests. Every category except `file-transfer` also has a comparison of the tools in its area and worked recipes.
|
|
64
|
+
|
|
65
|
+
| Category | Scripts for |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `automation` | auditing cron, generating systemd timers, deployment and Ansible preflight checks |
|
|
68
|
+
| `backup` | restic and borg snapshots, preflight checks, restore drills, off-site copies |
|
|
69
|
+
| `database` | migration safety checks, replication lag, slow queries, dump rotation |
|
|
70
|
+
| `development` | dependency checks, log anomalies, `strace` and `gdb` wrappers |
|
|
71
|
+
| `docker` | Compose linting, image vulnerability scans, image size audits, registry cleanup |
|
|
72
|
+
| `file-transfer` | resumable `rsync` and large copies |
|
|
73
|
+
| `git` | branch cleanup, safe rebases, signed-commit checks, worktrees |
|
|
74
|
+
| `monitoring` | SLO burn-rate alert rules, Prometheus rule tests, Alertmanager silences, Promtail to Alloy |
|
|
75
|
+
| `networking` | port probes, DNS health, firewall drift, WireGuard configuration |
|
|
76
|
+
| `performance` | benchmark runs, regression checks, flame graphs, memory tracking |
|
|
77
|
+
| `security` | certificate expiry, `sshd` audits, secret scans, permission audits |
|
|
78
|
+
| `system` | boot-time analysis, journal cleanup, cgroup v2 and pressure snapshots, unit health |
|
|
79
|
+
| `text-processing` | configuration validation, CSV transforms, JSON flattening, NDJSON search |
|
|
80
|
+
|
|
81
|
+
Five end-to-end [recipes](https://github.com/avitai/utilifex/tree/main/docs/recipes) combine scripts from several categories: hardening a Debian VM, a single-host observability stack, a Postgres region migration, self-hosted Gitea with CI runners, and a disaster-recovery drill.
|
|
82
|
+
|
|
83
|
+
## Install
|
|
84
|
+
|
|
85
|
+
There are two ways in, and they install different things.
|
|
86
|
+
|
|
87
|
+
### The scripts: from a clone, with `bin/install.sh`
|
|
88
|
+
|
|
89
|
+
The 31 shell scripts need `bash` 4.3 or later. The 19 Python scripts need Python 3.11 or later and run in the clone's own environment, which `uv` builds from the lock. Some scripts need further tools (`rsync`, `restic`, `docker` and so on); `bin/check-deps` reports which of the commands each script names are installed.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
git clone https://github.com/avitai/utilifex.git
|
|
93
|
+
cd utilifex
|
|
94
|
+
uv sync --locked # the Python scripts' environment, into .venv
|
|
95
|
+
bin/install.sh # installs the released scripts as commands in ~/.local/bin
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Each installed command is a short launcher that names its script in the clone, and for a Python script the clone's interpreter, `.venv/bin/python`, so a command runs from any shell with no environment activated and the clone stays the one copy. `bin/install.sh` installs the released scripts only, builds the environment in the clone's `.venv` if it is missing (whatever `UV_PROJECT_ENVIRONMENT` says), and checks that every command it wrote can start before it reports success. Run it again after moving the clone. It takes:
|
|
99
|
+
|
|
100
|
+
| Option | Effect |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `--prefix DIR` | install into `DIR` in place of `~/.local/bin` |
|
|
103
|
+
| `--only=git,docker` | install these categories only |
|
|
104
|
+
| `--list` | print what would be installed, each script with its status, and change nothing |
|
|
105
|
+
| `--include-held` | install the held scripts too |
|
|
106
|
+
| `--dry-run` | print each action without performing it, and change nothing |
|
|
107
|
+
| `--uninstall` | remove the launchers it wrote |
|
|
108
|
+
|
|
109
|
+
`~/.local/bin` has to be on your `PATH`.
|
|
110
|
+
|
|
111
|
+
Each script's header gives its status: `released`, or `held` with the reason it is not ready to rely on. A held script stays in the repository, tested, and is marked wherever it appears: its `--help` and every run say it is held, `bin/install.sh` installs it only with `--include-held`, and its category index lists it under "Held, not yet released". Which scripts are released and which are held, each held one with its reason, is in the [per-category indices](https://github.com/avitai/utilifex/tree/main/docs/per-category), generated from the headers; `bin/find-script --status held` lists the held ones (the Python tools under `bin/` run under the clone's interpreter, so they work from the clone once `uv sync --locked` has made it). See the [style guide](https://github.com/avitai/utilifex/blob/main/docs/style.md#release-status).
|
|
112
|
+
|
|
113
|
+
### The job tool and the support library: from PyPI
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install utilifex # into the active Python environment
|
|
117
|
+
uv tool install utilifex # or as a tool of its own, on PATH
|
|
118
|
+
utilifex-job --version
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This installs the Python package `utilifex`, the support library the Python scripts build on (`utilifex.cli`, `utilifex.report` and the other helpers), and one command, `utilifex-job` (see [Sharing one machine](https://github.com/avitai/utilifex/blob/main/README.md#sharing-one-machine)); it needs Python 3.11 or later. It does not install the fifty scripts or the shell library under `lib/bash/`: those are installed from a clone as above, whose `bin/install.sh` also installs `utilifex-job`, as a launcher for the same command.
|
|
122
|
+
|
|
123
|
+
## Quick start
|
|
124
|
+
|
|
125
|
+
Every script answers `--help`. Run a shell script from the clone or by its installed name; run a Python script by its installed name, or from the clone with `uv run --no-sync`:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
./scripts/git/nuke-merged-branches.sh --help
|
|
129
|
+
utilifex-git-nuke-merged-branches --base main --dry-run
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Find a script by what it does, and see what a category holds:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
utilifex-find-script --category backup
|
|
136
|
+
bin/install.sh --list --only=backup
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Sharing one machine
|
|
140
|
+
|
|
141
|
+
`utilifex-job` runs a command on a machine that several independent processes share, such as
|
|
142
|
+
coding agents working in different repositories. It is installed either way above: by
|
|
143
|
+
`pip install utilifex`, or from a clone by `bin/install.sh`, whose launcher runs `bin/job`.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
utilifex-job run --memory 6G myrepo -- uv run pytest # heavy work
|
|
147
|
+
utilifex-job measure --wait 600 myrepo -- python bench.py # a timing, with the machine to itself
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Heavy jobs run beside each other. A measurement waits until no heavy job started through
|
|
151
|
+
`utilifex-job` with the same state directory is running, and new heavy work started that way
|
|
152
|
+
queues behind it; a process started any other way is not seen. The memory a job declares is a hard limit on Linux, where a systemd user scope
|
|
153
|
+
enforces it and stops every process the job started. macOS offers no memory limit for a process
|
|
154
|
+
tree, so there the tool says the limit is not enforced.
|
|
155
|
+
|
|
156
|
+
Every job leaves one line in `jobs.jsonl` in the tool's state directory: what it declared, how it
|
|
157
|
+
ended, and the most memory it held. On Linux that peak is the kernel's figure for the whole job.
|
|
158
|
+
On macOS it is the largest sum that sampling saw over the job's processes, a lower bound, and is
|
|
159
|
+
marked `sampled`. The state directory is `$UTILIFEX_JOB_STATE_DIR` when that is set, otherwise
|
|
160
|
+
`$XDG_STATE_HOME/utilifex/job`, with `~/.local/state` standing in for an unset `XDG_STATE_HOME`.
|
|
161
|
+
|
|
162
|
+
A job states its memory the first time. After that `--memory` can be left out, and the job is
|
|
163
|
+
given 1.15 times the largest peak its label has on record, or 1.2 times a limit it met. The
|
|
164
|
+
Kubernetes Vertical Pod Autoscaler's recommender uses the same figures by default: a
|
|
165
|
+
`recommendation-margin-fraction` of 0.15 ("Fraction of usage added as the safety margin to the
|
|
166
|
+
recommended request") and an `oom-bump-up-ratio` of 1.2 ("Default memory bump up ratio when OOM
|
|
167
|
+
occurs"), per its [flags reference](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/docs/flags.md).
|
|
168
|
+
A peak recorded at its limit counts as a limit met, since the job would have used more.
|
|
169
|
+
|
|
170
|
+
A heavy job starts only when its memory fits beside the jobs already running: its request, plus
|
|
171
|
+
what each running job may still grow into, plus a reserve, must be no more than the memory the
|
|
172
|
+
system reports as available. Otherwise it waits, says what it is waiting for, and is tried again
|
|
173
|
+
as memory moves. Jobs are admitted in the order they arrived. The reserve is a tenth of the
|
|
174
|
+
machine's memory, the minimum `earlyoom` keeps available by default ("set available memory
|
|
175
|
+
minimum to PERCENT of total (default 10 %)", [earlyoom's README](https://github.com/rfjakob/earlyoom));
|
|
176
|
+
`UTILIFEX_JOB_RESERVE=8G` states another. A job that could never fit is refused.
|
|
177
|
+
|
|
178
|
+
The tool exits with the job's status. It reserves 75 for a measurement that could not get the
|
|
179
|
+
machine, 125 for a failure of the tool itself, 137 for a job killed at its limit, and 130 for an
|
|
180
|
+
interruption before a job started.
|
|
181
|
+
|
|
182
|
+
### What every script shares
|
|
183
|
+
|
|
184
|
+
The conventions live in [`lib/bash/`](https://github.com/avitai/utilifex/tree/main/lib/bash) and [`src/utilifex/`](https://github.com/avitai/utilifex/tree/main/src/utilifex), and `bin/new-script` generates a script that already follows them.
|
|
185
|
+
|
|
186
|
+
- `-h` or `--help`, `--version`, `-n` or `--dry-run`, `--log-level=DEBUG|INFO|WARN|ERROR`.
|
|
187
|
+
- `--json-report=PATH` writes a report with the fields `schema_version`, `name`, `category`, `version`, `started_at`, `ended_at`, `duration_seconds`, `exit_code`, `status`, `host`, `os`, `user`, `log_file`, `params`, `counts`, `errors` and `warnings`. Shell and Python scripts write the same fields, and a test checks that they do.
|
|
188
|
+
- Shell scripts start with `#!/usr/bin/env bash` and `set -Eeuo pipefail`, and clean up on interrupt.
|
|
189
|
+
- Settings come from `UTILIFEX_*` environment variables, for example `UTILIFEX_LOG_LEVEL`.
|
|
190
|
+
|
|
191
|
+
## How it is tested
|
|
192
|
+
|
|
193
|
+
- Every pull request runs the `bats` tests on Ubuntu and the shared shell library's `bats` tests on Alpine and Debian. The Python tests run under `pytest` on Python 3.11, 3.12, 3.13, 3.14 and 3.15, with a coverage floor of 80% over `src/utilifex/` and the Python scripts under `scripts/` together. A nightly run repeats the tests on macOS when `main` has moved.
|
|
194
|
+
- A test installs every script and runs each installed command from a shell whose environment holds only `PATH` and `HOME`.
|
|
195
|
+
- Each script has its own tests under [`tests/scripts/`](https://github.com/avitai/utilifex/tree/main/tests/scripts). `make test` and continuous integration run all of them. Run `make setup-check` first: it reports what a development machine lacks and how to install it. A test never skips for want of a tool; a test run that lacks one stops before its first test, naming each one missing and the command that installs it.
|
|
196
|
+
- Commit hooks run `shellcheck`, `shfmt`, `ruff`, `pyright` in strict mode, `bandit`, `gitleaks`, `detect-secrets`, docstring coverage, Markdown and YAML linting, and a Conventional Commits check on the commit message.
|
|
197
|
+
|
|
198
|
+
## Contributing
|
|
199
|
+
|
|
200
|
+
See the [contributor guide](https://github.com/avitai/utilifex/blob/main/docs/development/contributing.md). How dependencies are updated, and what stays stable between versions before 1.0, is in the [maintainers' runbook](https://github.com/avitai/utilifex/blob/main/docs/maintainers.md).
|
|
201
|
+
|
|
202
|
+
## Security
|
|
203
|
+
|
|
204
|
+
Report a vulnerability as described in [`SECURITY.md`](https://github.com/avitai/utilifex/blob/main/SECURITY.md). The [threat model](https://github.com/avitai/utilifex/blob/main/docs/threat-model.md) says what the scripts assume and what they enforce.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
[MIT License](https://github.com/avitai/utilifex/blob/main/LICENSE).
|
utilifex-0.1.0/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# utilifex
|
|
2
|
+
|
|
3
|
+
[](https://github.com/avitai/utilifex/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/avitai/utilifex/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/avitai/utilifex/blob/main/.pre-commit-config.yaml)
|
|
6
|
+
[](https://www.conventionalcommits.org)
|
|
7
|
+
|
|
8
|
+
Shell and Python scripts for the jobs a Linux or macOS machine needs done (backups, database checks, certificate, SSH and firewall audits, journal and disk cleanup, Git housekeeping), each with its tests and a guide to choosing and using it. It is for system administrators and developers who run servers or workstations and want scripts that check their input before they act, offer a dry run, and exit non-zero when they could not do their job.
|
|
9
|
+
|
|
10
|
+
[Documentation](https://github.com/avitai/utilifex/blob/main/docs/index.md) | [Recipes](https://github.com/avitai/utilifex/tree/main/docs/recipes) | [Style guide](https://github.com/avitai/utilifex/blob/main/docs/style.md) | [Changelog](https://github.com/avitai/utilifex/blob/main/CHANGELOG.md) | [Issues](https://github.com/avitai/utilifex/issues) | [Contributing](https://github.com/avitai/utilifex/blob/main/docs/development/contributing.md)
|
|
11
|
+
|
|
12
|
+
> **Status: before 1.0.** The scripts, their options and the installed command names can still change, and every such change is listed in `CHANGELOG.md` marked **Breaking** ([what you can rely on](https://github.com/avitai/utilifex/blob/main/docs/maintainers.md#compatibility-what-a-user-can-rely-on-before-10)). The [changelog](https://github.com/avitai/utilifex/blob/main/CHANGELOG.md) lists each release and what it ships. The scripts are installed from a clone; the package on PyPI, `utilifex`, holds the job tool and the Python support library only (see Install below).
|
|
13
|
+
|
|
14
|
+
**Every script carries a release status: of the fifty, thirty-five are released and fifteen are held.** A held script is not ready to rely on, for the reason its header gives: it stays in the repository, tested, says it is held whenever it runs, and the installer leaves it out unless asked; the [per-category indices](https://github.com/avitai/utilifex/tree/main/docs/per-category) list which is which, and why each held one is held.
|
|
15
|
+
|
|
16
|
+
## What it is
|
|
17
|
+
|
|
18
|
+
Fifty scripts in thirteen categories, written to one set of conventions and installed as commands named `utilifex-<category>-<name>`. Each category has its scripts, a guide and tests. Every category except `file-transfer` also has a comparison of the tools in its area and worked recipes.
|
|
19
|
+
|
|
20
|
+
| Category | Scripts for |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `automation` | auditing cron, generating systemd timers, deployment and Ansible preflight checks |
|
|
23
|
+
| `backup` | restic and borg snapshots, preflight checks, restore drills, off-site copies |
|
|
24
|
+
| `database` | migration safety checks, replication lag, slow queries, dump rotation |
|
|
25
|
+
| `development` | dependency checks, log anomalies, `strace` and `gdb` wrappers |
|
|
26
|
+
| `docker` | Compose linting, image vulnerability scans, image size audits, registry cleanup |
|
|
27
|
+
| `file-transfer` | resumable `rsync` and large copies |
|
|
28
|
+
| `git` | branch cleanup, safe rebases, signed-commit checks, worktrees |
|
|
29
|
+
| `monitoring` | SLO burn-rate alert rules, Prometheus rule tests, Alertmanager silences, Promtail to Alloy |
|
|
30
|
+
| `networking` | port probes, DNS health, firewall drift, WireGuard configuration |
|
|
31
|
+
| `performance` | benchmark runs, regression checks, flame graphs, memory tracking |
|
|
32
|
+
| `security` | certificate expiry, `sshd` audits, secret scans, permission audits |
|
|
33
|
+
| `system` | boot-time analysis, journal cleanup, cgroup v2 and pressure snapshots, unit health |
|
|
34
|
+
| `text-processing` | configuration validation, CSV transforms, JSON flattening, NDJSON search |
|
|
35
|
+
|
|
36
|
+
Five end-to-end [recipes](https://github.com/avitai/utilifex/tree/main/docs/recipes) combine scripts from several categories: hardening a Debian VM, a single-host observability stack, a Postgres region migration, self-hosted Gitea with CI runners, and a disaster-recovery drill.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
There are two ways in, and they install different things.
|
|
41
|
+
|
|
42
|
+
### The scripts: from a clone, with `bin/install.sh`
|
|
43
|
+
|
|
44
|
+
The 31 shell scripts need `bash` 4.3 or later. The 19 Python scripts need Python 3.11 or later and run in the clone's own environment, which `uv` builds from the lock. Some scripts need further tools (`rsync`, `restic`, `docker` and so on); `bin/check-deps` reports which of the commands each script names are installed.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/avitai/utilifex.git
|
|
48
|
+
cd utilifex
|
|
49
|
+
uv sync --locked # the Python scripts' environment, into .venv
|
|
50
|
+
bin/install.sh # installs the released scripts as commands in ~/.local/bin
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Each installed command is a short launcher that names its script in the clone, and for a Python script the clone's interpreter, `.venv/bin/python`, so a command runs from any shell with no environment activated and the clone stays the one copy. `bin/install.sh` installs the released scripts only, builds the environment in the clone's `.venv` if it is missing (whatever `UV_PROJECT_ENVIRONMENT` says), and checks that every command it wrote can start before it reports success. Run it again after moving the clone. It takes:
|
|
54
|
+
|
|
55
|
+
| Option | Effect |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `--prefix DIR` | install into `DIR` in place of `~/.local/bin` |
|
|
58
|
+
| `--only=git,docker` | install these categories only |
|
|
59
|
+
| `--list` | print what would be installed, each script with its status, and change nothing |
|
|
60
|
+
| `--include-held` | install the held scripts too |
|
|
61
|
+
| `--dry-run` | print each action without performing it, and change nothing |
|
|
62
|
+
| `--uninstall` | remove the launchers it wrote |
|
|
63
|
+
|
|
64
|
+
`~/.local/bin` has to be on your `PATH`.
|
|
65
|
+
|
|
66
|
+
Each script's header gives its status: `released`, or `held` with the reason it is not ready to rely on. A held script stays in the repository, tested, and is marked wherever it appears: its `--help` and every run say it is held, `bin/install.sh` installs it only with `--include-held`, and its category index lists it under "Held, not yet released". Which scripts are released and which are held, each held one with its reason, is in the [per-category indices](https://github.com/avitai/utilifex/tree/main/docs/per-category), generated from the headers; `bin/find-script --status held` lists the held ones (the Python tools under `bin/` run under the clone's interpreter, so they work from the clone once `uv sync --locked` has made it). See the [style guide](https://github.com/avitai/utilifex/blob/main/docs/style.md#release-status).
|
|
67
|
+
|
|
68
|
+
### The job tool and the support library: from PyPI
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install utilifex # into the active Python environment
|
|
72
|
+
uv tool install utilifex # or as a tool of its own, on PATH
|
|
73
|
+
utilifex-job --version
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This installs the Python package `utilifex`, the support library the Python scripts build on (`utilifex.cli`, `utilifex.report` and the other helpers), and one command, `utilifex-job` (see [Sharing one machine](https://github.com/avitai/utilifex/blob/main/README.md#sharing-one-machine)); it needs Python 3.11 or later. It does not install the fifty scripts or the shell library under `lib/bash/`: those are installed from a clone as above, whose `bin/install.sh` also installs `utilifex-job`, as a launcher for the same command.
|
|
77
|
+
|
|
78
|
+
## Quick start
|
|
79
|
+
|
|
80
|
+
Every script answers `--help`. Run a shell script from the clone or by its installed name; run a Python script by its installed name, or from the clone with `uv run --no-sync`:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
./scripts/git/nuke-merged-branches.sh --help
|
|
84
|
+
utilifex-git-nuke-merged-branches --base main --dry-run
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Find a script by what it does, and see what a category holds:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
utilifex-find-script --category backup
|
|
91
|
+
bin/install.sh --list --only=backup
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Sharing one machine
|
|
95
|
+
|
|
96
|
+
`utilifex-job` runs a command on a machine that several independent processes share, such as
|
|
97
|
+
coding agents working in different repositories. It is installed either way above: by
|
|
98
|
+
`pip install utilifex`, or from a clone by `bin/install.sh`, whose launcher runs `bin/job`.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
utilifex-job run --memory 6G myrepo -- uv run pytest # heavy work
|
|
102
|
+
utilifex-job measure --wait 600 myrepo -- python bench.py # a timing, with the machine to itself
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Heavy jobs run beside each other. A measurement waits until no heavy job started through
|
|
106
|
+
`utilifex-job` with the same state directory is running, and new heavy work started that way
|
|
107
|
+
queues behind it; a process started any other way is not seen. The memory a job declares is a hard limit on Linux, where a systemd user scope
|
|
108
|
+
enforces it and stops every process the job started. macOS offers no memory limit for a process
|
|
109
|
+
tree, so there the tool says the limit is not enforced.
|
|
110
|
+
|
|
111
|
+
Every job leaves one line in `jobs.jsonl` in the tool's state directory: what it declared, how it
|
|
112
|
+
ended, and the most memory it held. On Linux that peak is the kernel's figure for the whole job.
|
|
113
|
+
On macOS it is the largest sum that sampling saw over the job's processes, a lower bound, and is
|
|
114
|
+
marked `sampled`. The state directory is `$UTILIFEX_JOB_STATE_DIR` when that is set, otherwise
|
|
115
|
+
`$XDG_STATE_HOME/utilifex/job`, with `~/.local/state` standing in for an unset `XDG_STATE_HOME`.
|
|
116
|
+
|
|
117
|
+
A job states its memory the first time. After that `--memory` can be left out, and the job is
|
|
118
|
+
given 1.15 times the largest peak its label has on record, or 1.2 times a limit it met. The
|
|
119
|
+
Kubernetes Vertical Pod Autoscaler's recommender uses the same figures by default: a
|
|
120
|
+
`recommendation-margin-fraction` of 0.15 ("Fraction of usage added as the safety margin to the
|
|
121
|
+
recommended request") and an `oom-bump-up-ratio` of 1.2 ("Default memory bump up ratio when OOM
|
|
122
|
+
occurs"), per its [flags reference](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/docs/flags.md).
|
|
123
|
+
A peak recorded at its limit counts as a limit met, since the job would have used more.
|
|
124
|
+
|
|
125
|
+
A heavy job starts only when its memory fits beside the jobs already running: its request, plus
|
|
126
|
+
what each running job may still grow into, plus a reserve, must be no more than the memory the
|
|
127
|
+
system reports as available. Otherwise it waits, says what it is waiting for, and is tried again
|
|
128
|
+
as memory moves. Jobs are admitted in the order they arrived. The reserve is a tenth of the
|
|
129
|
+
machine's memory, the minimum `earlyoom` keeps available by default ("set available memory
|
|
130
|
+
minimum to PERCENT of total (default 10 %)", [earlyoom's README](https://github.com/rfjakob/earlyoom));
|
|
131
|
+
`UTILIFEX_JOB_RESERVE=8G` states another. A job that could never fit is refused.
|
|
132
|
+
|
|
133
|
+
The tool exits with the job's status. It reserves 75 for a measurement that could not get the
|
|
134
|
+
machine, 125 for a failure of the tool itself, 137 for a job killed at its limit, and 130 for an
|
|
135
|
+
interruption before a job started.
|
|
136
|
+
|
|
137
|
+
### What every script shares
|
|
138
|
+
|
|
139
|
+
The conventions live in [`lib/bash/`](https://github.com/avitai/utilifex/tree/main/lib/bash) and [`src/utilifex/`](https://github.com/avitai/utilifex/tree/main/src/utilifex), and `bin/new-script` generates a script that already follows them.
|
|
140
|
+
|
|
141
|
+
- `-h` or `--help`, `--version`, `-n` or `--dry-run`, `--log-level=DEBUG|INFO|WARN|ERROR`.
|
|
142
|
+
- `--json-report=PATH` writes a report with the fields `schema_version`, `name`, `category`, `version`, `started_at`, `ended_at`, `duration_seconds`, `exit_code`, `status`, `host`, `os`, `user`, `log_file`, `params`, `counts`, `errors` and `warnings`. Shell and Python scripts write the same fields, and a test checks that they do.
|
|
143
|
+
- Shell scripts start with `#!/usr/bin/env bash` and `set -Eeuo pipefail`, and clean up on interrupt.
|
|
144
|
+
- Settings come from `UTILIFEX_*` environment variables, for example `UTILIFEX_LOG_LEVEL`.
|
|
145
|
+
|
|
146
|
+
## How it is tested
|
|
147
|
+
|
|
148
|
+
- Every pull request runs the `bats` tests on Ubuntu and the shared shell library's `bats` tests on Alpine and Debian. The Python tests run under `pytest` on Python 3.11, 3.12, 3.13, 3.14 and 3.15, with a coverage floor of 80% over `src/utilifex/` and the Python scripts under `scripts/` together. A nightly run repeats the tests on macOS when `main` has moved.
|
|
149
|
+
- A test installs every script and runs each installed command from a shell whose environment holds only `PATH` and `HOME`.
|
|
150
|
+
- Each script has its own tests under [`tests/scripts/`](https://github.com/avitai/utilifex/tree/main/tests/scripts). `make test` and continuous integration run all of them. Run `make setup-check` first: it reports what a development machine lacks and how to install it. A test never skips for want of a tool; a test run that lacks one stops before its first test, naming each one missing and the command that installs it.
|
|
151
|
+
- Commit hooks run `shellcheck`, `shfmt`, `ruff`, `pyright` in strict mode, `bandit`, `gitleaks`, `detect-secrets`, docstring coverage, Markdown and YAML linting, and a Conventional Commits check on the commit message.
|
|
152
|
+
|
|
153
|
+
## Contributing
|
|
154
|
+
|
|
155
|
+
See the [contributor guide](https://github.com/avitai/utilifex/blob/main/docs/development/contributing.md). How dependencies are updated, and what stays stable between versions before 1.0, is in the [maintainers' runbook](https://github.com/avitai/utilifex/blob/main/docs/maintainers.md).
|
|
156
|
+
|
|
157
|
+
## Security
|
|
158
|
+
|
|
159
|
+
Report a vulnerability as described in [`SECURITY.md`](https://github.com/avitai/utilifex/blob/main/SECURITY.md). The [threat model](https://github.com/avitai/utilifex/blob/main/docs/threat-model.md) says what the scripts assume and what they enforce.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
[MIT License](https://github.com/avitai/utilifex/blob/main/LICENSE).
|
utilifex-0.1.0/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|