0xMax42 f4c7b2e18f
All checks were successful
Auto Changelog & Release / detect-version-change (push) Successful in 2s
CI / build (push) Successful in 6s
Auto Changelog & Release / release (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Successful in 5s
chore(pr): add rollback tests and update test descriptions #3
- Add tests for rollback behavior in `writeUnitFiles` on errors
- Simulate file write and delete failures in test scenarios
- Log rollback failures when file deletion is not possible
- Update all test descriptions and comments to English
- Add `testing/mock.ts` dependency in `deno.lock`

This change adds comprehensive tests for the `writeUnitFiles` function to verify that files are properly rolled back if errors occur during their creation. The tests simulate failures when writing `.service` or `.timer` files, as well as when file deletion is blocked, and check that the function responds by cleaning up as expected or logging rollback failures. All test comments and descriptions have been updated to English for clarity. The `testing/mock.ts` dependency was added to enable function stubbing in tests.

#2

Merged from test/fail-write-and-rollback into main
2025-05-30 11:21:41 +02:00
2025-05-21 03:09:40 +02:00
2025-05-28 18:34:09 +02:00

systemd-timer

A simple CLI tool for quickly generating systemd .service and .timer units — as a replacement or modern supplement to classic cron jobs.


🚀 Features

  • Generates .service and .timer files via CLI
  • Supports --user timers (for ~/.config/systemd/user/)
  • Optional logging (StandardOutput/StandardError)
  • Supports:
    • --calendar: Timer schedule (systemd OnCalendar)
    • --exec: Command to execute (ExecStart)
    • --description: Description for the unit
    • --after: After= dependencies in the service unit
    • --environment: Arbitrary Environment=KEY=VALUE entries
    • --output: Target directory for the generated unit files
    • --run-as: Sets User= in the service unit (only for system-level timers)
    • --home: Sets Environment=HOME=…
    • --cwd: Working directory for the process (WorkingDirectory)
    • --dry-run: Outputs unit content without writing to disk
  • Tested and fully typed with Deno + Cliffy

🛠️ Installation

You can install systemd-timer directly via shell script:

curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh | sh

The script automatically detects your platform (Linux amd64 or arm64) and installs the appropriate binary to /usr/local/bin, if permitted (possibly using sudo).

Note:

  • A working internet connection is required for installation.
  • The integrity of the binary is verified using a SHA256 checksum.
  • You can manually inspect the script before execution:
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh -o install.sh
less install.sh

Additional options and manual installation methods are available under scripts/install.sh.


📦 Example

./systemd-timer create \
  --exec "/usr/local/bin/backup.sh" \
  --calendar "Mon..Fri 02:00" \
  --description "Backup Job" \
  --user \
  --logfile "/var/log/backup.log"

This creates:

  • ~/.config/systemd/user/backup.service
  • ~/.config/systemd/user/backup.timer

Activate afterwards:

systemctl --user daemon-reload
systemctl --user enable --now backup.timer

🧪 Running Tests

deno task test

🧰 Development

deno task start create --exec "/bin/true" --calendar "daily" --dry-run

🔒 Permissions / Flags

The tool requires the following permissions when running or compiling:

  • --allow-env (for $HOME)
  • --allow-write (to write .service/.timer files)

During development, usually -A (allow all) is used.


📝 License

MIT License

Description
A simple CLI tool for quickly generating systemd .service and .timer units — as a replacement or modern supplement to classic cron jobs.
Readme MIT 221 KiB
2025-06-15 16:52:14 +02:00
Languages
TypeScript 86%
Shell 14%