node-lxc 1.0.1 → 1.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/README.md +43 -19
- package/bin/aarch64-linux-gnu/node-lxc.node +0 -0
- package/bin/x86_64-linux-gnu/node-lxc.node +0 -0
- package/lib/binding.js +7 -4
- package/lib/binding.js.map +1 -1
- package/lib/index.d.ts +35 -1
- package/lib/index.js.map +1 -1
- package/lib/types/custom/ExecSession.d.ts +30 -0
- package/lib/types/custom/ExecSession.js +3 -0
- package/lib/types/custom/ExecSession.js.map +1 -0
- package/lib/types/custom/index.d.ts +1 -0
- package/lib/types/custom/index.js +1 -0
- package/lib/types/custom/index.js.map +1 -1
- package/package.json +4 -4
- package/examples/attach/index.ts +0 -29
- package/examples/attach-streams/index.ts +0 -34
- package/examples/checkpoint/index.ts +0 -34
- package/examples/clone/index.ts +0 -34
- package/examples/concurrent_create/index.ts +0 -30
- package/examples/concurrent_destroy/index.ts +0 -23
- package/examples/concurrent_shutdown/index.ts +0 -28
- package/examples/concurrent_start/index.ts +0 -28
- package/examples/concurrent_stop/index.ts +0 -28
- package/examples/config/index.ts +0 -18
- package/examples/console/index.ts +0 -17
- package/examples/console_async/index.ts +0 -101
- package/examples/create/index.ts +0 -12
- package/examples/create_snapshot/index.ts +0 -10
- package/examples/destroy/index.ts +0 -10
- package/examples/destroy_snapshots/index.ts +0 -10
- package/examples/device_add_remove/index.ts +0 -11
- package/examples/execute/index.ts +0 -10
- package/examples/freeze/index.ts +0 -11
- package/examples/images/index.ts +0 -10
- package/examples/interfaces/index.ts +0 -10
- package/examples/ipaddress/index.ts +0 -12
- package/examples/limit/index.ts +0 -15
- package/examples/list/index.ts +0 -12
- package/examples/list_keys/index.ts +0 -10
- package/examples/list_snapshots/index.ts +0 -9
- package/examples/reboot/index.ts +0 -11
- package/examples/rename/index.ts +0 -11
- package/examples/restore_snapshot/index.ts +0 -11
- package/examples/shutdown/index.ts +0 -19
- package/examples/start/index.ts +0 -11
- package/examples/stats/index.ts +0 -48
- package/examples/stop/index.ts +0 -11
- package/examples/unfreeze/index.ts +0 -11
package/README.md
CHANGED
|
@@ -23,19 +23,15 @@
|
|
|
23
23
|
- **Memory-safe** — no leaks; all heap buffers freed, all async captures by value
|
|
24
24
|
- **TypeScript** — full type declarations included
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Requirements
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Node.js | ≥ 12.17 |
|
|
31
|
-
| LXC | ≥ 4.0 |
|
|
32
|
-
| liblxc-dev | (same as LXC) |
|
|
33
|
-
| g++ | ≥ 7 |
|
|
28
|
+
- Node.js ≥ 12.17
|
|
29
|
+
- LXC ≥ 4.0 (runtime library only)
|
|
34
30
|
|
|
35
31
|
Install LXC on Debian/Ubuntu:
|
|
36
32
|
|
|
37
33
|
```sh
|
|
38
|
-
sudo apt install lxc
|
|
34
|
+
sudo apt install lxc
|
|
39
35
|
```
|
|
40
36
|
|
|
41
37
|
Verify your kernel supports LXC features:
|
|
@@ -50,7 +46,14 @@ lxc-checkconfig
|
|
|
50
46
|
npm install node-lxc
|
|
51
47
|
```
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
Pre-built binaries are included for the following platforms — no compilation step required:
|
|
50
|
+
|
|
51
|
+
| Architecture | GNU triplet |
|
|
52
|
+
|---|---|
|
|
53
|
+
| x86-64 | `x86_64-linux-gnu` |
|
|
54
|
+
| ARM64 | `aarch64-linux-gnu` |
|
|
55
|
+
|
|
56
|
+
Other Linux architectures must be [built from source](#building-from-source).
|
|
54
57
|
|
|
55
58
|
## Quick Start
|
|
56
59
|
|
|
@@ -163,6 +166,18 @@ await c.save(alt_file)
|
|
|
163
166
|
// Run a command; returns its exit code
|
|
164
167
|
await c.exec({ argv: string[], ...lxc_attach_options }) // → number
|
|
165
168
|
|
|
169
|
+
// Run a command and capture all output
|
|
170
|
+
const { exitCode, stdout, stderr } = await c.execOutput({ argv: ["/bin/hostname"] });
|
|
171
|
+
|
|
172
|
+
// Run a command and stream output as events
|
|
173
|
+
const session = await c.execAsync({ argv: ["/usr/bin/top", "-b", "-n1"] });
|
|
174
|
+
session
|
|
175
|
+
.on("stdout", (chunk: Buffer) => process.stdout.write(chunk))
|
|
176
|
+
.on("stderr", (chunk: Buffer) => process.stderr.write(chunk))
|
|
177
|
+
.on("exit", (code: number) => console.log("exit:", code));
|
|
178
|
+
session.kill(); // send SIGTERM
|
|
179
|
+
session.kill(9); // send SIGKILL
|
|
180
|
+
|
|
166
181
|
// Open a shell; returns the shell's exit code
|
|
167
182
|
await c.attach(options?) // → number
|
|
168
183
|
|
|
@@ -277,20 +292,29 @@ npm run example:execute
|
|
|
277
292
|
npm run example:console_async
|
|
278
293
|
```
|
|
279
294
|
|
|
295
|
+
---
|
|
296
|
+
|
|
280
297
|
## Building from Source
|
|
281
298
|
|
|
282
|
-
|
|
283
|
-
# Install system dependencies (Debian/Ubuntu)
|
|
284
|
-
sudo apt install g++ lxc lxc-dev
|
|
299
|
+
Required additional dependencies:
|
|
285
300
|
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
| Tool | Version |
|
|
302
|
+
|---|---|
|
|
303
|
+
| liblxc-dev | same as LXC |
|
|
304
|
+
| g++ | ≥ 7 |
|
|
305
|
+
| cmake | any recent |
|
|
306
|
+
|
|
307
|
+
```sh
|
|
308
|
+
sudo apt install lxc lxc-dev g++ cmake
|
|
309
|
+
```
|
|
288
310
|
|
|
289
|
-
|
|
290
|
-
node-gyp configure
|
|
291
|
-
node-gyp build
|
|
311
|
+
Clone and build:
|
|
292
312
|
|
|
293
|
-
|
|
313
|
+
```sh
|
|
314
|
+
git clone https://github.com/SourceRegistry/node-lxc.git
|
|
315
|
+
cd node-lxc
|
|
316
|
+
npm install
|
|
317
|
+
npx node-gyp configure && npx node-gyp build
|
|
294
318
|
npx tsc --build
|
|
295
319
|
```
|
|
296
320
|
|
|
@@ -325,4 +349,4 @@ Please ensure:
|
|
|
325
349
|
|
|
326
350
|
- [LXC API documentation](https://linuxcontainers.org/lxc/apidoc/structlxc__container.html)
|
|
327
351
|
- [LXC C header (GitHub)](https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h)
|
|
328
|
-
- [Linux Containers](https://linuxcontainers.org)
|
|
352
|
+
- [Linux Containers](https://linuxcontainers.org)
|
|
Binary file
|
|
Binary file
|
package/lib/binding.js
CHANGED
|
@@ -21,12 +21,15 @@ if (!is_package) {
|
|
|
21
21
|
addonPath = path_1.default.join(__dirname, '..', 'build', mode, `${base_name}.node`);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const archToTriplet = {
|
|
25
|
+
x64: 'x86_64-linux-gnu',
|
|
26
|
+
arm64: 'aarch64-linux-gnu',
|
|
27
|
+
};
|
|
28
|
+
const triplet = platform === 'linux' ? archToTriplet[arch] : undefined;
|
|
29
|
+
if (!triplet) {
|
|
28
30
|
throw new Error(`Unsupported platform or architecture: ${platform}-${arch}`);
|
|
29
31
|
}
|
|
32
|
+
addonPath = path_1.default.join(__dirname, '..', 'bin', triplet, `${base_name}.node`);
|
|
30
33
|
}
|
|
31
34
|
exports.default = require(addonPath);
|
|
32
35
|
//# sourceMappingURL=binding.js.map
|
package/lib/binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../lib/binding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,gDAAwB;AAExB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;AAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACtD,IAAI,SAAS,CAAC;AACd,IAAI,CAAC,UAAU,EAAE,CAA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M,OAAO,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IACD,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC;AAChF,CAAC;AAGD,kBAAe,OAAO,CAAC,SAAS,CAAC,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @author A.P.A. Slaa (a.p.a.slaa@projectsource.nl) ProjectSource V.O.F.
|
|
3
3
|
* @date 03-07-2024
|
|
4
4
|
*/
|
|
5
|
-
import { bdev_specs, lxc_attach_options, lxc_clone_options, lxc_console_log, LXC_CREATE, LXC_MIGRATE, LXC_MOUNT, lxc_mount, lxc_snapshot, migrate_opts, ConsoleSession } from "./types";
|
|
5
|
+
import { bdev_specs, lxc_attach_options, lxc_clone_options, lxc_console_log, LXC_CREATE, LXC_MIGRATE, LXC_MOUNT, lxc_mount, lxc_snapshot, migrate_opts, ConsoleSession, ExecOutputResult, ExecSession } from "./types";
|
|
6
6
|
export * from "./types";
|
|
7
7
|
export type ContainerState = "STOPPED" | "STARTING" | "RUNNING" | "STOPPING" | "ABORTING" | "FREEZING" | "FROZEN" | "THAWED";
|
|
8
8
|
export type ContainerStats = {
|
|
@@ -498,6 +498,40 @@ export type Container = {
|
|
|
498
498
|
exec(options: Partial<lxc_attach_options> & {
|
|
499
499
|
argv: string[];
|
|
500
500
|
}): Promise<number>;
|
|
501
|
+
/**
|
|
502
|
+
* Run a command inside the container and capture its output.
|
|
503
|
+
* Internally creates pipes for stdout and stderr so the child never writes
|
|
504
|
+
* to the caller's terminal. Both streams are collected in memory and
|
|
505
|
+
* returned when the process exits.
|
|
506
|
+
* @param options.argv {string[]} Command and arguments.
|
|
507
|
+
* @param options {Partial<lxc_attach_options>} Attach options (uid, gid, env, …). `stdio` is ignored.
|
|
508
|
+
* @returns {Promise<ExecOutputResult>} `{ exitCode, stdout, stderr }`.
|
|
509
|
+
*/
|
|
510
|
+
execOutput(options: Omit<Partial<lxc_attach_options>, 'stdio'> & {
|
|
511
|
+
argv: string[];
|
|
512
|
+
}): Promise<ExecOutputResult>;
|
|
513
|
+
/**
|
|
514
|
+
* Run a command inside the container and stream its output as events.
|
|
515
|
+
* Resolves with a session object once the process has started.
|
|
516
|
+
* Register all listeners **before** the first `await` after this call so
|
|
517
|
+
* no output is lost between process start and listener registration.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* const session = await c.execAsync({ argv: ['/usr/bin/top', '-b', '-n1'] });
|
|
522
|
+
* session
|
|
523
|
+
* .on('stdout', chunk => process.stdout.write(chunk))
|
|
524
|
+
* .on('stderr', chunk => process.stderr.write(chunk))
|
|
525
|
+
* .on('exit', code => console.log('exit:', code));
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @param options.argv {string[]} Command and arguments.
|
|
529
|
+
* @param options {Partial<lxc_attach_options>} Attach options. `stdio` is ignored.
|
|
530
|
+
* @returns {Promise<ExecSession>} Active streaming session.
|
|
531
|
+
*/
|
|
532
|
+
execAsync(options: Omit<Partial<lxc_attach_options>, 'stdio'> & {
|
|
533
|
+
argv: string[];
|
|
534
|
+
}): Promise<ExecSession>;
|
|
501
535
|
/**
|
|
502
536
|
* Set a global timeout for LXC operations on this container.
|
|
503
537
|
* After the timeout expires LXC will abort the operation with an error.
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;AAQH,0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,CAAC,QAAQ,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sFAAsF,CAAC,CAAC;QAC5L,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,QAAoB,CAAC;IACrD,CAAC;CACJ,CAAA;AAGD,0CAAuB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result returned by {@link Container.execOutput}.
|
|
3
|
+
*/
|
|
4
|
+
export interface ExecOutputResult {
|
|
5
|
+
/** Process exit code, or -1 if the process was killed by a signal. */
|
|
6
|
+
exitCode: number;
|
|
7
|
+
/** All data written to stdout, as a UTF-8 string. */
|
|
8
|
+
stdout: string;
|
|
9
|
+
/** All data written to stderr, as a UTF-8 string. */
|
|
10
|
+
stderr: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Streaming exec session returned by {@link Container.execAsync}.
|
|
14
|
+
*
|
|
15
|
+
* Register listeners before yielding control back to the event loop so no
|
|
16
|
+
* output is missed. The session closes automatically when the process exits.
|
|
17
|
+
*/
|
|
18
|
+
export interface ExecSession {
|
|
19
|
+
/** Subscribe to a stdout chunk, stderr chunk, or process exit. */
|
|
20
|
+
on(event: 'stdout', listener: (chunk: Buffer) => void): this;
|
|
21
|
+
on(event: 'stderr', listener: (chunk: Buffer) => void): this;
|
|
22
|
+
on(event: 'exit', listener: (exitCode: number) => void): this;
|
|
23
|
+
/**
|
|
24
|
+
* Send a signal to the attached process.
|
|
25
|
+
* @param signal - Signal number (default: SIGTERM = 15).
|
|
26
|
+
*/
|
|
27
|
+
kill(signal?: number): void;
|
|
28
|
+
/** `true` once the process has exited and all resources have been freed. */
|
|
29
|
+
get closed(): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecSession.js","sourceRoot":"","sources":["../../../../lib/types/custom/ExecSession.ts"],"names":[],"mappings":""}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./ConsoleSession"), exports);
|
|
18
|
+
__exportStar(require("./ExecSession"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/types/custom/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/types/custom/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,gDAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-lxc",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Node.js native bindings for LXC (Linux Containers) — a complete, production-ready wrapper around liblxc built with N-API",
|
|
5
5
|
"homepage": "https://github.com/SourceRegistry/node-lxc#readme",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
"types": "lib/index.d.ts",
|
|
27
27
|
"files": [
|
|
28
28
|
"lib",
|
|
29
|
-
"bin"
|
|
30
|
-
"examples"
|
|
29
|
+
"bin"
|
|
31
30
|
],
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"node-addon-api": "^8.5.0"
|
|
@@ -83,5 +82,6 @@
|
|
|
83
82
|
},
|
|
84
83
|
"engines": {
|
|
85
84
|
"node": "~10 >=10.20 || >=12.17"
|
|
86
|
-
}
|
|
85
|
+
},
|
|
86
|
+
"gypfile": false
|
|
87
87
|
}
|
package/examples/attach/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
const c = new Container(name);
|
|
10
|
-
if (!c.defined) {
|
|
11
|
-
console.log("Container creating...");
|
|
12
|
-
await c.create({
|
|
13
|
-
template: "download",
|
|
14
|
-
argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
15
|
-
});
|
|
16
|
-
console.log("Created");
|
|
17
|
-
}
|
|
18
|
-
if (!c.running) {
|
|
19
|
-
await c.start();
|
|
20
|
-
}
|
|
21
|
-
console.log(`Attaching to container '${name}'`)
|
|
22
|
-
await c.attach({
|
|
23
|
-
stdio: [process.stdin.fd, process.stdout.fd, process.stderr.fd],
|
|
24
|
-
});
|
|
25
|
-
console.warn(`Destroying '${name}'`)
|
|
26
|
-
await c.destroy({force: true});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
main().catch(console.error);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
import {openSync} from "node:fs";
|
|
3
|
-
|
|
4
|
-
const name = "test-ct"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
8
|
-
*/
|
|
9
|
-
async function main() {
|
|
10
|
-
const c = new Container(name);
|
|
11
|
-
if (!c.defined) {
|
|
12
|
-
console.log("Container creating...");
|
|
13
|
-
await c.create({
|
|
14
|
-
template: "download",
|
|
15
|
-
argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
16
|
-
});
|
|
17
|
-
console.log("Created");
|
|
18
|
-
}
|
|
19
|
-
if (!c.running) {
|
|
20
|
-
await c.start();
|
|
21
|
-
}
|
|
22
|
-
console.log(`Attaching to container '${name}'`);
|
|
23
|
-
|
|
24
|
-
const stdoutFd = openSync("examples/attach-streams/stdout", "w+"); //TODO: Check if this works
|
|
25
|
-
const stderrFd = openSync("examples/attach-streams/stderr", "w+"); //TODO: Check if this works
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await c.attach({stdio: [process.stdin.fd, stdoutFd, stderrFd]}); //TODO: Check if this works
|
|
29
|
-
|
|
30
|
-
console.warn(`Destroying '${name}'`)
|
|
31
|
-
await c.destroy({force: true});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
main().catch(console.error);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {Container, LXC_LOGLEVEL} from "../../lib";
|
|
2
|
-
import {readdir} from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
const name = "test-ct"
|
|
5
|
-
const checkpointDir = `/tmp/${name}`
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
9
|
-
*/
|
|
10
|
-
async function main() {
|
|
11
|
-
const c = new Container(name);
|
|
12
|
-
|
|
13
|
-
c.setConfigItem("lxc.log.file", `./${name}/.log`);
|
|
14
|
-
c.setConfigItem("lxc.log.level", LXC_LOGLEVEL.TRACE);
|
|
15
|
-
|
|
16
|
-
if (!c.defined) {
|
|
17
|
-
console.log("Container creating...");
|
|
18
|
-
await c.create({
|
|
19
|
-
template: "download",
|
|
20
|
-
argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
21
|
-
});
|
|
22
|
-
console.log("Created");
|
|
23
|
-
}
|
|
24
|
-
if (!c.running) {
|
|
25
|
-
await c.start();
|
|
26
|
-
}
|
|
27
|
-
console.log(`Creating lcone for container '${name}' in directory '${checkpointDir}'`);
|
|
28
|
-
await c.checkpoint(checkpointDir, true, true); //TODO
|
|
29
|
-
|
|
30
|
-
console.table(await readdir(checkpointDir));
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
main().catch(console.error);
|
package/examples/clone/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {Container, LXC_LOGLEVEL} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
const c = new Container(name);
|
|
10
|
-
|
|
11
|
-
c.setConfigItem("lxc.log.file", `./${name}/.log`);
|
|
12
|
-
c.setConfigItem("lxc.log.level", LXC_LOGLEVEL.TRACE);
|
|
13
|
-
|
|
14
|
-
if (!c.defined) {
|
|
15
|
-
console.log("Container creating...");
|
|
16
|
-
await c.create({
|
|
17
|
-
template: "download",
|
|
18
|
-
argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
19
|
-
});
|
|
20
|
-
console.log("Created");
|
|
21
|
-
}
|
|
22
|
-
if (c.running) {
|
|
23
|
-
console.warn("Container needs to be stopped to create a clone")
|
|
24
|
-
console.log("Container shutting down...");
|
|
25
|
-
await c.shutdown();
|
|
26
|
-
console.log("Done");
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
console.log("Creating clone...")
|
|
30
|
-
await c.clone({newname: name + "2"});
|
|
31
|
-
console.log("Done");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
main().catch(console.error);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
-
const c = new Container(name + i);
|
|
12
|
-
if(!c.defined) {
|
|
13
|
-
await c.create({
|
|
14
|
-
template: "download", argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
15
|
-
});
|
|
16
|
-
console.log(`Created ${c.name}`);
|
|
17
|
-
}else{
|
|
18
|
-
console.warn(`Container ${c.name} already defined`);
|
|
19
|
-
}
|
|
20
|
-
return c;
|
|
21
|
-
}
|
|
22
|
-
));
|
|
23
|
-
|
|
24
|
-
console.table(containers.map((c) => {
|
|
25
|
-
return {name: c.name, state: c.state}
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
main().catch(console.error);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
-
let c = new Container(name + i);
|
|
12
|
-
if (c.defined) {
|
|
13
|
-
console.log(`Destroying ${c.name}`);
|
|
14
|
-
await c.destroy();
|
|
15
|
-
} else {
|
|
16
|
-
console.warn(`Container ${c.name} not defined`);
|
|
17
|
-
}
|
|
18
|
-
return c;
|
|
19
|
-
}
|
|
20
|
-
));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
main().catch(console.error);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
-
let c = new Container(name + i);
|
|
12
|
-
if (c.defined) {
|
|
13
|
-
console.log(`Shutting down ${c.name}`);
|
|
14
|
-
await c.shutdown();
|
|
15
|
-
} else {
|
|
16
|
-
console.warn(`Container ${c.name} not defined`);
|
|
17
|
-
}
|
|
18
|
-
return c;
|
|
19
|
-
}
|
|
20
|
-
));
|
|
21
|
-
|
|
22
|
-
console.table(containers.map((c) => {
|
|
23
|
-
return {name: c.name, state: c.state}
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
main().catch(console.error);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
-
const c = new Container(name + i);
|
|
12
|
-
if (!c.running) {
|
|
13
|
-
await c.start();
|
|
14
|
-
console.log(`Started ${c.name}`);
|
|
15
|
-
} else {
|
|
16
|
-
console.warn(`Container ${c.name} already running`);
|
|
17
|
-
}
|
|
18
|
-
return c;
|
|
19
|
-
}
|
|
20
|
-
));
|
|
21
|
-
|
|
22
|
-
console.table(containers.map((c) => {
|
|
23
|
-
return {name: c.name, state: c.state}
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
main().catch(console.error);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
-
const c = new Container(name + i);
|
|
12
|
-
if (c.running) {
|
|
13
|
-
await c.stop();
|
|
14
|
-
console.log(`Stopped ${c.name}`);
|
|
15
|
-
} else {
|
|
16
|
-
console.warn(`Container ${c.name} already stopped`);
|
|
17
|
-
}
|
|
18
|
-
return c;
|
|
19
|
-
}
|
|
20
|
-
));
|
|
21
|
-
|
|
22
|
-
console.table(containers.map((c) => {
|
|
23
|
-
return {name: c.name, state: c.state}
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
main().catch(console.error);
|
package/examples/config/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "test-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
|
|
10
|
-
const c = new Container(name);
|
|
11
|
-
c.setConfigItem("lxc.utsname", "test-host1");
|
|
12
|
-
|
|
13
|
-
const rootfs = c.getConfigItem("lxc.rootfs");
|
|
14
|
-
console.log("Root FS: ", rootfs);
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
main().catch(console.error);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const name = "node-ct"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
-
*/
|
|
8
|
-
async function main() {
|
|
9
|
-
const c = new Container(name);
|
|
10
|
-
if (c.defined && c.running) {
|
|
11
|
-
await c.console(0, [process.stdin.fd, process.stdout.fd, process.stderr.fd], 1);
|
|
12
|
-
} else {
|
|
13
|
-
console.warn(`Container '${name}' not defined or not running`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
main().catch(console.error);
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
const containerName = 'node-ct'; // Change to your container name
|
|
4
|
-
|
|
5
|
-
async function main() {
|
|
6
|
-
const container = new Container(containerName);
|
|
7
|
-
container.setConfigItem('lxc.log.file', `./${containerName}/container.log`)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!container.defined || !container.running) {
|
|
11
|
-
console.error(`Container '${containerName}' is not defined or not running.`);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
console.log(`📎 Attaching to console of container '${containerName}' (TTY 0)`);
|
|
16
|
-
console.log(`💡 Type commands, press Ctrl+C or Ctrl+D to exit.\n`);
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
|
|
20
|
-
// console.log(container.initPIDFd())
|
|
21
|
-
|
|
22
|
-
// Open console
|
|
23
|
-
const session = await container.consoleAsync(0);
|
|
24
|
-
|
|
25
|
-
// Ensure we're in raw mode
|
|
26
|
-
if (!process.stdin.isTTY) {
|
|
27
|
-
console.error('Stdin is not a TTY');
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
process.stdin.setRawMode(true);
|
|
32
|
-
process.stdin.setEncoding('utf8');
|
|
33
|
-
|
|
34
|
-
// Disable line buffering
|
|
35
|
-
process.stdin.resume();
|
|
36
|
-
|
|
37
|
-
// Handle data from container → stdout
|
|
38
|
-
session.on('data', (chunk) => {
|
|
39
|
-
process.stdout.write(chunk);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
session.on('close', () => {
|
|
43
|
-
process.exit(0);
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// Handle input from user → container
|
|
47
|
-
process.stdin.on('data', (data) => {
|
|
48
|
-
if (data.toString() === '\x04') {
|
|
49
|
-
// Ctrl+D
|
|
50
|
-
session.close();
|
|
51
|
-
process.exit(0);
|
|
52
|
-
} else {
|
|
53
|
-
session.write(data);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Handle terminal resize
|
|
59
|
-
function handleResize() {
|
|
60
|
-
const cols = process.stdout.columns || 80;
|
|
61
|
-
const rows = process.stdout.rows || 24;
|
|
62
|
-
try {
|
|
63
|
-
session.resize(cols, rows);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
// Ignore resize errors
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Initial resize
|
|
70
|
-
handleResize();
|
|
71
|
-
|
|
72
|
-
// Watch for resize events
|
|
73
|
-
process.stdout.on('resize', handleResize);
|
|
74
|
-
|
|
75
|
-
// Optional: send SIGWINCH on SIGHUP, SIGTERM
|
|
76
|
-
process.on('SIGINT', () => session.close());
|
|
77
|
-
process.on('SIGTERM', () => session.close());
|
|
78
|
-
|
|
79
|
-
// Cleanup on exit
|
|
80
|
-
const cleanup = () => {
|
|
81
|
-
session.close();
|
|
82
|
-
process.stdin.setRawMode(false);
|
|
83
|
-
process.exit(0);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
process.on('exit', cleanup);
|
|
87
|
-
process.on('SIGINT', cleanup);
|
|
88
|
-
process.on('SIGTERM', cleanup);
|
|
89
|
-
|
|
90
|
-
console.log('✅ Connected. You can now type inside the container.\n');
|
|
91
|
-
} catch (err) {
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
console.error('❌ Console error:', err?.message || err);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
main().catch(err => {
|
|
99
|
-
console.error('❌ Unexpected error:', err);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
});
|
package/examples/create/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
if (!c.defined) {
|
|
6
|
-
console.log("Container creating...")
|
|
7
|
-
await c.create({template: "download", argv: ["--dist", "ubuntu", "--release", "jammy", "--arch", "amd64"]});
|
|
8
|
-
console.log("Done")
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(console.error)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
if (c.defined && c.running) {
|
|
6
|
-
await c.addDeviceNode("/dev/network_latency");
|
|
7
|
-
await c.removeDeviceNode("/dev/network_latency");
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
main().catch(console.error)
|
package/examples/freeze/index.ts
DELETED
package/examples/images/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
if (c.defined) {
|
|
6
|
-
console.table(Promise.all((await c.getInterfaces()).map(async (inf) => {
|
|
7
|
-
return {interface: inf, ipv4: await c.getIPs(inf, "inet"), ipv6: await c.getIPs(inf, "inet6", 0)}
|
|
8
|
-
})));
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(console.error)
|
package/examples/limit/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
const limitInBytes = Number(c.getCGroupItem("memory.limit_in_bytes"));
|
|
6
|
-
console.log(`current limitInBytes ${limitInBytes}`);
|
|
7
|
-
const swapMemoryLimitInBytes = Number(c.getCGroupItem("memory.memsw.limit_in_bytes"));
|
|
8
|
-
console.log(`current swapMemoryLimitInBytes ${swapMemoryLimitInBytes}`);
|
|
9
|
-
|
|
10
|
-
c.setCGroupItem("memory.limit_in_bytes", (limitInBytes/4).toString())
|
|
11
|
-
c.setCGroupItem("memory.memsw.limit_in_bytes", (swapMemoryLimitInBytes/4).toString())
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
main().catch(console.error)
|
package/examples/list/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {LXC} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
console.log("===== ACTIVE =====");
|
|
5
|
-
LXC.ListAllActiveContainers().forEach(console.log)
|
|
6
|
-
console.log("===== DEFINED =====");
|
|
7
|
-
LXC.ListAllDefinedContainers().forEach(console.log)
|
|
8
|
-
console.log("===== ALL =====");
|
|
9
|
-
LXC.ListAllContainers().forEach(console.log)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(console.error)
|
package/examples/reboot/index.ts
DELETED
package/examples/rename/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
if (!c.defined) {
|
|
6
|
-
throw "Container not defined"
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
console.log("Shutting down the container...\n")
|
|
10
|
-
await c.shutdown(30).then(
|
|
11
|
-
() =>
|
|
12
|
-
console.log("Container shutdown"),
|
|
13
|
-
(reason) => {
|
|
14
|
-
console.warn("Failed to shutdown container reason:", reason);
|
|
15
|
-
return c.stop();
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
main().catch(console.error)
|
package/examples/start/index.ts
DELETED
package/examples/stats/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {Container} from "../../lib";
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const c = new Container("node-ct");
|
|
5
|
-
if (!c.defined) {
|
|
6
|
-
throw "Container not defined"
|
|
7
|
-
}
|
|
8
|
-
const memUsed = c.getCGroupItem("memory.usage_in_bytes");
|
|
9
|
-
console.log("MemoryUsage:", memUsed);
|
|
10
|
-
|
|
11
|
-
const memLimit = c.getConfigItem("memory.limit_in_bytes");
|
|
12
|
-
console.log("MemoryLimit:", memLimit);
|
|
13
|
-
|
|
14
|
-
const kmemUsed = c.getConfigItem("memory.kmem.usage_in_bytes");
|
|
15
|
-
console.log("KernelMemoryUsage:", kmemUsed);
|
|
16
|
-
|
|
17
|
-
const kmemLimit = c.getConfigItem("memory.kmem.limit_in_bytes");
|
|
18
|
-
console.log("KernelMemoryLimit:", kmemLimit);
|
|
19
|
-
|
|
20
|
-
const swapUsed = c.getConfigItem("memory.memsw.usage_in_bytes");
|
|
21
|
-
console.log("MemorySwapUsage:", swapUsed);
|
|
22
|
-
|
|
23
|
-
const swapLimit = c.getConfigItem("memory.memsw.limit_in_bytes");
|
|
24
|
-
console.log("MemorySwapLimit:", swapUsed);
|
|
25
|
-
|
|
26
|
-
const blkioUsage = c.getConfigItem("blkio.throttle.io_service_bytes"); //TODO: Go bindings more complex on nested items and io services
|
|
27
|
-
console.log("BlkioUsage:", blkioUsage);
|
|
28
|
-
|
|
29
|
-
const cpuTime = c.getConfigItem("cpuacct.usage");
|
|
30
|
-
console.log("cpuacct.usage:", cpuTime);
|
|
31
|
-
|
|
32
|
-
const cpuTimePerCPU = c.getConfigItem("cpuacct.usage_percpu"); //TODO: Go bindings more complex on nested cpuTimes
|
|
33
|
-
console.log("cpuacct.usage_percpu:", cpuTimePerCPU);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const cpuStats = c.getConfigItem("cpuacct.usage_percpu"); //TODO: CPUStats returns the number of CPU cycles (in the units defined by USER_HZ on the system)
|
|
37
|
-
//TODO: consumed by tasks in this cgroup and its children in both user mode and system (kernel) mode.
|
|
38
|
-
console.log("cpuacct.stat:", cpuStats);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const interfaceStats = c.getConfigItem("cpuacct.usage"); //TODO: InterfaceStats returns the stats about container's network interfaces
|
|
42
|
-
// @see https://github.com/lxc/go-lxc/blob/v2/container.go#L1707
|
|
43
|
-
console.log("InterfaceStats:", interfaceStats);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
main().catch(console.error)
|
package/examples/stop/index.ts
DELETED