@platformatic/control 3.4.1 → 3.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/README.md +1 -1
- package/eslint.config.js +2 -2
- package/lib/errors.d.ts +21 -0
- package/lib/errors.js +99 -26
- package/lib/index.d.ts +130 -0
- package/lib/{runtime-api-client.js → index.js} +247 -71
- package/package.json +20 -20
- package/control.js +0 -83
- package/help/config.txt +0 -16
- package/help/env.txt +0 -16
- package/help/help.txt +0 -11
- package/help/inject.txt +0 -30
- package/help/logs.txt +0 -21
- package/help/ps.txt +0 -10
- package/help/reload.txt +0 -19
- package/help/restart.txt +0 -16
- package/help/services.txt +0 -16
- package/help/stop.txt +0 -16
- package/index.js +0 -7
- package/lib/config.js +0 -29
- package/lib/env.js +0 -29
- package/lib/inject.js +0 -102
- package/lib/logs.js +0 -67
- package/lib/ps.js +0 -96
- package/lib/reload.js +0 -25
- package/lib/restart.js +0 -32
- package/lib/services.js +0 -73
- package/lib/stop.js +0 -25
package/help/inject.txt
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
Injects a request to the platformatic runtime service.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl inject -n runtime-name /hello
|
|
5
|
-
-X POST
|
|
6
|
-
-H "Content-Type: application/json"
|
|
7
|
-
-d '{"key": "value"}'
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
Options:
|
|
11
|
-
|
|
12
|
-
* `-p, --pid <number>` - The process id of the runtime.
|
|
13
|
-
* `-n, --name <string>` - The name of the runtime.
|
|
14
|
-
* `-s, --service <string>` - The name of the runtime service.
|
|
15
|
-
* `-X, --request <string>` - The request HTTP method. Default is `GET`.
|
|
16
|
-
* `-H, --header <string>` - The request header. Can be used multiple times.
|
|
17
|
-
* `-d, --data <string>` - The request data.
|
|
18
|
-
* `-i, --include <boolean>` - Include the response headers in the output. Default is `false`.
|
|
19
|
-
* `-v, --verbose <boolean>` - Make the operation more talkative. Default is `false`.
|
|
20
|
-
* `-o, --output <file>` - Write the response to the specified file.
|
|
21
|
-
|
|
22
|
-
The `inject` command sends a request to the runtime service and prints the
|
|
23
|
-
response to the standard output. If the `--service` option is not specified the
|
|
24
|
-
request is sent to the runtime entrypoint.
|
|
25
|
-
|
|
26
|
-
The `inject` command uses the Platformatic Runtime Management API. To enable it
|
|
27
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
28
|
-
|
|
29
|
-
To get the list of runtimes with enabled management API use the
|
|
30
|
-
`platformatic ctl ps` command.
|
package/help/logs.txt
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Streams logs from the platformatic runtime application.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl logs -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime.
|
|
11
|
-
* `-l, --level <string>` - The pino log level to stream. Default is `info`.
|
|
12
|
-
* `-s, --service <string>` - The name of the service to stream logs from.
|
|
13
|
-
* `--pretty <boolean>` - Pretty print the logs. Default is `true`.
|
|
14
|
-
|
|
15
|
-
If `--service` is not specified, the command will stream logs from all services.
|
|
16
|
-
|
|
17
|
-
The `logs` command uses the Platformatic Runtime Management API. To enable it
|
|
18
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
19
|
-
|
|
20
|
-
To get the list of runtimes with enabled management API use the
|
|
21
|
-
`platformatic ctl ps` command.
|
package/help/ps.txt
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Lists all running platformatic runtime applications.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl ps
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
To see the list of all available control commands, run `platformatic ctl help`.
|
|
8
|
-
|
|
9
|
-
The `ps` command uses the Platformatic Runtime Management API. To enable it
|
|
10
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
package/help/reload.txt
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Reloads a platformatic runtime application.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl reload -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime to reload.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime to reload.
|
|
11
|
-
|
|
12
|
-
The difference between `reload` and `restart` is that `reload` does not kill
|
|
13
|
-
the runtime process. It stops and starts all the runtime services.
|
|
14
|
-
|
|
15
|
-
The `reload` command uses the Platformatic Runtime Management API. To enable it
|
|
16
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
17
|
-
|
|
18
|
-
To get the list of runtimes with enabled management API use the
|
|
19
|
-
`platformatic ctl ps` command.
|
package/help/restart.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Restarts a platformatic runtime application.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl restart -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime to restart.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime to restart.
|
|
11
|
-
|
|
12
|
-
The `restart` command uses the Platformatic Runtime Management API. To enable it
|
|
13
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
14
|
-
|
|
15
|
-
To get the list of runtimes with enabled management API use the
|
|
16
|
-
`platformatic ctl ps` command.
|
package/help/services.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Lists the platformatic runtime services.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl services -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime.
|
|
11
|
-
|
|
12
|
-
The `services` command uses the Platformatic Runtime Management API. To enable it
|
|
13
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
14
|
-
|
|
15
|
-
To get the list of runtimes with enabled management API use the
|
|
16
|
-
`platformatic ctl ps` command.
|
package/help/stop.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Stops a platformatic runtime application.
|
|
2
|
-
|
|
3
|
-
``` bash
|
|
4
|
-
$ platformatic ctl stop -n runtime-name
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
Options:
|
|
8
|
-
|
|
9
|
-
* `-p, --pid <number>` - The process id of the runtime to stop.
|
|
10
|
-
* `-n, --name <string>` - The name of the runtime to stop.
|
|
11
|
-
|
|
12
|
-
The `stop` command uses the Platformatic Runtime Management API. To enable it
|
|
13
|
-
set the `managementApi` option to `true` in the runtime configuration file.
|
|
14
|
-
|
|
15
|
-
To get the list of runtimes with enabled management API use the
|
|
16
|
-
`platformatic ctl ps` command.
|
package/index.js
DELETED
package/lib/config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
async function getRuntimeConfigCommand (argv) {
|
|
7
|
-
const args = parseArgs({
|
|
8
|
-
args: argv,
|
|
9
|
-
options: {
|
|
10
|
-
pid: { type: 'string', short: 'p' },
|
|
11
|
-
name: { type: 'string', short: 'n' },
|
|
12
|
-
service: { type: 'string', short: 's' },
|
|
13
|
-
},
|
|
14
|
-
strict: false,
|
|
15
|
-
}).values
|
|
16
|
-
|
|
17
|
-
const client = new RuntimeApiClient()
|
|
18
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
19
|
-
|
|
20
|
-
const config = args.service
|
|
21
|
-
? await client.getRuntimeServiceConfig(runtime.pid, args.service)
|
|
22
|
-
: await client.getRuntimeConfig(runtime.pid)
|
|
23
|
-
|
|
24
|
-
console.log(JSON.stringify(config, null, 2))
|
|
25
|
-
|
|
26
|
-
await client.close()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = getRuntimeConfigCommand
|
package/lib/env.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
async function getRuntimeEnvCommand (argv) {
|
|
7
|
-
const args = parseArgs({
|
|
8
|
-
args: argv,
|
|
9
|
-
options: {
|
|
10
|
-
pid: { type: 'string', short: 'p' },
|
|
11
|
-
name: { type: 'string', short: 'n' },
|
|
12
|
-
},
|
|
13
|
-
strict: false,
|
|
14
|
-
}).values
|
|
15
|
-
|
|
16
|
-
const client = new RuntimeApiClient()
|
|
17
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
18
|
-
|
|
19
|
-
const runtimeEnv = await client.getRuntimeEnv(runtime.pid)
|
|
20
|
-
let output = ''
|
|
21
|
-
for (const key in runtimeEnv) {
|
|
22
|
-
output += `${key}=${runtimeEnv[key]}\n`
|
|
23
|
-
}
|
|
24
|
-
console.log(output)
|
|
25
|
-
|
|
26
|
-
await client.close()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = getRuntimeEnvCommand
|
package/lib/inject.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const { writeFile } = require('node:fs/promises')
|
|
5
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
6
|
-
const errors = require('./errors')
|
|
7
|
-
|
|
8
|
-
async function injectRuntimeCommand (argv) {
|
|
9
|
-
const { values: args, positionals } = parseArgs({
|
|
10
|
-
args: argv,
|
|
11
|
-
options: {
|
|
12
|
-
pid: { type: 'string', short: 'p' },
|
|
13
|
-
name: { type: 'string', short: 'n' },
|
|
14
|
-
service: { type: 'string', short: 's' },
|
|
15
|
-
request: { type: 'string', short: 'X', default: 'GET' },
|
|
16
|
-
header: { type: 'string', short: 'H', multiple: true },
|
|
17
|
-
data: { type: 'string', short: 'd' },
|
|
18
|
-
include: { type: 'boolean', short: 'i', default: false },
|
|
19
|
-
verbose: { type: 'boolean', short: 'v', default: false },
|
|
20
|
-
output: { type: 'string', short: 'o' },
|
|
21
|
-
},
|
|
22
|
-
strict: false,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const client = new RuntimeApiClient()
|
|
26
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
27
|
-
|
|
28
|
-
let serviceId = args.service
|
|
29
|
-
if (!serviceId) {
|
|
30
|
-
const runtimeServices = await client.getRuntimeServices(runtime.pid)
|
|
31
|
-
serviceId = runtimeServices.entrypoint
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (positionals.length === 0) {
|
|
35
|
-
throw errors.MissingRequestURL()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let result = ''
|
|
39
|
-
|
|
40
|
-
const fullUrl = new URL(positionals[0], runtime.url)
|
|
41
|
-
const injectPath = fullUrl.href.slice(runtime.url.length)
|
|
42
|
-
|
|
43
|
-
const method = args.request
|
|
44
|
-
const body = args.data
|
|
45
|
-
|
|
46
|
-
if (args.verbose) {
|
|
47
|
-
result += `> ${method} ${injectPath} HTTP/1.1\n`
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const headers = {}
|
|
51
|
-
for (const header of args.header || []) {
|
|
52
|
-
const [name, value] = header.split(':')
|
|
53
|
-
headers[name] = value
|
|
54
|
-
|
|
55
|
-
if (args.verbose) {
|
|
56
|
-
result += `> ${name}: ${value}\n`
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (args.verbose && args.header.length > 0) {
|
|
61
|
-
result += '> \n'
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const injectOptions = { url: injectPath, method, headers, body }
|
|
65
|
-
|
|
66
|
-
const response = await client.injectRuntime(runtime.pid, serviceId, injectOptions)
|
|
67
|
-
|
|
68
|
-
if (args.verbose) {
|
|
69
|
-
result += `< HTTP/1.1 ${response.statusCode}\n`
|
|
70
|
-
}
|
|
71
|
-
if (args.include) {
|
|
72
|
-
result += `HTTP/1.1 ${response.statusCode}\n`
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (const header in response.headers) {
|
|
76
|
-
if (args.verbose) {
|
|
77
|
-
result += `< ${header}: ${response.headers[header]}\n`
|
|
78
|
-
}
|
|
79
|
-
if (args.include) {
|
|
80
|
-
result += `${header}: ${response.headers[header]}\n`
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (args.verbose) {
|
|
85
|
-
result += '< \n'
|
|
86
|
-
}
|
|
87
|
-
if (args.include) {
|
|
88
|
-
result += '\n'
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
result += await response.body.text()
|
|
92
|
-
|
|
93
|
-
if (args.output) {
|
|
94
|
-
await writeFile(args.output, result)
|
|
95
|
-
} else {
|
|
96
|
-
console.log(result)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
await client.close()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = injectRuntimeCommand
|
package/lib/logs.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const { prettyFactory } = require('pino-pretty')
|
|
5
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
6
|
-
|
|
7
|
-
const pinoLogLevels = {
|
|
8
|
-
fatal: 60,
|
|
9
|
-
error: 50,
|
|
10
|
-
warn: 40,
|
|
11
|
-
info: 30,
|
|
12
|
-
debug: 20,
|
|
13
|
-
trace: 10,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function streamRuntimeLogsCommand (argv) {
|
|
17
|
-
const args = parseArgs({
|
|
18
|
-
args: argv,
|
|
19
|
-
options: {
|
|
20
|
-
pid: { type: 'string', short: 'p' },
|
|
21
|
-
name: { type: 'string', short: 'n' },
|
|
22
|
-
level: { type: 'string', short: 'l', default: 'info' },
|
|
23
|
-
pretty: { type: 'string', default: 'true' },
|
|
24
|
-
service: { type: 'string', short: 's' },
|
|
25
|
-
},
|
|
26
|
-
strict: false,
|
|
27
|
-
}).values
|
|
28
|
-
|
|
29
|
-
const client = new RuntimeApiClient()
|
|
30
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
31
|
-
|
|
32
|
-
const logLevelNumber = pinoLogLevels[args.level]
|
|
33
|
-
const prettify = prettyFactory()
|
|
34
|
-
|
|
35
|
-
const logsStream = client.getRuntimeLiveLogsStream(runtime.pid)
|
|
36
|
-
|
|
37
|
-
logsStream.on('data', (data) => {
|
|
38
|
-
const logs = data.toString().split('\n').filter(Boolean)
|
|
39
|
-
|
|
40
|
-
for (let log of logs) {
|
|
41
|
-
try {
|
|
42
|
-
const parsedLog = JSON.parse(log)
|
|
43
|
-
if (parsedLog.level < logLevelNumber) continue
|
|
44
|
-
if (args.service && parsedLog.name !== args.service) continue
|
|
45
|
-
if (args.pretty !== 'false') {
|
|
46
|
-
log = prettify(parsedLog)
|
|
47
|
-
} else {
|
|
48
|
-
log += '\n'
|
|
49
|
-
}
|
|
50
|
-
process.stdout.write(log)
|
|
51
|
-
} catch (err) {
|
|
52
|
-
console.error('Failed to parse log message: ', log, err)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
process.on('SIGINT', () => {
|
|
58
|
-
logsStream.destroy()
|
|
59
|
-
process.exit(0)
|
|
60
|
-
})
|
|
61
|
-
process.on('SIGTERM', () => {
|
|
62
|
-
logsStream.destroy()
|
|
63
|
-
process.exit(0)
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = streamRuntimeLogsCommand
|
package/lib/ps.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { table, getBorderCharacters } = require('table')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
const tableColumns = [
|
|
7
|
-
{
|
|
8
|
-
value: 'pid',
|
|
9
|
-
alias: 'PID',
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
value: 'packageName',
|
|
13
|
-
alias: 'NAME',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
value: 'platformaticVersion',
|
|
17
|
-
alias: 'PLT',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
value: 'uptimeSeconds',
|
|
21
|
-
alias: 'TIME',
|
|
22
|
-
formatter: formatRuntimeTime,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
value: 'url',
|
|
26
|
-
alias: 'URL',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
value: 'projectDir',
|
|
30
|
-
alias: 'PWD',
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
function formatRuntimeTime (timeSeconds) {
|
|
35
|
-
let result = ''
|
|
36
|
-
if (timeSeconds < 3600) {
|
|
37
|
-
const seconds = Math.floor(timeSeconds % 60)
|
|
38
|
-
result = `${seconds}s`
|
|
39
|
-
}
|
|
40
|
-
if (timeSeconds >= 60) {
|
|
41
|
-
const minutes = Math.floor((timeSeconds % 3600) / 60)
|
|
42
|
-
result = `${minutes}m ` + result
|
|
43
|
-
}
|
|
44
|
-
if (timeSeconds >= 3600) {
|
|
45
|
-
const hours = Math.floor((timeSeconds % (3600 * 24)) / 3600)
|
|
46
|
-
result = `${hours}h ` + result
|
|
47
|
-
}
|
|
48
|
-
if (timeSeconds >= 3600 * 24) {
|
|
49
|
-
const days = Math.floor(timeSeconds / (3600 * 24))
|
|
50
|
-
result = `${days}d ` + result
|
|
51
|
-
}
|
|
52
|
-
return result
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const tableConfig = {
|
|
56
|
-
border: getBorderCharacters('void'),
|
|
57
|
-
columnDefault: {
|
|
58
|
-
paddingLeft: 0,
|
|
59
|
-
paddingRight: 1,
|
|
60
|
-
},
|
|
61
|
-
drawHorizontalLine: () => false,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function printRuntimes (runtimes) {
|
|
65
|
-
const raws = [tableColumns.map(column => column.alias)]
|
|
66
|
-
|
|
67
|
-
for (const runtime of runtimes) {
|
|
68
|
-
const raw = []
|
|
69
|
-
for (const column of tableColumns) {
|
|
70
|
-
let value = runtime[column.value]
|
|
71
|
-
if (column.formatter) {
|
|
72
|
-
value = column.formatter(value)
|
|
73
|
-
}
|
|
74
|
-
value ??= '-----'
|
|
75
|
-
raw.push(value)
|
|
76
|
-
}
|
|
77
|
-
raws.push(raw)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const runtimesTable = table(raws, tableConfig)
|
|
81
|
-
process.stdout.write(runtimesTable)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function listRuntimesCommand () {
|
|
85
|
-
const client = new RuntimeApiClient()
|
|
86
|
-
const runtimes = await client.getRuntimes()
|
|
87
|
-
if (runtimes.length === 0) {
|
|
88
|
-
console.log('No platformatic runtimes found.')
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
printRuntimes(runtimes)
|
|
92
|
-
|
|
93
|
-
await client.close()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
module.exports = listRuntimesCommand
|
package/lib/reload.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
async function reloadRuntimeCommand (argv) {
|
|
7
|
-
const args = parseArgs({
|
|
8
|
-
args: argv,
|
|
9
|
-
options: {
|
|
10
|
-
pid: { type: 'string', short: 'p' },
|
|
11
|
-
name: { type: 'string', short: 'n' }
|
|
12
|
-
},
|
|
13
|
-
strict: false
|
|
14
|
-
}).values
|
|
15
|
-
|
|
16
|
-
const client = new RuntimeApiClient()
|
|
17
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
18
|
-
|
|
19
|
-
const child = await client.reloadRuntime(runtime.pid)
|
|
20
|
-
console.log(`Reloaded runtime "${runtime.packageName}". The new PID is ${child.pid}.`)
|
|
21
|
-
|
|
22
|
-
await client.close()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = reloadRuntimeCommand
|
package/lib/restart.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
async function restartRuntimeCommand (argv) {
|
|
7
|
-
const args = parseArgs({
|
|
8
|
-
args: argv,
|
|
9
|
-
options: {
|
|
10
|
-
pid: { type: 'string', short: 'p' },
|
|
11
|
-
name: { type: 'string', short: 'n' },
|
|
12
|
-
},
|
|
13
|
-
strict: false,
|
|
14
|
-
}).values
|
|
15
|
-
|
|
16
|
-
const client = new RuntimeApiClient()
|
|
17
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
18
|
-
|
|
19
|
-
const runtimeProcess = await client.restartRuntime(runtime.pid, { stdio: 'inherit' })
|
|
20
|
-
|
|
21
|
-
process.on('SIGINT', () => {
|
|
22
|
-
runtimeProcess.kill('SIGINT')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
process.on('SIGTERM', () => {
|
|
26
|
-
runtimeProcess.kill('SIGTERM')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
await client.close()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = restartRuntimeCommand
|
package/lib/services.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const { table, getBorderCharacters } = require('table')
|
|
5
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
6
|
-
|
|
7
|
-
const tableColumns = [
|
|
8
|
-
{
|
|
9
|
-
value: 'id',
|
|
10
|
-
alias: 'NAME',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
value: 'type',
|
|
14
|
-
alias: 'TYPE',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
value: 'entrypoint',
|
|
18
|
-
alias: 'ENTRYPOINT',
|
|
19
|
-
formatter: (entrypoint) => {
|
|
20
|
-
return entrypoint ? 'yes' : 'no'
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
const tableConfig = {
|
|
26
|
-
border: getBorderCharacters('void'),
|
|
27
|
-
columnDefault: {
|
|
28
|
-
paddingLeft: 0,
|
|
29
|
-
paddingRight: 1,
|
|
30
|
-
},
|
|
31
|
-
drawHorizontalLine: () => false,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function printRuntimeServices (services) {
|
|
35
|
-
const raws = [tableColumns.map(column => column.alias)]
|
|
36
|
-
|
|
37
|
-
for (const service of services.services) {
|
|
38
|
-
const raw = []
|
|
39
|
-
for (const column of tableColumns) {
|
|
40
|
-
let value = service[column.value]
|
|
41
|
-
if (column.formatter) {
|
|
42
|
-
value = column.formatter(value)
|
|
43
|
-
}
|
|
44
|
-
value ??= '-----'
|
|
45
|
-
raw.push(value)
|
|
46
|
-
}
|
|
47
|
-
raws.push(raw)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const servicesTable = table(raws, tableConfig)
|
|
51
|
-
process.stdout.write(servicesTable)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function getRuntimeServicesCommand (argv) {
|
|
55
|
-
const args = parseArgs({
|
|
56
|
-
args: argv,
|
|
57
|
-
options: {
|
|
58
|
-
pid: { type: 'string', short: 'p' },
|
|
59
|
-
name: { type: 'string', short: 'n' },
|
|
60
|
-
},
|
|
61
|
-
strict: false,
|
|
62
|
-
}).values
|
|
63
|
-
|
|
64
|
-
const client = new RuntimeApiClient()
|
|
65
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
66
|
-
|
|
67
|
-
const runtimeServices = await client.getRuntimeServices(runtime.pid)
|
|
68
|
-
printRuntimeServices(runtimeServices)
|
|
69
|
-
|
|
70
|
-
await client.close()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = getRuntimeServicesCommand
|
package/lib/stop.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseArgs } = require('node:util')
|
|
4
|
-
const RuntimeApiClient = require('./runtime-api-client')
|
|
5
|
-
|
|
6
|
-
async function stopRuntimeCommand (argv) {
|
|
7
|
-
const args = parseArgs({
|
|
8
|
-
args: argv,
|
|
9
|
-
options: {
|
|
10
|
-
pid: { type: 'string', short: 'p' },
|
|
11
|
-
name: { type: 'string', short: 'n' },
|
|
12
|
-
},
|
|
13
|
-
strict: false,
|
|
14
|
-
}).values
|
|
15
|
-
|
|
16
|
-
const client = new RuntimeApiClient()
|
|
17
|
-
const runtime = await client.getMatchingRuntime(args)
|
|
18
|
-
|
|
19
|
-
await client.stopRuntime(runtime.pid)
|
|
20
|
-
console.log(`Stopped runtime "${runtime.packageName}".`)
|
|
21
|
-
|
|
22
|
-
await client.close()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = stopRuntimeCommand
|