@yamf/services-pm3 0.1.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/package.json +23 -0
- package/service.js +68 -0
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yamf/services-pm3",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PM3 process management service for yamf - enables remote CLI capabilities",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "service.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"service.js"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@yamf/core": "0.4.0",
|
|
15
|
+
"@yamf/cli": "0.2.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@yamf/test": "0.1.4"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "yamf test -d ."
|
|
22
|
+
}
|
|
23
|
+
}
|
package/service.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createService,
|
|
3
|
+
Logger,
|
|
4
|
+
HttpError
|
|
5
|
+
} from '@yamf/core'
|
|
6
|
+
|
|
7
|
+
import { PM3 } from '@yamf/cli'
|
|
8
|
+
|
|
9
|
+
const logger = new Logger({ logGroup: 'pm3-service' })
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* PM3 Service - network-facing process manager for yamf nodes.
|
|
13
|
+
*
|
|
14
|
+
* Can be deployed at a given YAMF_SERVICE_URL to enable remote CLI capabilities.
|
|
15
|
+
* Wraps the pm3 library to expose start/stop/restart/list/status/logs over the wire.
|
|
16
|
+
*
|
|
17
|
+
* For now, this service is NOT recommended for production use.
|
|
18
|
+
*/
|
|
19
|
+
export default async function createPm3Service({
|
|
20
|
+
serviceName = 'pm3-service',
|
|
21
|
+
managedServicePath = '/tmp/yamf/services'
|
|
22
|
+
} = {}) {
|
|
23
|
+
const pm3 = new PM3()
|
|
24
|
+
|
|
25
|
+
const service = await createService(serviceName, async function (payload) {
|
|
26
|
+
const { command, filepath, options } = payload || {}
|
|
27
|
+
|
|
28
|
+
if (!command) {
|
|
29
|
+
throw new HttpError(400, 'command is required (start, stop, restart, list, status, logs, delete)')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
switch (command) {
|
|
33
|
+
case 'start': {
|
|
34
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for start')
|
|
35
|
+
return pm3.start(filepath, options)
|
|
36
|
+
}
|
|
37
|
+
case 'stop': {
|
|
38
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for stop')
|
|
39
|
+
return pm3.stop(filepath)
|
|
40
|
+
}
|
|
41
|
+
case 'restart': {
|
|
42
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for restart')
|
|
43
|
+
return pm3.restart(filepath, options)
|
|
44
|
+
}
|
|
45
|
+
case 'list': {
|
|
46
|
+
return pm3.list(options)
|
|
47
|
+
}
|
|
48
|
+
case 'status': {
|
|
49
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for status')
|
|
50
|
+
return pm3.status(filepath)
|
|
51
|
+
}
|
|
52
|
+
case 'logs': {
|
|
53
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for logs')
|
|
54
|
+
return pm3.logs(filepath)
|
|
55
|
+
}
|
|
56
|
+
case 'delete': {
|
|
57
|
+
if (!filepath) throw new HttpError(400, 'filepath is required for delete')
|
|
58
|
+
return pm3.delete(filepath)
|
|
59
|
+
}
|
|
60
|
+
// future: 'deploy' command for receiving esbuild bundles
|
|
61
|
+
default:
|
|
62
|
+
throw new HttpError(400, `Unknown command: ${command}. Valid: start, stop, restart, list, status, logs, delete`)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
logger.info(`pm3-service ready (managed path: ${managedServicePath})`)
|
|
67
|
+
return service
|
|
68
|
+
}
|