ramm 0.0.40 → 0.0.41
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/dist/ramm.js +35 -35
- package/dist/types/ramm.d.ts +1 -1
- package/dist/types/systemd.d.ts +8 -6
- package/package.json +4 -1
- package/dist/types/base.d.ts +0 -18
- package/dist/types/debug.d.ts +0 -4
package/dist/ramm.js
CHANGED
|
@@ -218,45 +218,41 @@ var writeFileFull = async (pathToFile, str) => {
|
|
|
218
218
|
|
|
219
219
|
// src/systemd.ts
|
|
220
220
|
var systemctlWordLangth = "systemctl ".length;
|
|
221
|
-
var formatUserspace = (
|
|
221
|
+
var formatUserspace = (command, context = defaultContext) => {
|
|
222
222
|
const userPart = context.userspace ? " --user " : "";
|
|
223
223
|
return "systemctl" + userPart + " " + command.slice(systemctlWordLangth);
|
|
224
224
|
};
|
|
225
|
-
var
|
|
226
|
-
|
|
225
|
+
var startSystemdUnit = async (unitName, context = defaultContext) => {
|
|
226
|
+
await execCommand(formatUserspace(`systemctl start ${unitName}`, context));
|
|
227
227
|
};
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
return `~/.config/systemd/user/${serviceName}`;
|
|
231
|
-
}
|
|
232
|
-
return `/etc/systemd/system/${serviceName}`;
|
|
228
|
+
var enabledSystemdUnit = async (unitName, context = defaultContext) => {
|
|
229
|
+
await execCommand(formatUserspace(`systemctl enable ${unitName}`, context));
|
|
233
230
|
};
|
|
234
|
-
var
|
|
235
|
-
await execCommand(formatUserspace(
|
|
231
|
+
var restartSystemdUnit = async (name, context = defaultContext) => {
|
|
232
|
+
await execCommand(formatUserspace(`systemctl restart ${name}`, context));
|
|
236
233
|
};
|
|
237
|
-
var
|
|
238
|
-
|
|
239
|
-
await execCommand(formatUserspace(constext, `systemctl restart ${name}`));
|
|
234
|
+
var stopSystemdUnit = async (name, context = defaultContext) => {
|
|
235
|
+
await execCommand(formatUserspace(`systemctl stop ${name}`, context));
|
|
240
236
|
};
|
|
241
|
-
var
|
|
242
|
-
const { spawnResult } = await execCommandMayError(formatUserspace(
|
|
237
|
+
var checkSystemdUnit = async (serviceName, context = defaultContext) => {
|
|
238
|
+
const { spawnResult } = await execCommandMayError(formatUserspace(`systemctl is-active ${serviceName}`, context));
|
|
243
239
|
return spawnResult.exitCode === 0;
|
|
244
240
|
};
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
const pathToSeviceTarget = getSystemdPathToService(context, serviceName);
|
|
241
|
+
var createSystemdUnit = async (unitName, content, context = defaultContext) => {
|
|
242
|
+
const pathToSeviceTarget = getSystemdPathToService(unitName, context);
|
|
248
243
|
await writeFileFull(pathToSeviceTarget, content);
|
|
249
|
-
await execCommand(formatUserspace(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
await
|
|
259
|
-
await
|
|
244
|
+
await execCommand(formatUserspace(`systemctl daemon-reload ${unitName}`, context));
|
|
245
|
+
};
|
|
246
|
+
var getSystemdPathToService = (serviceName, context = defaultContext) => {
|
|
247
|
+
if (context.userspace) {
|
|
248
|
+
return `~/.config/systemd/user/${serviceName}`;
|
|
249
|
+
}
|
|
250
|
+
return `/etc/systemd/system/${serviceName}`;
|
|
251
|
+
};
|
|
252
|
+
var createSystemdService = async (serviceName, content, context = defaultContext) => {
|
|
253
|
+
await createSystemdUnit(serviceName, content, context);
|
|
254
|
+
await enabledSystemdUnit(`systemctl enable ${serviceName}`, context);
|
|
255
|
+
await startSystemdUnit(`systemctl start ${serviceName}`, context);
|
|
260
256
|
};
|
|
261
257
|
|
|
262
258
|
// src/nft.ts
|
|
@@ -350,13 +346,13 @@ var runPodmanContainer = async (name, command) => {
|
|
|
350
346
|
console.info("Podman container is already running");
|
|
351
347
|
};
|
|
352
348
|
var runPodmanContainerService = async (name, command, context = defaultContext) => {
|
|
353
|
-
const serviceName =
|
|
354
|
-
if (await
|
|
355
|
-
await
|
|
349
|
+
const serviceName = `${name}.service`;
|
|
350
|
+
if (await checkSystemdUnit(serviceName, context)) {
|
|
351
|
+
await stopSystemdUnit(serviceName, context);
|
|
356
352
|
}
|
|
357
353
|
await runPodmanContainer(name, command);
|
|
358
354
|
await execCommand(`podman generate systemd --name --new ${name} > ${serviceName}`);
|
|
359
|
-
await createSystemdService(
|
|
355
|
+
await createSystemdService(serviceName, serviceName, context);
|
|
360
356
|
};
|
|
361
357
|
var addNftPodmanRule = async () => {
|
|
362
358
|
const podmanNetworksResult = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
@@ -489,11 +485,12 @@ export {
|
|
|
489
485
|
writeIfNewStr,
|
|
490
486
|
writeFileFull,
|
|
491
487
|
writeFile,
|
|
488
|
+
startSystemdUnit,
|
|
492
489
|
setupNftable,
|
|
493
490
|
saveSshFingerptint,
|
|
494
491
|
runPodmanContainerService,
|
|
495
492
|
runPodmanContainer,
|
|
496
|
-
|
|
493
|
+
restartSystemdUnit,
|
|
497
494
|
printBlock,
|
|
498
495
|
passVarsServer,
|
|
499
496
|
passVarsClient,
|
|
@@ -503,12 +500,15 @@ export {
|
|
|
503
500
|
installSystemPackage,
|
|
504
501
|
installPodman,
|
|
505
502
|
installBun,
|
|
503
|
+
getSystemdPathToService,
|
|
506
504
|
getServerFingerprint,
|
|
507
505
|
execCommandRaw,
|
|
508
506
|
execCommandOverSsh,
|
|
509
507
|
execCommandMayError,
|
|
510
508
|
execCommand,
|
|
511
|
-
|
|
509
|
+
enabledSystemdUnit,
|
|
510
|
+
createSystemdUnit,
|
|
511
|
+
createSystemdService,
|
|
512
512
|
createCron,
|
|
513
513
|
createAndAddSshKey,
|
|
514
514
|
copyFilesBySsh,
|
package/dist/types/ramm.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Context } from "./context.ts";
|
|
|
3
3
|
export { installBun } from "./init.ts";
|
|
4
4
|
export { installPodman, runPodmanContainer, loginPodman } from "./podman.ts";
|
|
5
5
|
export { runPodmanContainerService, addNftPodmanRule } from "./podman.ts";
|
|
6
|
-
export {
|
|
6
|
+
export { startSystemdUnit, enabledSystemdUnit, restartSystemdUnit, createSystemdService, getSystemdPathToService, createSystemdUnit, } from "./systemd.ts";
|
|
7
7
|
export { installSystemPackage } from "./packages.ts";
|
|
8
8
|
export { printBlock } from "./print.ts";
|
|
9
9
|
export { setupNftable } from "./nft.ts";
|
package/dist/types/systemd.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Context } from "./context.ts";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
2
|
+
export declare const startSystemdUnit: (unitName: string, context?: Context) => Promise<void>;
|
|
3
|
+
export declare const enabledSystemdUnit: (unitName: string, context?: Context) => Promise<void>;
|
|
4
|
+
export declare const restartSystemdUnit: (name: string, context?: Context) => Promise<void>;
|
|
5
|
+
export declare const stopSystemdUnit: (name: string, context?: Context) => Promise<void>;
|
|
6
|
+
export declare const checkSystemdUnit: (serviceName: string, context?: Context) => Promise<boolean>;
|
|
7
|
+
export declare const createSystemdUnit: (unitName: string, content: string, context?: Context) => Promise<void>;
|
|
8
|
+
export declare const getSystemdPathToService: (serviceName: string, context?: Context) => string;
|
|
9
|
+
export declare const createSystemdService: (serviceName: string, content: string, context?: Context) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ramm",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.41",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh",
|
|
7
7
|
"types": "tsc --project tsconfig.types.json"
|
|
@@ -18,5 +18,8 @@
|
|
|
18
18
|
"@types/bun": "latest",
|
|
19
19
|
"typescript": "^5.8.2",
|
|
20
20
|
"dapes": "^0.0.26"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"vitest": "^3.2.4"
|
|
21
24
|
}
|
|
22
25
|
}
|
package/dist/types/base.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Context } from "./context.ts";
|
|
2
|
-
export declare const defaultContext: Context;
|
|
3
|
-
export declare const teeErr: (read: ReadableStream) => Promise<string>;
|
|
4
|
-
export declare const execCommand: (command: string) => Promise<{
|
|
5
|
-
outputErr: string;
|
|
6
|
-
output: string;
|
|
7
|
-
spawnResult: import("bun").Subprocess<"inherit", "pipe", "pipe">;
|
|
8
|
-
}>;
|
|
9
|
-
export declare const execCommandSilent: (command: string) => Promise<{
|
|
10
|
-
output: string;
|
|
11
|
-
spawnResult: import("bun").Subprocess<"ignore", "pipe", "inherit">;
|
|
12
|
-
}>;
|
|
13
|
-
export declare const copyFilesBySsh: (from: string, to: string, context: Context) => Promise<void>;
|
|
14
|
-
export declare const execBySsh: (command: string, context: Context) => Promise<{
|
|
15
|
-
outputErr: string;
|
|
16
|
-
output: string;
|
|
17
|
-
spawnResult: import("bun").Subprocess<"inherit", "pipe", "pipe">;
|
|
18
|
-
}>;
|
package/dist/types/debug.d.ts
DELETED