node-lxc 1.0.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/LICENSE +201 -0
- package/README.md +328 -0
- package/bin/x86_64-linux-gnu/node-lxc.node +0 -0
- package/examples/attach/index.ts +29 -0
- package/examples/attach-streams/index.ts +34 -0
- package/examples/checkpoint/index.ts +34 -0
- package/examples/clone/index.ts +34 -0
- package/examples/concurrent_create/index.ts +30 -0
- package/examples/concurrent_destroy/index.ts +23 -0
- package/examples/concurrent_shutdown/index.ts +28 -0
- package/examples/concurrent_start/index.ts +28 -0
- package/examples/concurrent_stop/index.ts +28 -0
- package/examples/config/index.ts +18 -0
- package/examples/console/index.ts +17 -0
- package/examples/console_async/index.ts +101 -0
- package/examples/create/index.ts +12 -0
- package/examples/create_snapshot/index.ts +10 -0
- package/examples/destroy/index.ts +10 -0
- package/examples/destroy_snapshots/index.ts +10 -0
- package/examples/device_add_remove/index.ts +11 -0
- package/examples/execute/index.ts +10 -0
- package/examples/freeze/index.ts +11 -0
- package/examples/images/index.ts +10 -0
- package/examples/interfaces/index.ts +10 -0
- package/examples/ipaddress/index.ts +12 -0
- package/examples/limit/index.ts +15 -0
- package/examples/list/index.ts +12 -0
- package/examples/list_keys/index.ts +10 -0
- package/examples/list_snapshots/index.ts +9 -0
- package/examples/reboot/index.ts +11 -0
- package/examples/rename/index.ts +11 -0
- package/examples/restore_snapshot/index.ts +11 -0
- package/examples/shutdown/index.ts +19 -0
- package/examples/start/index.ts +11 -0
- package/examples/stats/index.ts +48 -0
- package/examples/stop/index.ts +11 -0
- package/examples/unfreeze/index.ts +11 -0
- package/lib/binding.d.ts +6 -0
- package/lib/binding.js +32 -0
- package/lib/binding.js.map +1 -0
- package/lib/index.d.ts +612 -0
- package/lib/index.js +73 -0
- package/lib/index.js.map +1 -0
- package/lib/types/Image.d.ts +22 -0
- package/lib/types/Image.js +3 -0
- package/lib/types/Image.js.map +1 -0
- package/lib/types/LXC_ATTACH.d.ts +67 -0
- package/lib/types/LXC_ATTACH.js +72 -0
- package/lib/types/LXC_ATTACH.js.map +1 -0
- package/lib/types/LXC_CLONE.d.ts +34 -0
- package/lib/types/LXC_CLONE.js +39 -0
- package/lib/types/LXC_CLONE.js.map +1 -0
- package/lib/types/LXC_CREATE.d.ts +8 -0
- package/lib/types/LXC_CREATE.js +13 -0
- package/lib/types/LXC_CREATE.js.map +1 -0
- package/lib/types/LXC_LOGLEVEL.d.ts +15 -0
- package/lib/types/LXC_LOGLEVEL.js +20 -0
- package/lib/types/LXC_LOGLEVEL.js.map +1 -0
- package/lib/types/LXC_MIGRATE.d.ts +10 -0
- package/lib/types/LXC_MIGRATE.js +15 -0
- package/lib/types/LXC_MIGRATE.js.map +1 -0
- package/lib/types/LXC_MOUNT.d.ts +42 -0
- package/lib/types/LXC_MOUNT.js +45 -0
- package/lib/types/LXC_MOUNT.js.map +1 -0
- package/lib/types/Personality.d.ts +14 -0
- package/lib/types/Personality.js +19 -0
- package/lib/types/Personality.js.map +1 -0
- package/lib/types/bdev_specs.d.ts +48 -0
- package/lib/types/bdev_specs.js +3 -0
- package/lib/types/bdev_specs.js.map +1 -0
- package/lib/types/custom/ConsoleSession.d.ts +23 -0
- package/lib/types/custom/ConsoleSession.js +3 -0
- package/lib/types/custom/ConsoleSession.js.map +1 -0
- package/lib/types/custom/index.d.ts +1 -0
- package/lib/types/custom/index.js +18 -0
- package/lib/types/custom/index.js.map +1 -0
- package/lib/types/index.d.ts +20 -0
- package/lib/types/index.js +37 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/lxc_attach_env_policy.d.ts +8 -0
- package/lib/types/lxc_attach_env_policy.js +13 -0
- package/lib/types/lxc_attach_env_policy.js.map +1 -0
- package/lib/types/lxc_attach_options.d.ts +99 -0
- package/lib/types/lxc_attach_options.js +30 -0
- package/lib/types/lxc_attach_options.js.map +1 -0
- package/lib/types/lxc_clone_options.d.ts +52 -0
- package/lib/types/lxc_clone_options.js +7 -0
- package/lib/types/lxc_clone_options.js.map +1 -0
- package/lib/types/lxc_console_log.d.ts +10 -0
- package/lib/types/lxc_console_log.js +7 -0
- package/lib/types/lxc_console_log.js.map +1 -0
- package/lib/types/lxc_snapshot.d.ts +10 -0
- package/lib/types/lxc_snapshot.js +7 -0
- package/lib/types/lxc_snapshot.js.map +1 -0
- package/lib/types/migrate_opts.d.ts +17 -0
- package/lib/types/migrate_opts.js +7 -0
- package/lib/types/migrate_opts.js.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 ProjectSource V.O.F.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# node-lxc
|
|
2
|
+
|
|
3
|
+
> Node.js native bindings for [LXC](https://linuxcontainers.org/lxc/) (Linux Containers) — a complete, production-ready wrapper around `liblxc` built with N-API.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/node-lxc)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](https://linuxcontainers.org)
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Full lifecycle control** — create, start, stop, reboot, shutdown, destroy
|
|
13
|
+
- **Async-first** — all blocking operations return `Promise`s backed by a libuv thread pool
|
|
14
|
+
- **Interactive console** — non-blocking console sessions with `EventEmitter` interface
|
|
15
|
+
- **Rich configuration API** — get, set, clear, and bulk-read container configuration
|
|
16
|
+
- **Snapshot support** — create, list, restore, and destroy snapshots
|
|
17
|
+
- **CRIU integration** — checkpoint, restore, and live-migrate containers
|
|
18
|
+
- **Mount injection** — bind-mount paths into running containers without restart
|
|
19
|
+
- **Resource metrics** — async cgroup stat reads (memory, CPU, block I/O)
|
|
20
|
+
- **Network management** — attach/detach interfaces, query IPs and interfaces
|
|
21
|
+
- **Device hotplug** — add/remove device nodes into running containers
|
|
22
|
+
- **Seccomp support** — retrieve seccomp notification file descriptors
|
|
23
|
+
- **Memory-safe** — no leaks; all heap buffers freed, all async captures by value
|
|
24
|
+
- **TypeScript** — full type declarations included
|
|
25
|
+
|
|
26
|
+
## Prerequisites
|
|
27
|
+
|
|
28
|
+
| Requirement | Version |
|
|
29
|
+
|---|---|
|
|
30
|
+
| Node.js | ≥ 12.17 |
|
|
31
|
+
| LXC | ≥ 4.0 |
|
|
32
|
+
| liblxc-dev | (same as LXC) |
|
|
33
|
+
| g++ | ≥ 7 |
|
|
34
|
+
|
|
35
|
+
Install LXC on Debian/Ubuntu:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
sudo apt install lxc lxc-dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Verify your kernel supports LXC features:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
lxc-checkconfig
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm install node-lxc
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The package ships a pre-built binary for `x86_64-linux-gnu`. No compilation step is required for this platform.
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Container, GetVersion } from "node-lxc";
|
|
59
|
+
|
|
60
|
+
console.log("LXC", GetVersion()); // e.g. "5.0.2"
|
|
61
|
+
|
|
62
|
+
// Create and start a container
|
|
63
|
+
const c = new Container("my-container");
|
|
64
|
+
|
|
65
|
+
await c.create({
|
|
66
|
+
template: "download",
|
|
67
|
+
argv: ["--dist", "ubuntu", "--release", "jammy", "--arch", "amd64"],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
c.setConfigItem("lxc.net.0.type", "veth");
|
|
71
|
+
c.setConfigItem("lxc.net.0.link", "lxcbr0");
|
|
72
|
+
c.setConfigItem("lxc.net.0.flags", "up");
|
|
73
|
+
|
|
74
|
+
await c.start();
|
|
75
|
+
console.log(c.state); // "RUNNING"
|
|
76
|
+
console.log(c.initPID); // e.g. 12345
|
|
77
|
+
|
|
78
|
+
// Run a command and get the exit code
|
|
79
|
+
const code = await c.exec({ argv: ["/bin/sh", "-c", "echo hello"] });
|
|
80
|
+
console.log(code); // 0
|
|
81
|
+
|
|
82
|
+
await c.shutdown(30);
|
|
83
|
+
await c.destroy();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### Global functions
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import {
|
|
92
|
+
GetVersion, // → string
|
|
93
|
+
GetGlobalConfigItem, // (key: string) → string
|
|
94
|
+
ListAllContainers, // (lxcpath?: string) → string[]
|
|
95
|
+
ListAllDefinedContainers, // (lxcpath?: string) → string[]
|
|
96
|
+
ListAllActiveContainers, // (lxcpath?: string) → string[]
|
|
97
|
+
ConfigItemIsSupported, // (key: string) → boolean
|
|
98
|
+
HasApiExtension, // (extension: string) → boolean
|
|
99
|
+
GetWaitStates, // () → string[]
|
|
100
|
+
} from "node-lxc";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Container constructor
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const c = new Container(name: string, configPath?: string, alt_file?: string);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Parameter | Description |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `name` | Container name |
|
|
112
|
+
| `configPath` | LXC container directory (defaults to `lxc.lxcpath`) |
|
|
113
|
+
| `alt_file` | Alternate configuration file path |
|
|
114
|
+
|
|
115
|
+
### Lifecycle
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
await c.create({ template?, argv?, bdevtype?, bdev_specs?, flags? });
|
|
119
|
+
await c.start(useinit?, argv?);
|
|
120
|
+
await c.stop();
|
|
121
|
+
await c.reboot(timeout?); // → Promise<boolean>
|
|
122
|
+
await c.shutdown(timeout?); // → Promise<boolean>
|
|
123
|
+
await c.freeze();
|
|
124
|
+
await c.unfreeze();
|
|
125
|
+
await c.destroy({ include_snapshots?, force? });
|
|
126
|
+
await c.clone(options); // → Promise<Container>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### State and introspection
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
c.name // string
|
|
133
|
+
c.defined // boolean
|
|
134
|
+
c.running // boolean
|
|
135
|
+
c.state // ContainerState ("RUNNING" | "STOPPED" | ...)
|
|
136
|
+
c.initPID // number (-1 if not running)
|
|
137
|
+
c.error // { num: number, string: string | null }
|
|
138
|
+
c.daemonize // boolean (get/set)
|
|
139
|
+
c.configPath // string (get/set)
|
|
140
|
+
c.configFileName // string
|
|
141
|
+
c.mayControl() // → boolean
|
|
142
|
+
await c.initPIDFd() // → number (pidfd)
|
|
143
|
+
await c.devptsFd() // → number
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Configuration
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
c.getConfigItem(key) // → string | null
|
|
150
|
+
c.setConfigItem(key, value)
|
|
151
|
+
c.clearConfigItem(key)
|
|
152
|
+
c.clearConfig()
|
|
153
|
+
c.getRunningConfigItem(key) // → string | null (live, running container)
|
|
154
|
+
c.getKeys(prefix?) // → string[]
|
|
155
|
+
c.getConfigItems(prefix?) // → Record<string, string | null>
|
|
156
|
+
await c.loadConfig(alt_file)
|
|
157
|
+
await c.save(alt_file)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Execution and console
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Run a command; returns its exit code
|
|
164
|
+
await c.exec({ argv: string[], ...lxc_attach_options }) // → number
|
|
165
|
+
|
|
166
|
+
// Open a shell; returns the shell's exit code
|
|
167
|
+
await c.attach(options?) // → number
|
|
168
|
+
|
|
169
|
+
// Non-blocking async console session (EventEmitter)
|
|
170
|
+
const session = await c.consoleAsync(ttynum?) // → ConsoleSession
|
|
171
|
+
session.on("data", (chunk: Buffer) => { ... });
|
|
172
|
+
session.on("close", () => { ... });
|
|
173
|
+
session.write(data);
|
|
174
|
+
session.resize(cols, rows);
|
|
175
|
+
session.close();
|
|
176
|
+
|
|
177
|
+
// Blocking console (connects current stdio)
|
|
178
|
+
await c.console(ttynum, [stdinfd, stdoutfd, stderrfd], escape);
|
|
179
|
+
|
|
180
|
+
// Raw TTY allocation
|
|
181
|
+
const [ttyfd, ptxfd] = await c.consoleGetFds(ttynum?);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Resource metrics
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const stats: ContainerStats = await c.stats();
|
|
188
|
+
// {
|
|
189
|
+
// "memory.usage_in_bytes": string | null,
|
|
190
|
+
// "memory.limit_in_bytes": string | null,
|
|
191
|
+
// "memory.memsw.usage_in_bytes": string | null,
|
|
192
|
+
// "cpuacct.usage": string | null,
|
|
193
|
+
// "cpu.stat": string | null,
|
|
194
|
+
// "blkio.throttle.io_service_bytes": string | null,
|
|
195
|
+
// }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Network
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
await c.getInterfaces() // → string[]
|
|
202
|
+
await c.getIPs(iface, "inet") // → string[] (IPv4)
|
|
203
|
+
await c.getIPs(iface, "inet6", scope) // → string[] (IPv6)
|
|
204
|
+
await c.attachInterface(dev, dst_dev?)
|
|
205
|
+
await c.detachInterface(dev, dst_dev?)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Devices and cgroups
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
await c.addDeviceNode(src_path, dest_path?)
|
|
212
|
+
await c.removeDeviceNode(src_path, dest_path?)
|
|
213
|
+
c.getCGroupItem(subsys) // → string | undefined
|
|
214
|
+
c.setCGroupItem(subsys, value)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Snapshots
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
await c.snapshot(commentfile) // → number (snap index)
|
|
221
|
+
await c.snapshotList() // → lxc_snapshot[]
|
|
222
|
+
await c.snapshotRestore(snapname, newname?)
|
|
223
|
+
await c.snapshotDestroy(snapname)
|
|
224
|
+
await c.snapshotDestroy(true) // destroy all
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Mount injection (running container)
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
await c.mount(source, target, filesystemtype, mountflags, mnt)
|
|
231
|
+
await c.umount(source, mountflags, mnt)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### CRIU checkpoint / restore / migrate
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
await c.checkpoint(directory, stop?, verbose?)
|
|
238
|
+
await c.restore(directory, verbose?)
|
|
239
|
+
await c.migrate(cmd: LXC_MIGRATE, options?)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Seccomp
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
await c.seccompNotifyFd() // → number
|
|
246
|
+
await c.seccompNotifyFdActive() // → number
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Console ring buffer
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
await c.consoleLog({ clear?, read?, read_max? }) // → string
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Examples
|
|
256
|
+
|
|
257
|
+
The `examples/` directory contains runnable scripts for common use cases:
|
|
258
|
+
|
|
259
|
+
| Script | Description |
|
|
260
|
+
|---|---|
|
|
261
|
+
| `examples/create/` | Create a container from a template |
|
|
262
|
+
| `examples/start/` | Start a container |
|
|
263
|
+
| `examples/execute/` | Run a command in a container |
|
|
264
|
+
| `examples/attach/` | Open a shell in a container |
|
|
265
|
+
| `examples/console_async/` | Non-blocking console session |
|
|
266
|
+
| `examples/clone/` | Clone a container |
|
|
267
|
+
| `examples/checkpoint/` | CRIU checkpoint/restore |
|
|
268
|
+
| `examples/concurrent_create/` | Concurrent container creation |
|
|
269
|
+
| `examples/stats/` | Read cgroup resource metrics |
|
|
270
|
+
| `examples/images/` | Browse available LXC images |
|
|
271
|
+
|
|
272
|
+
Run any example with ts-node:
|
|
273
|
+
|
|
274
|
+
```sh
|
|
275
|
+
npm run example:create
|
|
276
|
+
npm run example:execute
|
|
277
|
+
npm run example:console_async
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Building from Source
|
|
281
|
+
|
|
282
|
+
```sh
|
|
283
|
+
# Install system dependencies (Debian/Ubuntu)
|
|
284
|
+
sudo apt install g++ lxc lxc-dev
|
|
285
|
+
|
|
286
|
+
# Install npm dependencies
|
|
287
|
+
npm install
|
|
288
|
+
|
|
289
|
+
# Configure and build the native addon
|
|
290
|
+
node-gyp configure
|
|
291
|
+
node-gyp build
|
|
292
|
+
|
|
293
|
+
# Compile TypeScript
|
|
294
|
+
npx tsc --build
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Testing
|
|
298
|
+
|
|
299
|
+
```sh
|
|
300
|
+
npm test
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The test suite uses Node.js's built-in `node:test` runner. Tests that require root access (container create/start/stop/destroy) are automatically skipped unless the process is running as root.
|
|
304
|
+
|
|
305
|
+
To run the full integration test suite:
|
|
306
|
+
|
|
307
|
+
```sh
|
|
308
|
+
sudo npm test
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Contributing
|
|
312
|
+
|
|
313
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/SourceRegistry/node-lxc).
|
|
314
|
+
|
|
315
|
+
Please ensure:
|
|
316
|
+
- New C++ code uses `std::unique_ptr<char[]>` for heap buffers
|
|
317
|
+
- Async lambda captures use by-value (`[this, var]` not `[this, &var]`)
|
|
318
|
+
- All public API changes include TypeScript type updates and JSDoc
|
|
319
|
+
|
|
320
|
+
## License
|
|
321
|
+
|
|
322
|
+
[Apache 2.0](LICENSE) © 2026 [ProjectSource V.O.F.](https://projectsource.nl)
|
|
323
|
+
|
|
324
|
+
## See Also
|
|
325
|
+
|
|
326
|
+
- [LXC API documentation](https://linuxcontainers.org/lxc/apidoc/structlxc__container.html)
|
|
327
|
+
- [LXC C header (GitHub)](https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h)
|
|
328
|
+
- [Linux Containers](https://linuxcontainers.org)
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
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);
|
|
@@ -0,0 +1,34 @@
|
|
|
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);
|
|
@@ -0,0 +1,34 @@
|
|
|
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);
|
|
@@ -0,0 +1,34 @@
|
|
|
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);
|