Skip to content

Commit db94503

Browse files
committed
add lxc init options
1 parent 5f2a6dd commit db94503

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

runners/lxc/lxc-dispose.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
runners=$1
2+
3+
for i in {1..$runners}; do
4+
userdel runner$i
5+
done

runners/lxc/lxc-init.bash

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
for i in {1..150}; do
1+
runners=$1
2+
nproc=$2
3+
nofile=$3
4+
5+
for i in {1..$runners}; do
26
useradd -M runner$i
37
usermod -d /tmp runner$i
4-
echo "runner$i soft nproc 64" >> /etc/security/limits.conf
5-
echo "runner$i hard nproc 64" >> /etc/security/limits.conf
6-
echo "runner$i soft nofile 2048" >> /etc/security/limits.conf
7-
echo "runner$i hard nofile 2048" >> /etc/security/limits.conf
8+
echo "runner$i soft nproc $nproc" >> /etc/security/limits.conf
9+
echo "runner$i hard nproc $nproc" >> /etc/security/limits.conf
10+
echo "runner$i soft nofile $nofile" >> /etc/security/limits.conf
11+
echo "runner$i hard nofile $nofile" >> /etc/security/limits.conf
812
done

src/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ export interface IExecuteOptions {
2323
}
2424

2525
export const defaultExecutionTimeout = 5;
26+
27+
export interface ILxcInitOptions {
28+
runners?: number;
29+
maxProcesses?: number;
30+
maxFiles?: number;
31+
}
32+
33+
export const defaultLxcInitOptions: ILxcInitOptions = {
34+
runners: 100,
35+
maxProcesses: 64,
36+
maxFiles: 2048,
37+
};

src/lxc.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"use strict";
22

33
import { exec } from "child_process";
4-
import { mkdirSync, writeFileSync, readFileSync, chmodSync } from "fs";
4+
import { mkdirSync, writeFileSync, readFileSync } from "fs";
55
import { platform } from "os";
66
import {
77
defaultExecutionTimeout,
8+
defaultLxcInitOptions,
89
IExecuteOptions,
10+
ILxcInitOptions,
911
Language,
1012
} from "./constants";
1113

@@ -37,9 +39,12 @@ class LXC {
3739
}
3840

3941
/**
40-
* Run this function the first time, after installing the container
42+
* Run this function the first time, after installing the container. Please be patient, this could take a while
43+
*
44+
* @param options Pass options for the initialization to the function.
45+
* @returns
4146
*/
42-
init() {
47+
init(options: ILxcInitOptions = defaultLxcInitOptions) {
4348
try {
4449
// Copy .sh file to correct location
4550
const shFile = readFileSync(
@@ -55,7 +60,11 @@ class LXC {
5560

5661
return new Promise<string>((resolve, reject) => {
5762
exec(
58-
`lxc-attach --clear-env -n cee -- bash /tmp/lxc-init.bash`,
63+
`lxc-attach --clear-env -n cee -- bash /tmp/lxc-init.bash ${
64+
options.runners || defaultLxcInitOptions.runners
65+
} ${options.maxProcesses || defaultLxcInitOptions.maxProcesses} ${
66+
options.maxFiles || defaultLxcInitOptions.maxFiles
67+
}`,
5968
(err, stdout, stderr) => {
6069
if (err) return reject(err);
6170
if (stderr) return reject(stderr);

0 commit comments

Comments
 (0)