cvmts: Delete cgroup on VM stop
Makes clean shutdown with systemd actually work. I've also made superqemu version a SemVer thing so that we don't need to bump it as often, only on a major or minor bump.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@computernewb/nodejs-rfb": "^0.3.0",
|
||||
"@computernewb/superqemu": "0.3.0",
|
||||
"@computernewb/superqemu": "^0.3.0",
|
||||
"@cvmts/cvm-rs": "*",
|
||||
"@maxmind/geoip2-node": "^5.0.0",
|
||||
"execa": "^8.0.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Cgroup management code
|
||||
// this sucks, ill mess with it later
|
||||
|
||||
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmdirSync, writeFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export class CGroupController {
|
||||
@@ -46,6 +46,16 @@ export class CGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
DeleteSubgroup(name: string): void {
|
||||
let subgroup_root = path.join(this.path, name);
|
||||
if (!this.HasSubgroup(name)) {
|
||||
throw new Error(`Subgroup ${name} does not exist`);
|
||||
}
|
||||
|
||||
//console.log("Deleting subgroup", name);
|
||||
rmdirSync(subgroup_root);
|
||||
}
|
||||
|
||||
// Gets a CGroup inside of this cgroup.
|
||||
GetSubgroup(name: string): CGroup {
|
||||
// make the subgroup if it doesn't already exist
|
||||
|
||||
@@ -47,12 +47,16 @@ class CGroupLimitedProcess extends EventEmitter implements IProcess {
|
||||
stdin: Writable | null = null;
|
||||
stdout: Readable | null = null;
|
||||
stderr: Readable | null = null;
|
||||
private cgroup_root: CGroup;
|
||||
private cgroup: CGroup;
|
||||
private id;
|
||||
private limits;
|
||||
|
||||
constructor(cg: CGroup, limits: CgroupLimits, command: string, opts?: ProcessLaunchOptions) {
|
||||
constructor(cgroup_root: CGroup, id: string, limits: CgroupLimits, command: string, opts?: ProcessLaunchOptions) {
|
||||
super();
|
||||
this.cgroup = cg;
|
||||
this.cgroup_root = cgroup_root;
|
||||
this.cgroup = cgroup_root.GetSubgroup(id);
|
||||
this.id = id;
|
||||
this.limits = limits;
|
||||
|
||||
if(!this.limits.limitProcess)
|
||||
@@ -87,6 +91,7 @@ class CGroupLimitedProcess extends EventEmitter implements IProcess {
|
||||
this.stdout = null;
|
||||
this.stderr = null;
|
||||
|
||||
this.cgroup_root.DeleteSubgroup(this.id);
|
||||
this.process.removeAllListeners();
|
||||
this.removeAllListeners();
|
||||
}
|
||||
@@ -95,9 +100,11 @@ class CGroupLimitedProcess extends EventEmitter implements IProcess {
|
||||
export class QemuResourceLimitedLauncher implements IProcessLauncher {
|
||||
public group;
|
||||
private limits;
|
||||
private name;
|
||||
|
||||
constructor(name: string, limits: CgroupLimits) {
|
||||
let root = CGroup.Self();
|
||||
this.name = name;
|
||||
this.group = root.GetSubgroup(name);
|
||||
this.limits = limits;
|
||||
|
||||
@@ -109,6 +116,6 @@ export class QemuResourceLimitedLauncher implements IProcessLauncher {
|
||||
}
|
||||
|
||||
launch(command: string, opts?: ProcessLaunchOptions | undefined): IProcess {
|
||||
return new CGroupLimitedProcess(this.group, this.limits, command, opts);
|
||||
return new CGroupLimitedProcess(CGroup.Self(), this.name, this.limits, command, opts);
|
||||
}
|
||||
}
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@@ -41,13 +41,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@computernewb/superqemu@npm:0.3.0":
|
||||
version: 0.3.0
|
||||
resolution: "@computernewb/superqemu@npm:0.3.0"
|
||||
"@computernewb/superqemu@npm:^0.3.0":
|
||||
version: 0.3.2
|
||||
resolution: "@computernewb/superqemu@npm:0.3.2"
|
||||
dependencies:
|
||||
execa: "npm:^8.0.1"
|
||||
pino: "npm:^9.3.1"
|
||||
checksum: 10c0/232a83b3061bddcdf0fcef56a289f1d22cfdb70cc333ae2422a9246760310ac432b28a54e5d9d8bbcd5b87af8142d24c3fcaa9e3ce5e196bae7cf11b4538e8cc
|
||||
checksum: 10c0/845f1732f1e92b19bbf09b4bfc75381e707d367902535b1d520f1dc323e57f97cdf56d37a2d98e79c99443222224276d488d920e34010d199d798da7c564f7d1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -75,7 +75,7 @@ __metadata:
|
||||
resolution: "@cvmts/cvmts@workspace:cvmts"
|
||||
dependencies:
|
||||
"@computernewb/nodejs-rfb": "npm:^0.3.0"
|
||||
"@computernewb/superqemu": "npm:0.3.0"
|
||||
"@computernewb/superqemu": "npm:^0.3.0"
|
||||
"@cvmts/cvm-rs": "npm:*"
|
||||
"@maxmind/geoip2-node": "npm:^5.0.0"
|
||||
"@types/node": "npm:^20.12.5"
|
||||
|
||||
Reference in New Issue
Block a user