@partoska/dpal 0.0.0-stage → 1.3.1
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/README.md +160 -2
- package/bin/dpal.js +105 -0
- package/package.json +39 -4
package/README.md
CHANGED
|
@@ -1,3 +1,161 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @partoska/dpal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Daemon Pal — a compact user-space tool for process management. Supervise,
|
|
4
|
+
restart, and persist long-running processes from your terminal.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@partoska/dpal)
|
|
7
|
+
[](https://github.com/partoska/dpal/blob/main/LICENSE.txt)
|
|
8
|
+
|
|
9
|
+
## What is this?
|
|
10
|
+
|
|
11
|
+
`dpal` runs in two modes:
|
|
12
|
+
|
|
13
|
+
- **Control process** (`dpal -C`) — a small daemon that owns and supervises
|
|
14
|
+
your processes, restarting them as configured.
|
|
15
|
+
- **Command executor** (default) — a short-lived client that tells a running
|
|
16
|
+
control process what to do: add, start, stop, restart, list, delete,
|
|
17
|
+
import/export, or persist processes.
|
|
18
|
+
|
|
19
|
+
**Key features:**
|
|
20
|
+
|
|
21
|
+
- Process lifecycle management with automatic startup and restarts.
|
|
22
|
+
- Process persistence across control process restarts.
|
|
23
|
+
- Individual and batch (`-a`) process control.
|
|
24
|
+
- Import/export of process lists via INI files.
|
|
25
|
+
- Per-process memory limits, log rotation, and restart intervals.
|
|
26
|
+
- Isolated working directories, so multiple control processes can coexist.
|
|
27
|
+
- Works on macOS and Linux, including Raspberry Pi (arm64 and armhf).
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -g @partoska/dpal
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This installs a small launcher plus the prebuilt native binary for your
|
|
36
|
+
platform, selected automatically. No compiler or build tools are required — see
|
|
37
|
+
[How this package works](#how-this-package-works) for the details.
|
|
38
|
+
|
|
39
|
+
### Supported platforms
|
|
40
|
+
|
|
41
|
+
| OS | Architectures |
|
|
42
|
+
| ----- | --------------------------------------------- |
|
|
43
|
+
| macOS | Intel & Apple Silicon |
|
|
44
|
+
| Linux | x64, arm64, armhf (ARMv6+, e.g. Raspberry Pi) |
|
|
45
|
+
|
|
46
|
+
Windows is not supported (dpal relies on POSIX process control and SysV IPC).
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
dpal -C -a & # Start the control process.
|
|
52
|
+
dpal -c /usr/bin/python3 -m http.server # Add a process.
|
|
53
|
+
dpal -l -a # List all processes.
|
|
54
|
+
dpal -s python3 # Start it by name.
|
|
55
|
+
dpal -p # Persist the list for next time.
|
|
56
|
+
dpal -k # Shut the control process down.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Run `dpal -h` at any time for full usage.
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Control process mode
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
dpal -C [-D workdir] [-f] [-i procs.ini] [-a]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Flag | Long | Meaning |
|
|
70
|
+
| ---- | -------------- | ------------------------------------------------------ |
|
|
71
|
+
| `-C` | `--control` | Start the control process. |
|
|
72
|
+
| `-D` | `--dir` | Working directory for this control process. |
|
|
73
|
+
| `-f` | `--force` | Start even if another one holds the workdir (recovery).|
|
|
74
|
+
| `-i` | `--ini` | Load a process list from an INI file at startup. |
|
|
75
|
+
| `-a` | `--auto-start` | Automatically start every process in the list. |
|
|
76
|
+
|
|
77
|
+
### Command executor mode
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
dpal [-D workdir] [-f] COMMAND [NAME|ID ...|-a]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
| Flag | Long | Meaning |
|
|
84
|
+
| ---- | ----------- | ---------------------------------------------------- |
|
|
85
|
+
| `-l` | `--list` | List processes. |
|
|
86
|
+
| `-s` | `--start` | Start process(es). |
|
|
87
|
+
| `-t` | `--stop` | Stop process(es) (SIGTERM). |
|
|
88
|
+
| `-r` | `--restart` | Stop and start process(es). |
|
|
89
|
+
| `-c` | `--create` | Add a process from `EXEC [args...]`. |
|
|
90
|
+
| `-d` | `--delete` | Remove process(es) from the list. |
|
|
91
|
+
| `-i` | `--import` | Import a process list from an INI file. |
|
|
92
|
+
| `-e` | `--export` | Export the process list to an INI file. |
|
|
93
|
+
| `-p` | `--persist` | Save the current list so it reloads on next start. |
|
|
94
|
+
| `-k` | `--kill` | Shut down the control process and all its processes. |
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
The working directory is resolved in this order: `-D/--dir`, `$DPAL_HOME`,
|
|
99
|
+
`$HOME/.dpal`, then the current directory. Use the same `-D` for the control
|
|
100
|
+
process and every command aimed at it.
|
|
101
|
+
|
|
102
|
+
Process lists use a simple INI format:
|
|
103
|
+
|
|
104
|
+
```ini
|
|
105
|
+
[web]
|
|
106
|
+
App=/usr/bin/python3
|
|
107
|
+
Dir=/srv/www
|
|
108
|
+
Arg=python3
|
|
109
|
+
Arg=-m
|
|
110
|
+
Arg=http.server
|
|
111
|
+
; Restart 5 seconds after the process exits.
|
|
112
|
+
RestartSec=5
|
|
113
|
+
; Rotate logs at 1 MiB, keeping 3 rotated files.
|
|
114
|
+
LogMaxSize=1048576
|
|
115
|
+
LogRotation=3
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## How this package works
|
|
119
|
+
|
|
120
|
+
`@partoska/dpal` follows the per-platform `optionalDependencies` model. The
|
|
121
|
+
package you install ships only a tiny Node launcher; the actual native binary
|
|
122
|
+
comes from one of these platform packages, and npm installs only the one
|
|
123
|
+
matching your OS and CPU:
|
|
124
|
+
|
|
125
|
+
- `@partoska/dpal-darwin` — macOS universal (Intel + Apple Silicon)
|
|
126
|
+
- `@partoska/dpal-linux-x64`
|
|
127
|
+
- `@partoska/dpal-linux-arm64`
|
|
128
|
+
- `@partoska/dpal-linux-arm` — armhf (ARMv6+), e.g. 32-bit Raspberry Pi OS
|
|
129
|
+
|
|
130
|
+
When you run `dpal`, the launcher resolves the matching binary and, on Node
|
|
131
|
+
22.15 or newer, replaces itself with it (`execve`), so the control process
|
|
132
|
+
owns its PID and receives signals directly. On older Node versions it runs
|
|
133
|
+
the binary as a child, forwarding signals and the exit status.
|
|
134
|
+
|
|
135
|
+
## Troubleshooting
|
|
136
|
+
|
|
137
|
+
### "Unsupported platform" or "could not find the native binary"
|
|
138
|
+
|
|
139
|
+
This usually means optional dependencies were skipped during install (for
|
|
140
|
+
example with `npm install --omit=optional`, or behind a strict CI mirror).
|
|
141
|
+
Reinstall with optional dependencies enabled:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npm install -g @partoska/dpal
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### "No control process is running"
|
|
148
|
+
|
|
149
|
+
Executor commands talk to the control process bound to the working directory.
|
|
150
|
+
Make sure one is running (`dpal -C &`) and that both use the same `-D` or
|
|
151
|
+
`$DPAL_HOME`.
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT. Copyright (C) 2024 Fabrika Charvat s.r.o. Developed by the
|
|
156
|
+
[Partoska Laboratory](https://lab.partoska.com) team.
|
|
157
|
+
|
|
158
|
+
## Links
|
|
159
|
+
|
|
160
|
+
- **Project website:** <https://lab.partoska.com/dpal>
|
|
161
|
+
- **Source & issues:** <https://github.com/partoska/dpal>
|
package/bin/dpal.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Daemon Pal - Compact user-space tool/library for process management.
|
|
5
|
+
* Copyright (C) 2024 Fabrika Charvat s.r.o. All rights reserved.
|
|
6
|
+
* Developed by Partoska Laboratory team, <https://lab.partoska.com>
|
|
7
|
+
*
|
|
8
|
+
* MIT License
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to
|
|
12
|
+
* deal in the Software without restriction, including without limitation the
|
|
13
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
14
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in
|
|
18
|
+
* all copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
25
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
26
|
+
* IN THE SOFTWARE.
|
|
27
|
+
*
|
|
28
|
+
* You can contact the author(s) via email at ask <at> partoska.com.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
"use strict";
|
|
32
|
+
|
|
33
|
+
const { spawn } = require("child_process");
|
|
34
|
+
|
|
35
|
+
// Map `${process.platform}-${process.arch}` to the package + relative binary.
|
|
36
|
+
const TARGETS = {
|
|
37
|
+
"darwin-x64": ["@partoska/dpal-darwin", "bin/dpal"],
|
|
38
|
+
"darwin-arm64": ["@partoska/dpal-darwin", "bin/dpal"],
|
|
39
|
+
"linux-x64": ["@partoska/dpal-linux-x64", "bin/dpal"],
|
|
40
|
+
"linux-arm64": ["@partoska/dpal-linux-arm64", "bin/dpal"],
|
|
41
|
+
"linux-arm": ["@partoska/dpal-linux-arm", "bin/dpal"],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const key = `${process.platform}-${process.arch}`;
|
|
45
|
+
const target = TARGETS[key];
|
|
46
|
+
if (!target) {
|
|
47
|
+
console.error(
|
|
48
|
+
`dpal: unsupported platform/architecture "${key}".\n` +
|
|
49
|
+
`Supported: ${Object.keys(TARGETS).join(", ")}.`,
|
|
50
|
+
);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const [pkg, relPath] = target;
|
|
55
|
+
let binary;
|
|
56
|
+
try {
|
|
57
|
+
binary = require.resolve(`${pkg}/${relPath}`);
|
|
58
|
+
} catch {
|
|
59
|
+
console.error(
|
|
60
|
+
`dpal: could not find the native binary for "${key}".\n` +
|
|
61
|
+
`The optional dependency "${pkg}" does not seem to be installed.\n` +
|
|
62
|
+
`Try reinstalling dpal (e.g. "npm install -g @partoska/dpal"), and make\n` +
|
|
63
|
+
`sure optional dependencies are not disabled.`,
|
|
64
|
+
);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const args = process.argv.slice(2);
|
|
69
|
+
|
|
70
|
+
// Prefer replacing this Node process with the native binary (Node >= 22.15).
|
|
71
|
+
// The control process (`dpal -C`) is long-lived, so it should own the PID and
|
|
72
|
+
// receive signals directly rather than sit behind a Node wrapper.
|
|
73
|
+
if (typeof process.execve === "function") {
|
|
74
|
+
try {
|
|
75
|
+
process.execve(binary, [binary, ...args], process.env);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
// Fall through to the spawn-based launcher below.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const child = spawn(binary, args, { stdio: "inherit" });
|
|
82
|
+
|
|
83
|
+
// Forward termination signals so the wrapper behaves like the binary itself.
|
|
84
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGUSR1", "SIGUSR2"]) {
|
|
85
|
+
process.on(sig, () => {
|
|
86
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
87
|
+
child.kill(sig);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
child.on("error", (err) => {
|
|
93
|
+
console.error(`dpal: failed to launch native binary: ${err.message}`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Mirror the child's exit.
|
|
98
|
+
child.on("exit", (code, signal) => {
|
|
99
|
+
if (signal) {
|
|
100
|
+
process.removeAllListeners(signal);
|
|
101
|
+
process.kill(process.pid, signal);
|
|
102
|
+
} else {
|
|
103
|
+
process.exit(code === null ? 1 : code);
|
|
104
|
+
}
|
|
105
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@partoska/dpal",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Compact user-space tool for process management — supervise, restart, and persist long-running processes.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"dpal": "bin/dpal.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"@partoska/dpal-darwin": "1.3.1",
|
|
14
|
+
"@partoska/dpal-linux-x64": "1.3.1",
|
|
15
|
+
"@partoska/dpal-linux-arm64": "1.3.1",
|
|
16
|
+
"@partoska/dpal-linux-arm": "1.3.1"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/partoska/dpal.git"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://lab.partoska.com/dpal",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/partoska/dpal/issues"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"process",
|
|
35
|
+
"supervisor",
|
|
36
|
+
"daemon",
|
|
37
|
+
"process-manager",
|
|
38
|
+
"cli",
|
|
39
|
+
"raspberry-pi"
|
|
40
|
+
]
|
|
41
|
+
}
|