@kaynooo/cli-proc 0.3.0 → 0.5.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/dist/pid-cli.js +357 -57
- package/dist/ports-cli.js +444 -77
- package/dist/proc-cli.js +465 -93
- package/dist/procs-cli.js +374 -69
- package/package.json +2 -2
- package/src/ports.ts +8 -2
- package/src/procs.ts +11 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-proc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "pid, ports, procs: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"procs": "$npm_execpath src/procs-cli.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
38
|
+
"@kaynooo/cli-kit": "0.28.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/ports.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Container, Protocol, Socket } from './parse'
|
|
|
2
2
|
import type { ProcInfo } from './read'
|
|
3
3
|
import { basename } from 'node:path'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
-
import { badUsage, duration, fail, jsonOption, paint, parse, printJson, table, truncate, wholeNumber } from '@kaynooo/cli-kit'
|
|
5
|
+
import { badUsage, duration, fail, jsonOption, paint, parse, printHeader, printJson, table, truncate, watching, watchOption, wholeNumber, withoutWatch } from '@kaynooo/cli-kit'
|
|
6
6
|
import { confirm } from '@kaynooo/cli-kit/prompt'
|
|
7
7
|
import { dockerContainers } from './docker'
|
|
8
8
|
import { protectionOf, terminate } from './kill'
|
|
@@ -19,7 +19,8 @@ Exits 0 when it listed or stopped, 1 when nothing listens on the given port or t
|
|
|
19
19
|
|
|
20
20
|
const options = {
|
|
21
21
|
json: jsonOption('[{ port, protocol, addresses, pid, command, cwd, container }]'),
|
|
22
|
-
kill: { type: 'boolean', description: 'stop the owner of the given port' },
|
|
22
|
+
kill: { type: 'boolean', conflicts: ['watch'], description: 'stop the owner of the given port' },
|
|
23
|
+
watch: watchOption('the ports'),
|
|
23
24
|
force: { type: 'boolean', description: 'with --kill, SIGKILL what SIGTERM did not stop within --grace' },
|
|
24
25
|
yes: { type: 'boolean', short: 'y', description: 'with --kill, do not ask first' },
|
|
25
26
|
grace: { type: 'string', description: 'with --force, how long SIGTERM gets before SIGKILL (5s)' },
|
|
@@ -150,6 +151,10 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
150
151
|
'ports --json',
|
|
151
152
|
],
|
|
152
153
|
})
|
|
154
|
+
|
|
155
|
+
if (values.watch !== undefined)
|
|
156
|
+
return watching(values.watch, async () => ports(withoutWatch(args)))
|
|
157
|
+
|
|
153
158
|
const [given] = positionals
|
|
154
159
|
const port = given === undefined ? undefined : wholeNumber(given, '<port>', 0)
|
|
155
160
|
|
|
@@ -184,6 +189,7 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
184
189
|
return 0
|
|
185
190
|
}
|
|
186
191
|
|
|
192
|
+
printHeader('ports')
|
|
187
193
|
console.log(render(rows))
|
|
188
194
|
|
|
189
195
|
const unknown = rows.filter(row => row.pid === undefined && row.container === undefined).length
|
package/src/procs.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Group } from './select'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
-
import { duration, fail, formatFileSize, formatSeconds, jsonOption, paint, parse, parseSize, printJson, table, truncate } from '@kaynooo/cli-kit'
|
|
5
|
+
import { duration, fail, formatFileSize, formatSeconds, jsonOption, paint, parse, parseSize, printHeader, printJson, table, truncate, watching, watchOption, withoutWatch } from '@kaynooo/cli-kit'
|
|
6
6
|
import { terminate } from './kill'
|
|
7
7
|
import { maskArgs } from './mask'
|
|
8
8
|
import { ancestry, snapshot } from './read'
|
|
@@ -18,7 +18,8 @@ Exits 0 when it listed or stopped everything, 1 when a process survived SIGKILL,
|
|
|
18
18
|
|
|
19
19
|
const options = {
|
|
20
20
|
'json': jsonOption('{ groups: [{ origin, kind, count, rss, oldestSeconds, tools, orphans, pids, processes }], skipped }'),
|
|
21
|
-
'kill': { type: 'boolean', description: 'stop the listed processes: a dry run without --yes' },
|
|
21
|
+
'kill': { type: 'boolean', conflicts: ['watch'], description: 'stop the listed processes: a dry run without --yes' },
|
|
22
|
+
'watch': watchOption('the processes'),
|
|
22
23
|
'yes': { type: 'boolean', short: 'y', description: 'with --kill, really stop them, without asking' },
|
|
23
24
|
'min-mem': { type: 'string', description: 'heavy from this resident size (500M), and the least a left over process must use to be listed; a bare number counts megabytes' },
|
|
24
25
|
'older': { type: 'string', description: 'only processes at least this old: 30m, 2h, 1d' },
|
|
@@ -73,6 +74,9 @@ export async function procs(args: string[]): Promise<number> {
|
|
|
73
74
|
if (values['min-mem'] !== undefined && minMem === undefined)
|
|
74
75
|
fail(`--min-mem takes a size such as 500M or 1.5G, not ${values['min-mem']}`, 2)
|
|
75
76
|
|
|
77
|
+
if (values.watch !== undefined)
|
|
78
|
+
return watching(values.watch, async () => procs(withoutWatch(args)))
|
|
79
|
+
|
|
76
80
|
const olderMs = values.older === undefined ? undefined : duration(values.older, 'older', 0, 'm')
|
|
77
81
|
const uid = process.getuid?.() ?? -1
|
|
78
82
|
const all = await snapshot('/proc', owner => owner === uid)
|
|
@@ -81,10 +85,13 @@ export async function procs(args: string[]): Promise<number> {
|
|
|
81
85
|
const pids = groups.flatMap(group => group.members.map(({ proc }) => proc.pid))
|
|
82
86
|
|
|
83
87
|
const show = (extra: object = {}): void => {
|
|
84
|
-
if (values.json === true)
|
|
88
|
+
if (values.json === true) {
|
|
85
89
|
printJson({ groups: groups.map(summary), skipped: protectedCount, ...extra })
|
|
86
|
-
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
printHeader('procs')
|
|
87
93
|
console.log(groups.length === 0 ? 'nothing to clean' : render(groups))
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
if (values.kill !== true || pids.length === 0 || values.yes !== true) {
|