Compare commits
4 Commits
v0.1.0
...
1a1ad66ab6
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a1ad66ab6 | |||
|
bd71b8ee14
|
|||
| a76417ce1d | |||
|
a288dbc140
|
10
CHANGELOG.md
10
CHANGELOG.md
@@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [unreleased]
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
- *(utils)* Handle file write failures with rollback - ([bd71b8e](https://git.0xmax42.io/maxp/systemd-timer/commit/bd71b8ee14a1856f1adaaaea198c8467b1a00d24))
|
||||||
|
|
||||||
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- *(readme)* Add project time badge - ([a288dbc](https://git.0xmax42.io/maxp/systemd-timer/commit/a288dbc140fefbc46745f70cdcd71148802fdabf))
|
||||||
|
|
||||||
## [0.1.0] - 2025-05-21
|
## [0.1.0] - 2025-05-21
|
||||||
|
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# systemd-timer
|
# systemd-timer
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Ein einfaches CLI-Tool zum schnellen Erzeugen von systemd `.service` und `.timer` Units – als Ersatz oder moderne Ergänzung zu klassischen `cron`-Jobs.
|
Ein einfaches CLI-Tool zum schnellen Erzeugen von systemd `.service` und `.timer` Units – als Ersatz oder moderne Ergänzung zu klassischen `cron`-Jobs.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -12,14 +12,20 @@ export async function generateUnitFiles(options: TimerOptions): Promise<void> {
|
|||||||
console.log(`\n===== ${name}.timer =====`);
|
console.log(`\n===== ${name}.timer =====`);
|
||||||
console.log(timerUnit);
|
console.log(timerUnit);
|
||||||
} else {
|
} else {
|
||||||
const { servicePath, timerPath } = await writeUnitFiles(
|
const result = await writeUnitFiles(
|
||||||
name,
|
name,
|
||||||
serviceUnit,
|
serviceUnit,
|
||||||
timerUnit,
|
timerUnit,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
console.log(`Service unit written to: ${servicePath}`);
|
|
||||||
console.log(`Timer unit written to: ${timerPath}`);
|
if (result) {
|
||||||
|
const { servicePath, timerPath } = result;
|
||||||
|
console.log(`Service Unit geschrieben in: ${servicePath}`);
|
||||||
|
console.log(`Timer Unit geschrieben in: ${timerPath}`);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`\nℹ️ Hinweis:`);
|
console.log(`\nℹ️ Hinweis:`);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Deno.test('writeUnitFiles schreibt .service und .timer korrekt', async () => {
|
|||||||
serviceContent,
|
serviceContent,
|
||||||
timerContent,
|
timerContent,
|
||||||
options as TimerOptions,
|
options as TimerOptions,
|
||||||
);
|
) as { servicePath: string; timerPath: string };
|
||||||
|
|
||||||
// Überprüfe Pfade
|
// Überprüfe Pfade
|
||||||
assertEquals(servicePath, join(tmp, 'test-backup.service'));
|
assertEquals(servicePath, join(tmp, 'test-backup.service'));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ensureDir } from 'https://deno.land/std@0.224.0/fs/mod.ts';
|
import { ensureDir, exists } from 'https://deno.land/std@0.224.0/fs/mod.ts';
|
||||||
import { join } from 'https://deno.land/std@0.224.0/path/mod.ts';
|
import { join } from 'https://deno.land/std@0.224.0/path/mod.ts';
|
||||||
import { TimerOptions } from '../types/mod.ts';
|
import { TimerOptions } from '../types/mod.ts';
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ export async function writeUnitFiles(
|
|||||||
serviceContent: string,
|
serviceContent: string,
|
||||||
timerContent: string,
|
timerContent: string,
|
||||||
options: TimerOptions,
|
options: TimerOptions,
|
||||||
): Promise<{ servicePath: string; timerPath: string }> {
|
): Promise<{ servicePath: string; timerPath: string } | undefined> {
|
||||||
const basePath = resolveUnitTargetPath(options);
|
const basePath = resolveUnitTargetPath(options);
|
||||||
|
|
||||||
await ensureDir(basePath);
|
await ensureDir(basePath);
|
||||||
@@ -15,8 +15,24 @@ export async function writeUnitFiles(
|
|||||||
const servicePath = join(basePath, `${name}.service`);
|
const servicePath = join(basePath, `${name}.service`);
|
||||||
const timerPath = join(basePath, `${name}.timer`);
|
const timerPath = join(basePath, `${name}.timer`);
|
||||||
|
|
||||||
await Deno.writeTextFile(servicePath, serviceContent);
|
try {
|
||||||
await Deno.writeTextFile(timerPath, timerContent);
|
await Deno.writeTextFile(servicePath, serviceContent);
|
||||||
|
await Deno.writeTextFile(timerPath, timerContent);
|
||||||
|
} catch (error) {
|
||||||
|
// Rollback: Remove any files that were written
|
||||||
|
try {
|
||||||
|
if (await exists(servicePath)) {
|
||||||
|
await Deno.remove(servicePath);
|
||||||
|
}
|
||||||
|
if (await exists(timerPath)) {
|
||||||
|
await Deno.remove(timerPath);
|
||||||
|
}
|
||||||
|
} catch (rollbackError) {
|
||||||
|
console.error('Rollback fehlgeschlagen:', rollbackError);
|
||||||
|
}
|
||||||
|
console.error('Fehler beim Schreiben der Units:', error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return { servicePath, timerPath };
|
return { servicePath, timerPath };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user