tunectl 1.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tunectl contributors
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.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # tunectl
2
+
3
+ **Battle-tested VPS performance tuning toolkit for Ubuntu 24.04 LTS.**
4
+
5
+ Extracted from production server tuning missions — 86 tuning parameters, 3 risk tiers, automatic rollback. Battle-tested on DigitalOcean droplets (4 vCPU / 8 GB). Supports servers with 1–8 GB RAM with automatic parameter scaling.
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ | Requirement | Details |
12
+ |-------------|---------|
13
+ | **OS** | Ubuntu 24.04 LTS |
14
+ | **Python** | Python 3.x (Ubuntu 24.04 ships 3.12) |
15
+ | **Shell** | bash |
16
+ | **Node.js / npm** | Optional — only needed for `npx tunectl` usage |
17
+ | **jq** | Required by the bash scripts for JSON parsing |
18
+ | **Root access** | Required for `apply` and `rollback` commands only |
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ### Option A: Clone and run directly
25
+
26
+ ```bash
27
+ git clone https://github.com/symulacr/tunectl.git
28
+ cd tunectl
29
+ python3 -m tunectl --help
30
+ ```
31
+
32
+ ### Option B: Install with pip
33
+
34
+ ```bash
35
+ git clone https://github.com/symulacr/tunectl.git
36
+ cd tunectl
37
+ pip install .
38
+ tunectl --help
39
+ ```
40
+
41
+ ### Option C: Run via npx (requires Node.js + npm)
42
+
43
+ ```bash
44
+ # Run directly without cloning
45
+ npx tunectl --help
46
+
47
+ # Run any subcommand via npx
48
+ npx tunectl discover
49
+ npx tunectl plan --tier balanced
50
+ sudo npx tunectl apply --tier conservative
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Quick Start
56
+
57
+ tunectl follows a **discover → plan → apply → audit → benchmark** workflow:
58
+
59
+ ```bash
60
+ # 1. Discover — detect your system environment
61
+ tunectl discover
62
+
63
+ # 2. Plan — preview tuning changes (dry-run, no modifications)
64
+ tunectl plan --tier balanced
65
+
66
+ # 3. Apply — apply the tuning (creates automatic backup first)
67
+ sudo tunectl apply --tier balanced
68
+
69
+ # 4. Audit — verify all parameters were applied correctly
70
+ tunectl audit
71
+
72
+ # 5. Benchmark — measure performance improvements
73
+ tunectl benchmark
74
+ ```
75
+
76
+ For a before/after performance comparison, capture a baseline before applying:
77
+
78
+ ```bash
79
+ tunectl benchmark --baseline # Capture baseline metrics
80
+ sudo tunectl apply --tier balanced # Apply tuning
81
+ tunectl benchmark --compare # Compare against baseline
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Usage
87
+
88
+ ### `tunectl discover`
89
+
90
+ Detect the system environment and output a JSON profile. Strictly read-only — no system modifications.
91
+
92
+ ```bash
93
+ tunectl discover
94
+ ```
95
+
96
+ Example output:
97
+
98
+ ```json
99
+ {
100
+ "os_version": "Ubuntu 24.04 LTS",
101
+ "kernel_version": "6.8.0-101-generic",
102
+ "ram_mb": 8192,
103
+ "cpu_count": 4,
104
+ "disk_type": "virtio",
105
+ "swap_configured": true,
106
+ "swap_type": "zram",
107
+ "swap_total_mb": 4096
108
+ }
109
+ ```
110
+
111
+ ### `tunectl plan --tier <tier>`
112
+
113
+ Show a dry-run tuning plan for the selected tier. Displays all parameters that would be changed, their current values, and target values. No system files are modified.
114
+
115
+ ```bash
116
+ # Preview conservative tier (51 entries, zero risk)
117
+ tunectl plan --tier conservative
118
+
119
+ # Preview balanced tier (80 entries, very low risk)
120
+ tunectl plan --tier balanced
121
+
122
+ # Preview aggressive tier (all 86 entries)
123
+ tunectl plan --tier aggressive
124
+ ```
125
+
126
+ ### `tunectl apply --tier <tier>`
127
+
128
+ Apply tuning changes for the selected tier. Automatically creates a timestamped backup before making any modifications. Requires root.
129
+
130
+ ```bash
131
+ # Apply conservative tier (safest — zero breakage risk)
132
+ sudo tunectl apply --tier conservative
133
+
134
+ # Apply balanced tier (recommended for most servers)
135
+ sudo tunectl apply --tier balanced
136
+
137
+ # Apply aggressive tier (maximum performance)
138
+ sudo tunectl apply --tier aggressive
139
+ ```
140
+
141
+ ### `tunectl rollback`
142
+
143
+ Restore system configuration from a backup created by `tunectl apply`. By default, restores from the most recent backup. Requires root for restore operations.
144
+
145
+ ```bash
146
+ # List available backups (no root needed)
147
+ tunectl rollback --list
148
+
149
+ # Rollback to the most recent backup
150
+ sudo tunectl rollback
151
+
152
+ # Rollback to a specific backup
153
+ sudo tunectl rollback --backup 2025-01-15T14-30-00
154
+ ```
155
+
156
+ ### `tunectl audit`
157
+
158
+ Verify all 86 manifest tuning entries against the live system state. Reports PASS, FAIL, or SKIP for each entry. Strictly read-only.
159
+
160
+ ```bash
161
+ tunectl audit
162
+ ```
163
+
164
+ Example output:
165
+
166
+ ```
167
+ [SWAP-001] PASS vm.swappiness expected=180 actual=180
168
+ [MEM-001] FAIL vm.dirty_ratio expected=40 actual=20
169
+ ...
170
+ 51/86 checks passed
171
+ ```
172
+
173
+ ### `tunectl benchmark`
174
+
175
+ Run CPU, memory, and disk I/O performance benchmarks using sysbench and fio. Supports baseline capture and before/after comparison.
176
+
177
+ ```bash
178
+ # Run benchmarks and display current results
179
+ tunectl benchmark
180
+
181
+ # Capture a baseline before tuning
182
+ tunectl benchmark --baseline
183
+
184
+ # After tuning, compare against the baseline
185
+ tunectl benchmark --compare
186
+ ```
187
+
188
+ Example comparison output:
189
+
190
+ ```
191
+ Metric Baseline Current Change %Change
192
+ cpu_single_thread 1234 eps 1356 eps +122 +9.9%
193
+ memory_write 5678 MiB/s 6012 MiB/s +334 +5.9%
194
+ disk_randread_iops 12000 14500 +2500 +20.8%
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Risk Tiers
200
+
201
+ tunectl organizes 86 tuning parameters into three risk tiers. Each higher tier includes all parameters from the tiers below it.
202
+
203
+ | Tier | Included Risk Levels | Entry Count | Description |
204
+ |------|---------------------|-------------|-------------|
205
+ | **conservative** | `none` | 51 | Zero breakage risk. Sysctl memory/dirty tuning, inotify limits, I/O scheduler, readahead, noatime. No reboot required. |
206
+ | **balanced** | `none` + `low` | 80 | Very low risk, well-tested. Adds zram swap, BBR networking, socket buffers, THP, KSM, jemalloc, service tuning, tmpfs /tmp. Some items may need reboot. |
207
+ | **aggressive** | `none` + `low` + `med` | 86 | Low-to-medium risk. Adds preempt=none scheduling, cgroup isolation, memory overcommit, balanced CPU mitigations. Reboot required. |
208
+
209
+ ---
210
+
211
+ ## Rollback
212
+
213
+ ### Automatic Backups
214
+
215
+ Every time you run `tunectl apply`, a timestamped backup is automatically created **before** any changes are written. This ensures you can always restore your previous configuration.
216
+
217
+ ### Backup Location
218
+
219
+ Backups are stored at:
220
+
221
+ ```
222
+ /var/lib/tunectl/backups/YYYY-MM-DDTHH-MM-SS/
223
+ ```
224
+
225
+ Each backup directory contains copies of every config file that was modified during that apply operation.
226
+
227
+ ### How to Rollback
228
+
229
+ ```bash
230
+ # List all available backups (newest first)
231
+ tunectl rollback --list
232
+
233
+ # Restore from the most recent backup
234
+ sudo tunectl rollback
235
+
236
+ # Restore from a specific backup by timestamp
237
+ sudo tunectl rollback --backup 2025-01-15T14-30-00
238
+ ```
239
+
240
+ After rollback, sysctl values are automatically reloaded into the running kernel. The backup directory is preserved after restore (not deleted), so you can rollback to the same snapshot multiple times.
241
+
242
+ ---
243
+
244
+ ## Architecture
245
+
246
+ ```
247
+ tunectl/
248
+ ├── tune-manifest.json ← Single source of truth: 86 tuning parameters
249
+ ├── scripts/
250
+ │ ├── discover.sh ← System environment detection (JSON output)
251
+ │ ├── tune.sh ← Tuning engine (dry-run / apply with backup)
252
+ │ ├── rollback.sh ← Restore config from timestamped backups
253
+ │ ├── audit.sh ← Verify tuning against live system state
254
+ │ └── benchmark.sh ← Performance benchmarks (sysbench + fio)
255
+ ├── tunectl/
256
+ │ ├── __init__.py ← Package version
257
+ │ ├── __main__.py ← python3 -m tunectl support
258
+ │ └── cli.py ← Python CLI (argparse, delegates to scripts)
259
+ ├── bin/
260
+ │ └── tunectl ← npm/npx shim (bash → python3 -m tunectl)
261
+ ├── package.json ← npm package definition
262
+ ├── setup.py ← pip install support
263
+ └── tests/ ← Test suite
264
+ ```
265
+
266
+ **Data flow:** `tune-manifest.json` → bash scripts → Python CLI → npm shim
267
+
268
+ - **tune-manifest.json** is the single source of truth for all 86 tuning parameters. Every script reads from this file — no hardcoded tuning values anywhere.
269
+ - **Bash scripts** contain the core logic: discovery, planning, applying, rollback, auditing, and benchmarking.
270
+ - **Python CLI** (`tunectl/cli.py`) provides the user-facing `tunectl` command with 6 subcommands, each delegating to the corresponding bash script.
271
+ - **npm shim** (`bin/tunectl`) enables `npx tunectl` by checking for python3 and forwarding to `python3 -m tunectl`.
272
+
273
+ ---
274
+
275
+ ## RAM Auto-Scaling
276
+
277
+ tunectl supports servers with **1–8 GB RAM**. Parameters with RAM-dependent values are automatically scaled proportionally based on detected system memory. The manifest reference values are calibrated for 8 GB:
278
+
279
+ ```
280
+ scaled_value = reference_value × (detected_ram_gb / 8)
281
+ ```
282
+
283
+ Values are rounded to sensible boundaries (powers of 2 for memory sizes, integers for counts). Parameters without a scaling note use their manifest value directly. No manual configuration needed — tunectl detects your RAM and adjusts automatically.
284
+
285
+ ---
286
+
287
+ ## Exit Codes
288
+
289
+ All commands use consistent exit codes:
290
+
291
+ | Code | Meaning |
292
+ |------|---------|
293
+ | 0 | Success |
294
+ | 1 | Operational failure |
295
+ | 2 | Usage error |
296
+
297
+ For `audit`: exit code 0 means all checks passed; exit code 1 means one or more checks failed.
298
+
299
+ ---
300
+
301
+ ## License
302
+
303
+ MIT
package/bin/tunectl ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env bash
2
+ # tunectl — npm/npx shim that delegates to the Python CLI.
3
+ #
4
+ # This script is the bin entry point for the npm package. It checks
5
+ # that python3 is available, then invokes `python3 -m tunectl` with
6
+ # all arguments forwarded unchanged.
7
+
8
+ set -euo pipefail
9
+
10
+ # Resolve the package root (one level up from bin/).
11
+ # Follow symlinks so npm link / npx scenarios resolve correctly.
12
+ SOURCE="${BASH_SOURCE[0]}"
13
+ while [[ -L "$SOURCE" ]]; do
14
+ DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
15
+ SOURCE="$(readlink "$SOURCE")"
16
+ # Handle relative symlinks
17
+ [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
18
+ done
19
+ PACKAGE_ROOT="$(cd "$(dirname "$SOURCE")/.." && pwd)"
20
+
21
+ # Check that python3 is available
22
+ if ! command -v python3 &>/dev/null; then
23
+ echo "Error: python3 is required but was not found on PATH." >&2
24
+ echo "" >&2
25
+ echo "Install Python 3 for your platform:" >&2
26
+ echo " Ubuntu/Debian: sudo apt install python3" >&2
27
+ echo " macOS: brew install python3" >&2
28
+ echo " Fedora/RHEL: sudo dnf install python3" >&2
29
+ echo " Arch Linux: sudo pacman -S python" >&2
30
+ echo "" >&2
31
+ echo "Then re-run: npx tunectl $*" >&2
32
+ exit 1
33
+ fi
34
+
35
+ # Ensure the tunectl Python package is importable by adding the
36
+ # package root to PYTHONPATH (needed for npm link / npx scenarios
37
+ # where the package is not pip-installed).
38
+ export PYTHONPATH="${PACKAGE_ROOT}${PYTHONPATH:+:$PYTHONPATH}"
39
+
40
+ # Delegate to the Python CLI, running from the package root so that
41
+ # scripts/ and tune-manifest.json are located correctly.
42
+ cd "$PACKAGE_ROOT"
43
+ exec python3 -m tunectl "$@"
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "tunectl",
3
+ "version": "1.0.0",
4
+ "description": "Battle-tested VPS performance tuning toolkit for Ubuntu 24.04 LTS",
5
+ "bin": {
6
+ "tunectl": "./bin/tunectl"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "scripts/",
11
+ "tunectl/",
12
+ "tune-manifest.json",
13
+ "setup.py"
14
+ ],
15
+ "keywords": [
16
+ "vps",
17
+ "performance",
18
+ "tuning",
19
+ "sysctl",
20
+ "linux",
21
+ "ubuntu"
22
+ ],
23
+ "license": "MIT",
24
+ "author": "tunectl contributors",
25
+ "homepage": "https://github.com/symulacr/tunectl",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/symulacr/tunectl.git"
29
+ },
30
+ "engines": {
31
+ "node": ">=14"
32
+ }
33
+ }