cleanup all runner user processes

This commit is contained in:
Thomas Hobson 2021-04-26 10:35:34 +12:00
parent 3b0f2a0013
commit 72bda367e0
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 30 additions and 45 deletions

62
api/package-lock.json generated
View File

@ -11,12 +11,12 @@
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"express-validator": "^6.10.0",
"is-docker": "^2.1.1",
"js-yaml": "^4.0.0",
"logplease": "^1.2.15",
"nocamel": "HexF/nocamel#patch-1",
"node-fetch": "^2.6.1",
"ps-list": "^7.2.0",
"semver": "^7.3.4",
"uuid": "^8.3.2",
"yargs": "^16.2.0"
@ -252,18 +252,6 @@
"node": ">= 0.10.0"
}
},
"node_modules/express-validator": {
"version": "6.10.0",
"resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.10.0.tgz",
"integrity": "sha512-gDtepU94EpUzgFvKO/8JzjZ4uqIF4xHekjYtcNgFDiBK6Hob3MQhPU8s/c3NaWd1xi5e5nA0oVmOJ0b0ZBO36Q==",
"dependencies": {
"lodash": "^4.17.20",
"validator": "^13.5.2"
},
"engines": {
"node": ">= 8.0.0"
}
},
"node_modules/finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@ -377,11 +365,6 @@
"js-yaml": "bin/js-yaml.js"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/logplease": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/logplease/-/logplease-1.2.15.tgz",
@ -511,6 +494,17 @@
"node": ">= 0.10"
}
},
"node_modules/ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
@ -696,14 +690,6 @@
"uuid": "dist/bin/uuid"
}
},
"node_modules/validator": {
"version": "13.5.2",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.5.2.tgz",
"integrity": "sha512-mD45p0rvHVBlY2Zuy3F3ESIe1h5X58GPfAtslBjY7EtTqGquZTj+VX/J4RnHWN8FKq0C9WRVt1oWAcytWRuYLQ==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
@ -953,15 +939,6 @@
"vary": "~1.1.2"
}
},
"express-validator": {
"version": "6.10.0",
"resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.10.0.tgz",
"integrity": "sha512-gDtepU94EpUzgFvKO/8JzjZ4uqIF4xHekjYtcNgFDiBK6Hob3MQhPU8s/c3NaWd1xi5e5nA0oVmOJ0b0ZBO36Q==",
"requires": {
"lodash": "^4.17.20",
"validator": "^13.5.2"
}
},
"finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@ -1039,11 +1016,6 @@
"argparse": "^2.0.1"
}
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"logplease": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/logplease/-/logplease-1.2.15.tgz",
@ -1136,6 +1108,11 @@
"ipaddr.js": "1.9.1"
}
},
"ps-list": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz",
"integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ=="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
@ -1275,11 +1252,6 @@
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"validator": {
"version": "13.5.2",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.5.2.tgz",
"integrity": "sha512-mD45p0rvHVBlY2Zuy3F3ESIe1h5X58GPfAtslBjY7EtTqGquZTj+VX/J4RnHWN8FKq0C9WRVt1oWAcytWRuYLQ=="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -11,6 +11,7 @@
"logplease": "^1.2.15",
"nocamel": "HexF/nocamel#patch-1",
"node-fetch": "^2.6.1",
"ps-list": "^7.2.0",
"semver": "^7.3.4",
"uuid": "^8.3.2",
"yargs": "^16.2.0"

View File

@ -5,6 +5,7 @@ const path = require('path');
const config = require('./config');
const globals = require('./globals');
const fs = require('fs/promises');
const ps_list = require('ps-list');
const job_states = {
READY: Symbol('Ready to be primed'),
@ -183,6 +184,17 @@ class Job {
async cleanup() {
logger.info(`Cleaning up job uuid=${this.uuid}`);
await fs.rm(this.dir, { recursive: true, force: true });
let processes = await ps_list();
processes.filter(proc => proc.uid == this.uid);
await Promise.all(
processes.map(
proc => process.kill(proc.pid, 'SIGKILL')
)
);
}
}