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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user