Archived
Compare commits
23
Commits
v0.1.2-rc2
...
v0.1.3
No files matched your search
@@ -46,29 +46,6 @@ jobs:
|
|||||||
name: spotbugs-report
|
name: spotbugs-report
|
||||||
path: target/spotbugsXml.xml
|
path: target/spotbugsXml.xml
|
||||||
|
|
||||||
pmd:
|
|
||||||
name: PMD
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: '21'
|
|
||||||
distribution: 'temurin'
|
|
||||||
cache: maven
|
|
||||||
|
|
||||||
- name: Run PMD
|
|
||||||
run: mvn compile pmd:check
|
|
||||||
|
|
||||||
- name: Upload PMD Report
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
if: failure()
|
|
||||||
with:
|
|
||||||
name: pmd-report
|
|
||||||
path: target/pmd.xml
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Tests
|
name: Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -91,12 +68,9 @@ jobs:
|
|||||||
name: coverage-report
|
name: coverage-report
|
||||||
path: target/site/jacoco/
|
path: target/site/jacoco/
|
||||||
|
|
||||||
- name: Check Coverage Thresholds
|
|
||||||
run: mvn jacoco:check
|
|
||||||
|
|
||||||
verify:
|
verify:
|
||||||
name: Full Verification
|
name: Full Verification
|
||||||
needs: [checkstyle, spotbugs, pmd, test]
|
needs: [checkstyle, spotbugs, test]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ jobs:
|
|||||||
artifact: barn-linux-arm64
|
artifact: barn-linux-arm64
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
artifact: barn-macos-arm64
|
artifact: barn-macos-arm64
|
||||||
|
- os: macos-13
|
||||||
|
artifact: barn-macos-x64
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
artifact: barn-windows-x64
|
artifact: barn-windows-x64
|
||||||
|
|
||||||
@@ -48,12 +50,28 @@ jobs:
|
|||||||
Move-Item -Path "target\barn.exe" -Destination "target\${{ matrix.artifact }}.exe" -Force
|
Move-Item -Path "target\barn.exe" -Destination "target\${{ matrix.artifact }}.exe" -Force
|
||||||
Get-ChildItem target\*.exe
|
Get-ChildItem target\*.exe
|
||||||
|
|
||||||
|
- name: Build Windows installer
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$version = "${{ github.ref_name }}" -replace '^v', ''
|
||||||
|
choco install innosetup -y
|
||||||
|
iscc /DAppVersion=$version installer\barn.iss
|
||||||
|
Get-ChildItem dist\*.exe
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.artifact }}
|
name: ${{ matrix.artifact }}
|
||||||
path: target/${{ matrix.artifact }}*
|
path: target/${{ matrix.artifact }}*
|
||||||
|
|
||||||
|
- name: Upload Windows installer
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: windows-installer
|
||||||
|
path: dist/*.exe
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: build-native
|
needs: build-native
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -69,6 +87,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir release
|
mkdir release
|
||||||
find artifacts -type f -exec mv {} release/ \;
|
find artifacts -type f -exec mv {} release/ \;
|
||||||
|
# Add installer scripts
|
||||||
|
cp install.sh release/
|
||||||
|
cp install.ps1 release/
|
||||||
cd release
|
cd release
|
||||||
sha256sum * > SHA256SUMS
|
sha256sum * > SHA256SUMS
|
||||||
ls -la
|
ls -la
|
||||||
|
|||||||
@@ -16,12 +16,17 @@ jobs:
|
|||||||
|
|
||||||
# Get checksums from release
|
# Get checksums from release
|
||||||
curl -sL "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/SHA256SUMS" -o SHA256SUMS
|
curl -sL "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/SHA256SUMS" -o SHA256SUMS
|
||||||
|
cat SHA256SUMS
|
||||||
|
|
||||||
MACOS_ARM64_SHA=$(grep barn-macos-arm64 SHA256SUMS | awk '{print $1}')
|
MACOS_ARM64_SHA=$(grep barn-macos-arm64 SHA256SUMS | awk '{print $1}')
|
||||||
MACOS_X64_SHA=$(grep barn-macos-x64 SHA256SUMS | awk '{print $1}')
|
MACOS_X64_SHA=$(grep barn-macos-x64 SHA256SUMS | awk '{print $1}')
|
||||||
|
LINUX_ARM64_SHA=$(grep barn-linux-arm64 SHA256SUMS | awk '{print $1}')
|
||||||
|
LINUX_X64_SHA=$(grep barn-linux-x64 SHA256SUMS | awk '{print $1}')
|
||||||
|
|
||||||
echo "macos_arm64_sha=$MACOS_ARM64_SHA" >> $GITHUB_OUTPUT
|
echo "macos_arm64_sha=$MACOS_ARM64_SHA" >> $GITHUB_OUTPUT
|
||||||
echo "macos_x64_sha=$MACOS_X64_SHA" >> $GITHUB_OUTPUT
|
echo "macos_x64_sha=$MACOS_X64_SHA" >> $GITHUB_OUTPUT
|
||||||
|
echo "linux_arm64_sha=$LINUX_ARM64_SHA" >> $GITHUB_OUTPUT
|
||||||
|
echo "linux_x64_sha=$LINUX_X64_SHA" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Checkout homebrew tap
|
- name: Checkout homebrew tap
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -31,18 +36,24 @@ jobs:
|
|||||||
path: homebrew-tap
|
path: homebrew-tap
|
||||||
|
|
||||||
- name: Update formula
|
- name: Update formula
|
||||||
|
env:
|
||||||
|
VERSION: ${{ steps.release.outputs.version }}
|
||||||
|
MACOS_ARM64_SHA: ${{ steps.release.outputs.macos_arm64_sha }}
|
||||||
|
MACOS_X64_SHA: ${{ steps.release.outputs.macos_x64_sha }}
|
||||||
|
LINUX_ARM64_SHA: ${{ steps.release.outputs.linux_arm64_sha }}
|
||||||
|
LINUX_X64_SHA: ${{ steps.release.outputs.linux_x64_sha }}
|
||||||
run: |
|
run: |
|
||||||
cat > homebrew-tap/Formula/barn.rb << 'EOF'
|
cat > homebrew-tap/Formula/barn.rb << EOF
|
||||||
class Barn < Formula
|
class Barn < Formula
|
||||||
desc "Cross-platform job daemon for media processing"
|
desc "Cross-platform job daemon for media processing"
|
||||||
homepage "https://github.com/samson-media/barn"
|
homepage "https://github.com/samson-media/barn"
|
||||||
version "${{ steps.release.outputs.version }}"
|
version "${VERSION}"
|
||||||
license "MIT"
|
license "MIT"
|
||||||
|
|
||||||
on_macos do
|
on_macos do
|
||||||
on_arm do
|
on_arm do
|
||||||
url "https://github.com/samson-media/barn/releases/download/v${{ steps.release.outputs.version }}/barn-macos-arm64"
|
url "https://github.com/samson-media/barn/releases/download/v${VERSION}/barn-macos-arm64"
|
||||||
sha256 "${{ steps.release.outputs.macos_arm64_sha }}"
|
sha256 "${MACOS_ARM64_SHA}"
|
||||||
|
|
||||||
def install
|
def install
|
||||||
bin.install "barn-macos-arm64" => "barn"
|
bin.install "barn-macos-arm64" => "barn"
|
||||||
@@ -50,8 +61,8 @@ jobs:
|
|||||||
end
|
end
|
||||||
|
|
||||||
on_intel do
|
on_intel do
|
||||||
url "https://github.com/samson-media/barn/releases/download/v${{ steps.release.outputs.version }}/barn-macos-x64"
|
url "https://github.com/samson-media/barn/releases/download/v${VERSION}/barn-macos-x64"
|
||||||
sha256 "${{ steps.release.outputs.macos_x64_sha }}"
|
sha256 "${MACOS_X64_SHA}"
|
||||||
|
|
||||||
def install
|
def install
|
||||||
bin.install "barn-macos-x64" => "barn"
|
bin.install "barn-macos-x64" => "barn"
|
||||||
@@ -59,11 +70,24 @@ jobs:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
service do
|
on_linux do
|
||||||
run [opt_bin/"barn", "service", "run"]
|
on_arm do
|
||||||
keep_alive true
|
url "https://github.com/samson-media/barn/releases/download/v${VERSION}/barn-linux-arm64"
|
||||||
log_path var/"log/barn.log"
|
sha256 "${LINUX_ARM64_SHA}"
|
||||||
error_log_path var/"log/barn.error.log"
|
|
||||||
|
def install
|
||||||
|
bin.install "barn-linux-arm64" => "barn"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on_intel do
|
||||||
|
url "https://github.com/samson-media/barn/releases/download/v${VERSION}/barn-linux-x64"
|
||||||
|
sha256 "${LINUX_X64_SHA}"
|
||||||
|
|
||||||
|
def install
|
||||||
|
bin.install "barn-linux-x64" => "barn"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test do
|
test do
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/).
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
|
## [0.1.3] - 2026-01-22
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Debug logs no longer break JSON/XML CLI output (#30)
|
||||||
|
- Replace SLF4J/logback with custom BarnLogger (disabled for CLI, enabled for service)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Update documentation: remove .deb and AUR references (no longer applicable)
|
||||||
|
- Update documentation: add Windows setup.exe installation instructions
|
||||||
|
- Update documentation: clarify auto-update only works with Homebrew
|
||||||
|
|
||||||
## [0.1.2] - 2026-01-21
|
## [0.1.2] - 2026-01-21
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -32,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|||||||
- Jobs that fail to start now properly transition to FAILED state
|
- Jobs that fail to start now properly transition to FAILED state
|
||||||
- Startup errors are written to stderr.log for visibility
|
- Startup errors are written to stderr.log for visibility
|
||||||
|
|
||||||
|
[0.1.3]: https://github.com/samson-media/barn/releases/tag/v0.1.3
|
||||||
[0.1.2]: https://github.com/samson-media/barn/releases/tag/v0.1.2
|
[0.1.2]: https://github.com/samson-media/barn/releases/tag/v0.1.2
|
||||||
[0.1.1]: https://github.com/samson-media/barn/releases/tag/v0.1.1
|
[0.1.1]: https://github.com/samson-media/barn/releases/tag/v0.1.1
|
||||||
[0.1.0]: https://github.com/samson-media/barn/releases/tag/v0.1.0
|
[0.1.0]: https://github.com/samson-media/barn/releases/tag/v0.1.0
|
||||||
@@ -610,6 +610,174 @@ mvn compile spotbugs:gui
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Pre-Release Testing Checklist (MANDATORY)
|
||||||
|
|
||||||
|
Before creating ANY release tag, you MUST test ALL subcommands with the native binary locally.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
1. **Build the native image locally:**
|
||||||
|
```bash
|
||||||
|
export JAVA_HOME="/Library/Java/JavaVirtualMachines/graalvm-25.jdk/Contents/Home"
|
||||||
|
mvn package -Pnative -DskipTests -Dspotbugs.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true -Djacoco.skip=true
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Verify the binary exists:**
|
||||||
|
```bash
|
||||||
|
ls -la target/barn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Every Subcommand
|
||||||
|
|
||||||
|
Run each command and verify the expected output. **Do NOT skip any command.**
|
||||||
|
|
||||||
|
#### Basic Commands
|
||||||
|
```bash
|
||||||
|
# Should show usage/help
|
||||||
|
./target/barn
|
||||||
|
# Expected: Shows "Usage: barn [-hV] [COMMAND]" and lists all subcommands
|
||||||
|
|
||||||
|
./target/barn --help
|
||||||
|
# Expected: Same as above
|
||||||
|
|
||||||
|
./target/barn --version
|
||||||
|
# Expected: Shows "barn X.Y.Z"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Service Commands (Start service first)
|
||||||
|
```bash
|
||||||
|
# Stop any existing service
|
||||||
|
./target/barn service stop 2>/dev/null || true
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
./target/barn service start
|
||||||
|
# Expected: "Barn service started (PID: XXXXX)"
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
./target/barn service status
|
||||||
|
# Expected: Shows "Status: running", PID, uptime, job counts
|
||||||
|
|
||||||
|
# Test reload (reloads config without restart)
|
||||||
|
./target/barn service reload
|
||||||
|
# Expected: "Configuration reloaded"
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
./target/barn service logs
|
||||||
|
# Expected: Shows recent log entries or "No logs found"
|
||||||
|
|
||||||
|
# Restart the service
|
||||||
|
./target/barn service restart
|
||||||
|
# Expected: "Barn service restarted"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Job Commands (Service must be running)
|
||||||
|
```bash
|
||||||
|
# Run a test job
|
||||||
|
./target/barn run -- echo "test from native binary"
|
||||||
|
# Expected: "Job created: job-XXXXXXXX" with state: queued
|
||||||
|
|
||||||
|
# Wait a moment, then check status
|
||||||
|
sleep 2
|
||||||
|
./target/barn status
|
||||||
|
# Expected: Shows table with jobs, including the new job as "succeeded"
|
||||||
|
|
||||||
|
# Get the job ID from status output, then describe it
|
||||||
|
./target/barn describe <job-id>
|
||||||
|
# Expected: Shows detailed job info including timestamps, exit code, files
|
||||||
|
|
||||||
|
# Check resource usage
|
||||||
|
./target/barn usage <job-id>
|
||||||
|
# Expected: Shows CPU/memory/disk usage samples
|
||||||
|
|
||||||
|
# Test kill on a non-running job (should fail gracefully)
|
||||||
|
./target/barn kill <job-id>
|
||||||
|
# Expected: "Error: Job is not running: SUCCEEDED"
|
||||||
|
|
||||||
|
# Clean with dry-run
|
||||||
|
./target/barn clean --dry-run
|
||||||
|
# Expected: "Would clean X jobs:" followed by list
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Config Commands
|
||||||
|
```bash
|
||||||
|
./target/barn config show
|
||||||
|
# Expected: Shows configuration with all sections (service, jobs, cleanup, storage)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Autocompletion Commands
|
||||||
|
```bash
|
||||||
|
./target/barn autocompletion --bash | head -5
|
||||||
|
# Expected: Shows bash completion script starting with "#!/usr/bin/env bash"
|
||||||
|
|
||||||
|
./target/barn autocompletion --zsh | head -5
|
||||||
|
# Expected: Shows zsh completion script
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Service Stop (Clean up)
|
||||||
|
```bash
|
||||||
|
./target/barn service stop
|
||||||
|
# Expected: "Barn service stopped"
|
||||||
|
|
||||||
|
./target/barn service status
|
||||||
|
# Expected: "Barn service is not running"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Checklist Summary
|
||||||
|
|
||||||
|
Copy this checklist and verify each item:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
## Pre-Release Testing for vX.Y.Z
|
||||||
|
|
||||||
|
### Build
|
||||||
|
- [ ] Native image builds successfully
|
||||||
|
- [ ] Binary exists at target/barn
|
||||||
|
|
||||||
|
### Basic Commands
|
||||||
|
- [ ] `barn` shows help
|
||||||
|
- [ ] `barn --help` shows help
|
||||||
|
- [ ] `barn --version` shows correct version
|
||||||
|
|
||||||
|
### Service Commands
|
||||||
|
- [ ] `barn service start` starts the service
|
||||||
|
- [ ] `barn service status` shows running status
|
||||||
|
- [ ] `barn service reload` reloads config
|
||||||
|
- [ ] `barn service logs` shows logs
|
||||||
|
- [ ] `barn service restart` restarts cleanly
|
||||||
|
- [ ] `barn service stop` stops the service
|
||||||
|
|
||||||
|
### Job Commands (with service running)
|
||||||
|
- [ ] `barn run -- echo test` creates a job
|
||||||
|
- [ ] `barn status` shows job list
|
||||||
|
- [ ] `barn describe <id>` shows job details
|
||||||
|
- [ ] `barn usage <id>` shows resource usage
|
||||||
|
- [ ] `barn kill <id>` handles non-running job gracefully
|
||||||
|
- [ ] `barn clean --dry-run` shows what would be cleaned
|
||||||
|
|
||||||
|
### Config Commands
|
||||||
|
- [ ] `barn config show` displays configuration
|
||||||
|
|
||||||
|
### Autocompletion
|
||||||
|
- [ ] `barn autocompletion --bash` generates bash script
|
||||||
|
- [ ] `barn autocompletion --zsh` generates zsh script
|
||||||
|
|
||||||
|
### Final
|
||||||
|
- [ ] All commands return expected output
|
||||||
|
- [ ] No crashes or exceptions
|
||||||
|
- [ ] Service starts and stops cleanly
|
||||||
|
```
|
||||||
|
|
||||||
|
### Only After All Tests Pass
|
||||||
|
|
||||||
|
1. Commit any fixes
|
||||||
|
2. Push to main
|
||||||
|
3. Wait for CI to pass
|
||||||
|
4. Create the release tag: `git tag vX.Y.Z && git push origin vX.Y.Z`
|
||||||
|
|
||||||
|
**NEVER create a release tag without completing this checklist.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Questions to Ask Before Implementing
|
## Questions to Ask Before Implementing
|
||||||
|
|
||||||
1. Have I read the relevant documentation?
|
1. Have I read the relevant documentation?
|
||||||
|
|||||||
@@ -42,57 +42,99 @@ This project treats FFmpeg jobs as **first-class managed units of work**, not sh
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### macOS
|
### Quick Install (Recommended)
|
||||||
|
|
||||||
|
#### MacOS - Homebrew
|
||||||
|
|
||||||
**Homebrew (recommended):**
|
|
||||||
```bash
|
```bash
|
||||||
brew install samson-media/tap/barn
|
brew install samson-media/tap/barn
|
||||||
```
|
```
|
||||||
|
|
||||||
**Manual download:**
|
|
||||||
|
#### Linux / MacOS
|
||||||
|
|
||||||
|
The installer scripts download the latest release, install the binary, and set up barn to run as a service on startup.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/samson-media/barn/main/install.sh | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Windows Installer (setup.exe)
|
||||||
|
|
||||||
|
Download the latest `setup-barn-vX.X.X-windows-x64.exe` from the [releases page](https://github.com/samson-media/barn/releases/latest).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Alternative Installation Methods
|
||||||
|
|
||||||
|
### Windows (PowerShell as Administrator)
|
||||||
|
|
||||||
|
The installer scripts download the latest release, install the binary, and set up barn to run as a service on startup.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
iwr -useb https://raw.githubusercontent.com/samson-media/barn/main/install.ps1 | iex
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual Download
|
||||||
|
|
||||||
|
**MacOS (ARM64):**
|
||||||
```bash
|
```bash
|
||||||
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-macos-arm64
|
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-macos-arm64
|
||||||
chmod +x barn
|
chmod +x barn
|
||||||
sudo mv barn /usr/local/bin/
|
sudo mv barn /usr/local/bin/
|
||||||
```
|
```
|
||||||
|
|
||||||
### Linux
|
**Linux (x64):**
|
||||||
|
|
||||||
**Download the binary:**
|
|
||||||
```bash
|
```bash
|
||||||
# For x64
|
|
||||||
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-linux-x64
|
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-linux-x64
|
||||||
|
|
||||||
# For ARM64
|
|
||||||
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-linux-arm64
|
|
||||||
|
|
||||||
chmod +x barn
|
chmod +x barn
|
||||||
sudo mv barn /usr/local/bin/
|
sudo mv barn /usr/local/bin/
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows
|
**Linux (ARM64):**
|
||||||
|
```bash
|
||||||
|
curl -L -o barn https://github.com/samson-media/barn/releases/latest/download/barn-linux-arm64
|
||||||
|
chmod +x barn
|
||||||
|
sudo mv barn /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
**PowerShell (recommended):**
|
**Windows (PowerShell):**
|
||||||
```powershell
|
```powershell
|
||||||
# Create install directory
|
|
||||||
New-Item -ItemType Directory -Force -Path "$env:LOCALAPPDATA\Programs\barn"
|
New-Item -ItemType Directory -Force -Path "$env:LOCALAPPDATA\Programs\barn"
|
||||||
|
|
||||||
# Download
|
|
||||||
Invoke-WebRequest -Uri "https://github.com/samson-media/barn/releases/latest/download/barn-windows-x64.exe" -OutFile "$env:LOCALAPPDATA\Programs\barn\barn.exe"
|
Invoke-WebRequest -Uri "https://github.com/samson-media/barn/releases/latest/download/barn-windows-x64.exe" -OutFile "$env:LOCALAPPDATA\Programs\barn\barn.exe"
|
||||||
|
|
||||||
# Add to PATH (current user)
|
|
||||||
$path = [Environment]::GetEnvironmentVariable("Path", "User")
|
$path = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
if ($path -notlike "*$env:LOCALAPPDATA\Programs\barn*") {
|
if ($path -notlike "*$env:LOCALAPPDATA\Programs\barn*") {
|
||||||
[Environment]::SetEnvironmentVariable("Path", "$path;$env:LOCALAPPDATA\Programs\barn", "User")
|
[Environment]::SetEnvironmentVariable("Path", "$path;$env:LOCALAPPDATA\Programs\barn", "User")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Restart your terminal after installation.
|
### Setting Up the Service (Manual Install)
|
||||||
|
|
||||||
|
If you installed manually, you need to set up the service to run on startup:
|
||||||
|
|
||||||
|
**Linux (systemd):**
|
||||||
|
```bash
|
||||||
|
barn service install
|
||||||
|
sudo systemctl enable barn
|
||||||
|
sudo systemctl start barn
|
||||||
|
```
|
||||||
|
|
||||||
|
**macOS (launchd):**
|
||||||
|
```bash
|
||||||
|
barn service install
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows (as Administrator):**
|
||||||
|
```powershell
|
||||||
|
barn service install
|
||||||
|
barn service start
|
||||||
|
```
|
||||||
|
|
||||||
### Verify Installation
|
### Verify Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
barn --version
|
barn --version
|
||||||
|
barn service status
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -112,19 +154,40 @@ barn is just one binary for both the service and the client. the client uses IPC
|
|||||||
|
|
||||||
clients typically access barn over ssh:
|
clients typically access barn over ssh:
|
||||||
- fetch from webdav server: `barn run --output=json curl -u username:password -o /tmp/barn/input/video.mp4 https://example.com/dav/remote-file.ext`
|
- fetch from webdav server: `barn run --output=json curl -u username:password -o /tmp/barn/input/video.mp4 https://example.com/dav/remote-file.ext`
|
||||||
- analyse file with ffmpeg: `barn run --output=json curl ffprobe -i /tmp/barn/input/video.mp4`
|
- analyse file with ffmpeg: `barn run --output=json ffprobe -i /tmp/barn/input/video.mp4`
|
||||||
- get status of the jobs `bar status --output=json`
|
- get status of the jobs `barn status --output=json`
|
||||||
|
|
||||||
barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
||||||
|
|
||||||
### Managing the service
|
### Managing the service
|
||||||
|
|
||||||
There needs to be a barn service in order to run jobs (unless you use --offline). You manage the service using the `barn service` sub command.
|
There needs to be a barn service in order to run jobs (unless you use --offline). You manage the service using the `barn service` sub command.
|
||||||
- `barn service status"` - check the status of the service. up/down, process id etc.
|
- `barn service status` - check the status of the service. up/down, process id etc.
|
||||||
- `barn service start"` - starts barn service process
|
- `barn service start` - starts barn service process
|
||||||
- `barn service stop"` - stops/kills the barn service
|
- `barn service stop` - stops/kills the barn service
|
||||||
- `barn service restart"` - restarts the barn service
|
- `barn service restart` - restarts the barn service
|
||||||
- `barn service reload"` - reloads the configuration and soft restarts the barn service
|
- `barn service reload` - reloads the configuration and soft restarts the barn service
|
||||||
|
|
||||||
|
**Example: `barn service status --output=json`**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status" : "running",
|
||||||
|
"running" : true,
|
||||||
|
"pid" : 17474,
|
||||||
|
"uptime_seconds" : 16,
|
||||||
|
"started_at" : "2026-01-22T01:48:41.869Z",
|
||||||
|
"jobs" : {
|
||||||
|
"running" : 0,
|
||||||
|
"queued" : 1,
|
||||||
|
"succeeded" : 1,
|
||||||
|
"failed" : 0,
|
||||||
|
"canceled" : 0,
|
||||||
|
"killed" : 0,
|
||||||
|
"total" : 2
|
||||||
|
},
|
||||||
|
"data_dir" : "/tmp/barn"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Adding jobs
|
### Adding jobs
|
||||||
|
|
||||||
@@ -147,19 +210,92 @@ Users can tag job for the purpose of filtering using the --tag=string CLI option
|
|||||||
|
|
||||||
Developers can use the --offline command line option to test how the service behaves eg creating tmp files etc. This runs the same code as the service but without having to run the service
|
Developers can use the --offline command line option to test how the service behaves eg creating tmp files etc. This runs the same code as the service but without having to run the service
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
**Example: `barn run --output=json -- echo "Hello World"`**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "job-6d368040",
|
||||||
|
"state" : "QUEUED",
|
||||||
|
"command" : [ "echo", "Hello World" ],
|
||||||
|
"tag" : null,
|
||||||
|
"createdAt" : "2026-01-22T01:48:46.749629Z",
|
||||||
|
"startedAt" : null,
|
||||||
|
"finishedAt" : null,
|
||||||
|
"exitCode" : null,
|
||||||
|
"error" : null,
|
||||||
|
"pid" : null,
|
||||||
|
"heartbeat" : null,
|
||||||
|
"retryCount" : 0,
|
||||||
|
"retryAt" : null,
|
||||||
|
"terminal" : false,
|
||||||
|
"running" : false,
|
||||||
|
"queued" : true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Get status of jobs
|
### Get status of jobs
|
||||||
|
|
||||||
`bar status` gets the status of all jobs found in /tmp.
|
`barn status` gets the status of all jobs found in /tmp.
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
**Example: `barn status --output=json`**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"jobs" : [ {
|
||||||
|
"id" : "job-6d368040",
|
||||||
|
"state" : "SUCCEEDED",
|
||||||
|
"command" : [ "echo", "Hello World" ],
|
||||||
|
"tag" : null,
|
||||||
|
"createdAt" : "2026-01-22T01:48:46.739979Z",
|
||||||
|
"startedAt" : "2026-01-22T01:48:47.161895Z",
|
||||||
|
"finishedAt" : "2026-01-22T01:48:47.184605Z",
|
||||||
|
"exitCode" : 0,
|
||||||
|
"error" : null,
|
||||||
|
"pid" : 17486,
|
||||||
|
"heartbeat" : "2026-01-22T01:48:47.161895Z",
|
||||||
|
"retryCount" : 0,
|
||||||
|
"retryAt" : null,
|
||||||
|
"running" : false,
|
||||||
|
"terminal" : true,
|
||||||
|
"queued" : false
|
||||||
|
} ],
|
||||||
|
"summary" : {
|
||||||
|
"total" : 1,
|
||||||
|
"queued" : 0,
|
||||||
|
"running" : 0,
|
||||||
|
"succeeded" : 1,
|
||||||
|
"failed" : 0,
|
||||||
|
"canceled" : 0,
|
||||||
|
"killed" : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Get Details of a job
|
### Get Details of a job
|
||||||
`barn describe {jobId}` - collects all the info from /tmp and display it
|
`barn describe {jobId}` - collects all the info from /tmp and display it
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
**Example: `barn describe job-6d368040 --output=json`**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id" : "job-6d368040",
|
||||||
|
"state" : "succeeded",
|
||||||
|
"tag" : null,
|
||||||
|
"command" : [ "echo", "Hello World" ],
|
||||||
|
"createdAt" : "2026-01-22T01:48:46.739979Z",
|
||||||
|
"startedAt" : "2026-01-22T01:48:47.161895Z",
|
||||||
|
"finishedAt" : "2026-01-22T01:48:47.184605Z",
|
||||||
|
"pid" : 17486,
|
||||||
|
"exitCode" : 0,
|
||||||
|
"error" : null,
|
||||||
|
"heartbeat" : "2026-01-22T01:48:47.161895Z",
|
||||||
|
"retryCount" : 0,
|
||||||
|
"retryAt" : null,
|
||||||
|
"paths" : {
|
||||||
|
"jobDir" : "/tmp/barn/jobs/job-6d368040",
|
||||||
|
"workDir" : "/tmp/barn/jobs/job-6d368040/work",
|
||||||
|
"logsDir" : "/tmp/barn/jobs/job-6d368040/logs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -167,19 +303,8 @@ Developers can use the --offline command line option to test how the service beh
|
|||||||
### Stop a job
|
### Stop a job
|
||||||
`barn kill {jobId}` - kills a job process
|
`barn kill {jobId}` - kills a job process
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
|
||||||
|
|
||||||
|
|
||||||
### Stop a job
|
|
||||||
`barn kill {jobId}` - kills a job
|
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
|
||||||
|
|
||||||
|
|
||||||
### Clean up jobs
|
### Clean up jobs
|
||||||
`barn clean` - removes completed jobs and cleans up old jobs (older than max_age config) with errors from /tmp
|
`barn clean` - removes completed jobs and cleans up old jobs (older than max_age config) from /tmp
|
||||||
|
|
||||||
> barn's output defaults to a human-readable format, but also supports xml or json via the --output={json|xml} cli option.
|
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
@@ -190,7 +315,7 @@ Developers can use the --offline command line option to test how the service beh
|
|||||||
- [Coding Standards](docs/coding-standards.md) defines code style, conventions, and quality enforcement
|
- [Coding Standards](docs/coding-standards.md) defines code style, conventions, and quality enforcement
|
||||||
- [Releasing](docs/releasing.md) describes version management and the release process
|
- [Releasing](docs/releasing.md) describes version management and the release process
|
||||||
- [CI/CD](docs/ci-cd.md) documents the GitHub Actions workflows for building and releasing
|
- [CI/CD](docs/ci-cd.md) documents the GitHub Actions workflows for building and releasing
|
||||||
- [Distribution](docs/distribution.md) covers package manager setup (WinGet, apt, AUR, Homebrew)
|
- [Distribution](docs/distribution.md) covers installation methods (Windows setup, Linux binary, Homebrew)
|
||||||
- [Auto-Update](docs/auto-update.md) explains the built-in `barn update` command
|
- [Updating](docs/auto-update.md) explains how to update Barn on each platform
|
||||||
- [Automated Testing](docs/testing-automated.md) covers the test suite, running tests, and CI integration
|
- [Automated Testing](docs/testing-automated.md) covers the test suite, running tests, and CI integration
|
||||||
- [Manual Testing](docs/testing-manual.md) provides step-by-step manual test procedures
|
- [Manual Testing](docs/testing-manual.md) provides step-by-step manual test procedures
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<ruleset name="Barn PMD Ruleset"
|
|
||||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
|
||||||
|
|
||||||
<description>
|
|
||||||
PMD ruleset for Barn project.
|
|
||||||
Based on PMD best practices with adjustments for modern Java.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- BEST PRACTICES -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/bestpractices.xml">
|
|
||||||
<!-- Allow JUnit 5 assertions -->
|
|
||||||
<exclude name="JUnitTestContainsTooManyAsserts"/>
|
|
||||||
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
|
|
||||||
<!-- We use Mockito, not JUnit 4 -->
|
|
||||||
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
|
|
||||||
<exclude name="JUnit4TestShouldUseBeforeAnnotation"/>
|
|
||||||
<exclude name="JUnit4TestShouldUseAfterAnnotation"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
|
|
||||||
<properties>
|
|
||||||
<property name="ignoredAnnotations" value="jakarta.annotation.PostConstruct|javax.annotation.PostConstruct"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- CODE STYLE -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/codestyle.xml">
|
|
||||||
<!-- We prefer explicit imports -->
|
|
||||||
<exclude name="OnlyOneReturn"/>
|
|
||||||
<!-- Allow short variable names like 'id', 'in', 'out' -->
|
|
||||||
<exclude name="ShortVariable"/>
|
|
||||||
<!-- Allow longer method names for clarity -->
|
|
||||||
<exclude name="LongVariable"/>
|
|
||||||
<!-- Allow static imports for test utilities -->
|
|
||||||
<exclude name="TooManyStaticImports"/>
|
|
||||||
<!-- We have our own formatting rules -->
|
|
||||||
<exclude name="AtLeastOneConstructor"/>
|
|
||||||
<!-- Allow default package for CLI commands -->
|
|
||||||
<exclude name="CommentDefaultAccessModifier"/>
|
|
||||||
<!-- Java 21+ has useful implicit classes -->
|
|
||||||
<exclude name="UnnecessaryFullyQualifiedName"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
|
|
||||||
<properties>
|
|
||||||
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/codestyle.xml/MethodNamingConventions">
|
|
||||||
<properties>
|
|
||||||
<property name="methodPattern" value="[a-z][a-zA-Z0-9]*"/>
|
|
||||||
<property name="nativePattern" value="[a-z][a-zA-Z0-9]*"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- DESIGN -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/design.xml">
|
|
||||||
<!-- Modern Java allows reasonable complexity -->
|
|
||||||
<exclude name="LawOfDemeter"/>
|
|
||||||
<!-- Allow data classes with many fields -->
|
|
||||||
<exclude name="TooManyFields"/>
|
|
||||||
<!-- Exclude for builders and configs -->
|
|
||||||
<exclude name="ExcessivePublicCount"/>
|
|
||||||
<!-- Allow reasonable method size -->
|
|
||||||
<exclude name="ExcessiveMethodLength"/>
|
|
||||||
<!-- Allow reasonable class size -->
|
|
||||||
<exclude name="ExcessiveClassLength"/>
|
|
||||||
<!-- Too strict for modern patterns -->
|
|
||||||
<exclude name="AvoidCatchingGenericException"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/design.xml/CyclomaticComplexity">
|
|
||||||
<properties>
|
|
||||||
<property name="classReportLevel" value="80"/>
|
|
||||||
<property name="methodReportLevel" value="15"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/design.xml/NPathComplexity">
|
|
||||||
<properties>
|
|
||||||
<property name="reportLevel" value="200"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/design.xml/TooManyMethods">
|
|
||||||
<properties>
|
|
||||||
<property name="maxmethods" value="25"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- DOCUMENTATION -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/documentation.xml">
|
|
||||||
<exclude name="CommentRequired"/>
|
|
||||||
<exclude name="CommentSize"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- ERROR PRONE -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/errorprone.xml">
|
|
||||||
<!-- Allow null assignments in cleanup -->
|
|
||||||
<exclude name="NullAssignment"/>
|
|
||||||
<!-- Allow close in finally for legacy code -->
|
|
||||||
<exclude name="CloseResource"/>
|
|
||||||
<!-- We validate beans differently -->
|
|
||||||
<exclude name="BeanMembersShouldSerialize"/>
|
|
||||||
<!-- Too strict -->
|
|
||||||
<exclude name="DataflowAnomalyAnalysis"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="category/java/errorprone.xml/AvoidLiteralsInIfCondition">
|
|
||||||
<properties>
|
|
||||||
<property name="ignoreMagicNumbers" value="-1,0,1,2"/>
|
|
||||||
<property name="ignoreExpressions" value="true"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- MULTITHREADING -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/multithreading.xml">
|
|
||||||
<!-- We use modern concurrency utilities -->
|
|
||||||
<exclude name="UseConcurrentHashMap"/>
|
|
||||||
<exclude name="DoNotUseThreads"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- PERFORMANCE -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/performance.xml">
|
|
||||||
<!-- Modern JVM handles this well -->
|
|
||||||
<exclude name="AvoidInstantiatingObjectsInLoops"/>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- SECURITY -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
|
|
||||||
<rule ref="category/java/security.xml"/>
|
|
||||||
|
|
||||||
</ruleset>
|
|
||||||
+146
-1
@@ -24,15 +24,29 @@
|
|||||||
<Bug pattern="DM_EXIT"/>
|
<Bug pattern="DM_EXIT"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
<!-- Allow command execution in specific classes -->
|
<!-- Allow command execution in specific classes - commands are hardcoded, not user input -->
|
||||||
<Match>
|
<Match>
|
||||||
<Or>
|
<Or>
|
||||||
<Class name="~.*ProcessExecutor.*"/>
|
<Class name="~.*ProcessExecutor.*"/>
|
||||||
<Class name="~.*CommandRunner.*"/>
|
<Class name="~.*CommandRunner.*"/>
|
||||||
|
<Class name="~.*ServiceStartCommand.*"/>
|
||||||
|
<Class name="~.*ServiceStopCommand.*"/>
|
||||||
|
<Class name="~.*ServiceRestartCommand.*"/>
|
||||||
|
<Class name="~.*ServiceInstallCommand.*"/>
|
||||||
|
<Class name="~.*ServiceUninstallCommand.*"/>
|
||||||
|
<Class name="~.*WindowsServiceManager.*"/>
|
||||||
|
<Class name="~.*SystemdManager.*"/>
|
||||||
|
<Class name="~.*LaunchdManager.*"/>
|
||||||
|
<Class name="~.*UsageCollector.*"/>
|
||||||
</Or>
|
</Or>
|
||||||
<Bug pattern="COMMAND_INJECTION"/>
|
<Bug pattern="COMMAND_INJECTION"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
|
<!-- CRLF injection in logs is not exploitable - we log internal identifiers like job IDs -->
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="CRLF_INJECTION_LOGS"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
<!-- Exclude false positives for try-with-resources -->
|
<!-- Exclude false positives for try-with-resources -->
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
|
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
|
||||||
@@ -46,4 +60,135 @@
|
|||||||
</Not>
|
</Not>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
|
<!-- Hardcoded absolute paths are intentional for system service installation paths -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*ConfigDefaults.*"/>
|
||||||
|
<Class name="~.*ServiceInstallCommand.*"/>
|
||||||
|
<Class name="~.*SystemdManager.*"/>
|
||||||
|
<Class name="~.*LaunchdManager.*"/>
|
||||||
|
<Class name="~.*IpcClient.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- XmlFormatter uses internal data, not user input - XML injection not applicable -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*XmlFormatter.*"/>
|
||||||
|
<Bug pattern="POTENTIAL_XML_INJECTION"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Throwing exceptions from constructors is a valid pattern for checked initialization -->
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="CT_CONSTRUCTOR_THROW"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- ThreadLocalRandom for retry jitter doesn't need cryptographic randomness -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*RetryCalculator.*"/>
|
||||||
|
<Bug pattern="PREDICTABLE_RANDOM"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Using \n instead of %n is intentional for systemd/launchd config file templates -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*SystemdManager.*"/>
|
||||||
|
<Class name="~.*LaunchdManager.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="VA_FORMAT_STRING_USES_NEWLINE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Exposing internal representation is acceptable for records and DTOs -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*IpcMessage.*"/>
|
||||||
|
<Class name="~.*IpcRequest.*"/>
|
||||||
|
<Class name="~.*ProcessMonitor.*"/>
|
||||||
|
<Class name="~.*BarnService.*"/>
|
||||||
|
</Or>
|
||||||
|
<Or>
|
||||||
|
<Bug pattern="EI_EXPOSE_REP"/>
|
||||||
|
<Bug pattern="EI_EXPOSE_REP2"/>
|
||||||
|
</Or>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Lazy initialization race condition in OperatingSystem.current() is benign -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*OperatingSystem.*"/>
|
||||||
|
<Bug pattern="LI_LAZY_INIT_STATIC"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Catching generic Exception is intentional in some cases for resilience -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*UsageCollector.*"/>
|
||||||
|
<Class name="~.*XmlFormatter.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="REC_CATCH_EXCEPTION"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Throwing RuntimeException is intentional in ProcessMonitor for fatal errors -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*ProcessMonitor.*"/>
|
||||||
|
<Bug pattern="THROWS_METHOD_THROWS_RUNTIMEEXCEPTION"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Ignored Future returns are intentional for fire-and-forget tasks -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*JobScheduler.*"/>
|
||||||
|
<Class name="~.*IpcServer.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Format string manipulation warnings in CLI - internal use only -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*StatusCommand.*"/>
|
||||||
|
<Bug pattern="FORMAT_STRING_MANIPULATION"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Use of TEMP env variable is intentional for Windows compatibility -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*ConfigDefaults.*"/>
|
||||||
|
<Bug pattern="ENV_USE_PROPERTY_INSTEAD_OF_ENV"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- toLowerCase with Locale.ROOT is correct - these are false positives -->
|
||||||
|
<Match>
|
||||||
|
<Bug pattern="IMPROPER_UNICODE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- IpcClient/IpcServer streams wrap channels managed separately - closing streams would close channels -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*IpcClient.*"/>
|
||||||
|
<Class name="~.*IpcServer.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="OS_OPEN_STREAM"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- Paths are always absolute in this codebase - getParent()/getFileName() won't return null -->
|
||||||
|
<Match>
|
||||||
|
<Or>
|
||||||
|
<Class name="~.*ProcessExecutor.*"/>
|
||||||
|
<Class name="~.*JobRunner.*"/>
|
||||||
|
<Class name="~.*JobRepository.*"/>
|
||||||
|
<Class name="~.*IpcServer.*"/>
|
||||||
|
</Or>
|
||||||
|
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- BarnLogger.setOutput() intentionally exposes mutable state for testing purposes -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*BarnLogger.*"/>
|
||||||
|
<Bug pattern="EI_EXPOSE_STATIC_REP2"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
|
<!-- BarnLogger error logging intentionally prints stack traces - that's its purpose -->
|
||||||
|
<Match>
|
||||||
|
<Class name="~.*BarnLogger.*"/>
|
||||||
|
<Bug pattern="INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
</FindBugsFilter>
|
</FindBugsFilter>
|
||||||
+69
-386
@@ -1,137 +1,100 @@
|
|||||||
# Auto-Update
|
# Updating Barn
|
||||||
|
|
||||||
This document describes Barn's built-in self-update mechanism.
|
This document describes how to keep Barn updated on different platforms.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Barn includes a `barn update` command that can check for and install new versions directly from GitHub Releases without requiring a package manager.
|
| Platform | Update Method | Automatic |
|
||||||
|
|----------|---------------|-----------|
|
||||||
|
| macOS (Homebrew) | `brew upgrade barn` | Yes |
|
||||||
|
| macOS (manual) | Download from GitHub Releases | No |
|
||||||
|
| Windows | Download setup installer from GitHub Releases | No |
|
||||||
|
| Linux | Download binary from GitHub Releases | No |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Commands
|
## macOS (Homebrew)
|
||||||
|
|
||||||
### Check for Updates
|
If you installed Barn via Homebrew, updates are handled automatically:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
barn update --check
|
# Check for updates
|
||||||
|
brew outdated barn
|
||||||
|
|
||||||
|
# Update Barn
|
||||||
|
brew upgrade barn
|
||||||
|
|
||||||
|
# Restart the service after updating
|
||||||
|
brew services restart barn
|
||||||
```
|
```
|
||||||
|
|
||||||
Output:
|
Homebrew will automatically fetch the latest version from the Homebrew tap when you run `brew upgrade`.
|
||||||
|
|
||||||
```
|
---
|
||||||
Current version: 1.2.3
|
|
||||||
Latest version: 1.3.0
|
|
||||||
Update available: yes
|
|
||||||
|
|
||||||
Run 'barn update' to install the latest version.
|
## macOS (Manual Installation)
|
||||||
```
|
|
||||||
|
|
||||||
### Install Latest Version
|
If you installed Barn manually (not via Homebrew):
|
||||||
|
|
||||||
```bash
|
1. Download the latest binary from [GitHub Releases](https://github.com/samson-media/barn/releases/latest)
|
||||||
barn update
|
2. Stop the service: `barn service stop`
|
||||||
```
|
3. Replace the binary:
|
||||||
|
```bash
|
||||||
|
chmod +x barn-macos-arm64
|
||||||
|
sudo mv barn-macos-arm64 /usr/local/bin/barn
|
||||||
|
```
|
||||||
|
4. Verify: `barn --version`
|
||||||
|
5. Start the service: `barn service start`
|
||||||
|
|
||||||
Output:
|
---
|
||||||
|
|
||||||
```
|
## Windows
|
||||||
Current version: 1.2.3
|
|
||||||
Latest version: 1.3.0
|
|
||||||
|
|
||||||
Downloading barn-macos-arm64...
|
To update Barn on Windows:
|
||||||
Verifying checksum...
|
|
||||||
Installing...
|
|
||||||
Restarting service...
|
|
||||||
|
|
||||||
Successfully updated to version 1.3.0
|
1. Download the latest `setup-barn-vX.X.X-windows-x64.exe` from [GitHub Releases](https://github.com/samson-media/barn/releases/latest)
|
||||||
```
|
2. Run the installer - it will automatically:
|
||||||
|
- Stop the Barn service
|
||||||
|
- Update the binary
|
||||||
|
- Restart the service
|
||||||
|
|
||||||
### Install Specific Version
|
Alternatively, for silent updates:
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
barn update --version=1.2.0
|
# Download the installer
|
||||||
```
|
Invoke-WebRequest -Uri "https://github.com/samson-media/barn/releases/latest/download/setup-barn-vX.X.X-windows-x64.exe" -OutFile "setup-barn.exe"
|
||||||
|
|
||||||
### Force Update (Reinstall Current Version)
|
# Run silent installation
|
||||||
|
.\setup-barn.exe /S
|
||||||
```bash
|
|
||||||
barn update --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### JSON Output
|
|
||||||
|
|
||||||
```bash
|
|
||||||
barn update --check --output=json
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"current_version": "1.2.3",
|
|
||||||
"latest_version": "1.3.0",
|
|
||||||
"update_available": true,
|
|
||||||
"release_url": "https://github.com/samson-media/barn/releases/tag/v1.3.0"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Update Flow
|
## Linux
|
||||||
|
|
||||||
### 1. Query GitHub Releases API
|
To update Barn on Linux:
|
||||||
|
|
||||||
Barn queries the GitHub Releases API to find the latest version:
|
1. Download the latest binary from [GitHub Releases](https://github.com/samson-media/barn/releases/latest)
|
||||||
|
2. Stop the service:
|
||||||
|
```bash
|
||||||
|
sudo systemctl stop barn
|
||||||
|
```
|
||||||
|
3. Replace the binary:
|
||||||
|
```bash
|
||||||
|
chmod +x barn-linux-x64
|
||||||
|
sudo mv barn-linux-x64 /usr/local/bin/barn
|
||||||
|
```
|
||||||
|
4. Verify: `barn --version`
|
||||||
|
5. Start the service:
|
||||||
|
```bash
|
||||||
|
sudo systemctl start barn
|
||||||
|
```
|
||||||
|
|
||||||
```
|
---
|
||||||
GET https://api.github.com/repos/samson-media/barn/releases/latest
|
|
||||||
```
|
|
||||||
|
|
||||||
Response includes:
|
## Checking Your Current Version
|
||||||
- Version tag
|
|
||||||
- Asset download URLs
|
|
||||||
- Checksums
|
|
||||||
|
|
||||||
### 2. Compare Versions
|
|
||||||
|
|
||||||
Versions are compared using semantic versioning:
|
|
||||||
|
|
||||||
```
|
|
||||||
1.3.0 > 1.2.3 → Update available
|
|
||||||
1.2.3 = 1.2.3 → Up to date
|
|
||||||
1.2.0 < 1.2.3 → Downgrade (requires --force)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Download Binary
|
|
||||||
|
|
||||||
The appropriate binary is downloaded based on OS and architecture:
|
|
||||||
|
|
||||||
| OS | Architecture | Asset |
|
|
||||||
|----|--------------|-------|
|
|
||||||
| Linux | x86_64 | `barn-linux-x64` |
|
|
||||||
| Linux | ARM64 | `barn-linux-arm64` |
|
|
||||||
| macOS | x86_64 | `barn-macos-x64` |
|
|
||||||
| macOS | ARM64 | `barn-macos-arm64` |
|
|
||||||
| Windows | x86_64 | `barn-windows-x64.exe` |
|
|
||||||
|
|
||||||
### 4. Verify Checksum
|
|
||||||
|
|
||||||
The SHA256 checksum is verified against `SHA256SUMS`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Downloaded automatically and verified
|
|
||||||
sha256sum -c SHA256SUMS
|
|
||||||
```
|
|
||||||
|
|
||||||
If verification fails, the update is aborted.
|
|
||||||
|
|
||||||
### 5. Replace Binary
|
|
||||||
|
|
||||||
The old binary is replaced with the new one.
|
|
||||||
|
|
||||||
### 6. Verify Installation
|
|
||||||
|
|
||||||
After replacement, Barn verifies the new binary works:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
barn --version
|
barn --version
|
||||||
@@ -139,296 +102,16 @@ barn --version
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Platform-Specific Behavior
|
## Release Notifications
|
||||||
|
|
||||||
### Windows
|
To be notified of new releases, watch the [GitHub repository](https://github.com/samson-media/barn):
|
||||||
|
|
||||||
Windows cannot replace a running executable. The update process:
|
1. Go to https://github.com/samson-media/barn
|
||||||
|
2. Click "Watch" → "Custom" → Select "Releases"
|
||||||
1. Download new binary to temp location
|
|
||||||
2. Stop the Barn service
|
|
||||||
3. Rename current `barn.exe` to `barn.exe.old`
|
|
||||||
4. Move new binary to `barn.exe`
|
|
||||||
5. Start the Barn service
|
|
||||||
6. Delete `barn.exe.old` on next run
|
|
||||||
|
|
||||||
```
|
|
||||||
C:\Program Files\Barn\
|
|
||||||
barn.exe ← New version
|
|
||||||
barn.exe.old ← Previous version (deleted on next run)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Linux / macOS
|
|
||||||
|
|
||||||
Direct replacement if permissions allow:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Requires write permission to binary location
|
|
||||||
sudo barn update
|
|
||||||
```
|
|
||||||
|
|
||||||
If running without sudo and binary is in a protected location:
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Cannot update binary at /usr/local/bin/barn
|
|
||||||
Permission denied. Run with sudo or use your package manager.
|
|
||||||
```
|
|
||||||
|
|
||||||
### Package Manager Installations
|
|
||||||
|
|
||||||
If Barn detects it was installed via a package manager, it warns the user:
|
|
||||||
|
|
||||||
```
|
|
||||||
Warning: Barn appears to be installed via Homebrew.
|
|
||||||
Using 'barn update' may conflict with your package manager.
|
|
||||||
|
|
||||||
Recommended: Run 'brew upgrade barn' instead.
|
|
||||||
|
|
||||||
Continue anyway? [y/N]
|
|
||||||
```
|
|
||||||
|
|
||||||
Detection methods:
|
|
||||||
|
|
||||||
| Package Manager | Detection |
|
|
||||||
|-----------------|-----------|
|
|
||||||
| Homebrew | Binary in `/opt/homebrew/` or `/usr/local/Cellar/` |
|
|
||||||
| apt/dpkg | Binary in `/usr/bin/` with dpkg ownership |
|
|
||||||
| pacman | Binary in `/usr/bin/` with pacman ownership |
|
|
||||||
| WinGet | Registry entries present |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Security
|
|
||||||
|
|
||||||
### HTTPS Only
|
|
||||||
|
|
||||||
All downloads use HTTPS. HTTP is never used.
|
|
||||||
|
|
||||||
### Checksum Verification
|
|
||||||
|
|
||||||
Every download is verified against the published SHA256 checksum:
|
|
||||||
|
|
||||||
```
|
|
||||||
SHA256SUMS content:
|
|
||||||
a1b2c3d4... barn-linux-x64
|
|
||||||
e5f6g7h8... barn-linux-arm64
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
If the checksum doesn't match, the update fails:
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Checksum verification failed
|
|
||||||
Expected: a1b2c3d4...
|
|
||||||
Got: xxxxxxxx...
|
|
||||||
|
|
||||||
The download may be corrupted or tampered with.
|
|
||||||
Update aborted.
|
|
||||||
```
|
|
||||||
|
|
||||||
### Signature Verification (Optional)
|
|
||||||
|
|
||||||
If GPG signatures are published, Barn can verify them:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
barn update --verify-signature
|
|
||||||
```
|
|
||||||
|
|
||||||
This requires the Samson Media public key to be imported.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Update behavior can be configured in `barn.conf`:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[update]
|
|
||||||
# Disable update checks
|
|
||||||
enabled = true
|
|
||||||
|
|
||||||
# Check for updates automatically on service start
|
|
||||||
check_on_start = true
|
|
||||||
|
|
||||||
# Notify about updates without auto-installing
|
|
||||||
auto_install = false
|
|
||||||
|
|
||||||
# GitHub API endpoint (for enterprise GitHub)
|
|
||||||
github_api = "https://api.github.com"
|
|
||||||
|
|
||||||
# Proxy settings
|
|
||||||
proxy = ""
|
|
||||||
```
|
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Disable update functionality
|
|
||||||
BARN_UPDATE_ENABLED=false
|
|
||||||
|
|
||||||
# Use proxy for downloads
|
|
||||||
BARN_UPDATE_PROXY=http://proxy.example.com:8080
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Rollback
|
|
||||||
|
|
||||||
Barn keeps the previous version as a backup.
|
|
||||||
|
|
||||||
### Automatic Backup
|
|
||||||
|
|
||||||
During update, the previous binary is preserved:
|
|
||||||
|
|
||||||
| Platform | Backup Location |
|
|
||||||
|----------|-----------------|
|
|
||||||
| Linux/macOS | `/usr/local/bin/barn.backup` or alongside binary |
|
|
||||||
| Windows | `barn.exe.backup` |
|
|
||||||
|
|
||||||
### Manual Rollback
|
|
||||||
|
|
||||||
```bash
|
|
||||||
barn update --rollback
|
|
||||||
```
|
|
||||||
|
|
||||||
Or manually:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Linux/macOS
|
|
||||||
sudo mv /usr/local/bin/barn.backup /usr/local/bin/barn
|
|
||||||
|
|
||||||
# Windows
|
|
||||||
move "C:\Program Files\Barn\barn.exe.backup" "C:\Program Files\Barn\barn.exe"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Rollback Retention
|
|
||||||
|
|
||||||
Only the most recent previous version is kept. Older backups are deleted.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Offline Mode
|
|
||||||
|
|
||||||
If network is unavailable:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
barn update --check
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Cannot reach GitHub API
|
|
||||||
Check your network connection or proxy settings.
|
|
||||||
|
|
||||||
For offline installation, download the binary manually from:
|
|
||||||
https://github.com/samson-media/barn/releases
|
|
||||||
```
|
|
||||||
|
|
||||||
### Manual Offline Update
|
|
||||||
|
|
||||||
1. Download binary on another machine
|
|
||||||
2. Transfer to target machine
|
|
||||||
3. Replace binary manually:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
chmod +x barn-linux-x64
|
|
||||||
sudo mv barn-linux-x64 /usr/local/bin/barn
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Update Notifications
|
|
||||||
|
|
||||||
When `check_on_start = true`, Barn checks for updates when the service starts and logs:
|
|
||||||
|
|
||||||
```
|
|
||||||
[INFO] Update available: 1.3.0 (current: 1.2.3)
|
|
||||||
[INFO] Run 'barn update' to install
|
|
||||||
```
|
|
||||||
|
|
||||||
This check is non-blocking and doesn't affect service startup.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Update Check Fails
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Failed to check for updates
|
|
||||||
GitHub API rate limit exceeded.
|
|
||||||
```
|
|
||||||
|
|
||||||
Solution: Wait an hour or authenticate with a GitHub token:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
GITHUB_TOKEN=xxx barn update --check
|
|
||||||
```
|
|
||||||
|
|
||||||
### Permission Denied
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Cannot write to /usr/local/bin/barn
|
|
||||||
```
|
|
||||||
|
|
||||||
Solution: Run with elevated privileges:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo barn update
|
|
||||||
```
|
|
||||||
|
|
||||||
### Binary Corrupted After Update
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: barn: cannot execute binary file
|
|
||||||
```
|
|
||||||
|
|
||||||
Solution: Roll back and report the issue:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo mv /usr/local/bin/barn.backup /usr/local/bin/barn
|
|
||||||
barn --version # Verify rollback worked
|
|
||||||
```
|
|
||||||
|
|
||||||
### Service Won't Start After Update
|
|
||||||
|
|
||||||
1. Check logs: `barn service logs`
|
|
||||||
2. Roll back: `barn update --rollback`
|
|
||||||
3. Start service: `barn service start`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Implementation Details
|
|
||||||
|
|
||||||
### Version Detection
|
|
||||||
|
|
||||||
Barn determines its own version at compile time:
|
|
||||||
|
|
||||||
```kotlin
|
|
||||||
object Version {
|
|
||||||
const val CURRENT = "1.2.3" // Injected at build
|
|
||||||
val commit = System.getenv("BARN_COMMIT") ?: "unknown"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### API Endpoint
|
|
||||||
|
|
||||||
```
|
|
||||||
GET https://api.github.com/repos/samson-media/barn/releases/latest
|
|
||||||
Accept: application/vnd.github.v3+json
|
|
||||||
```
|
|
||||||
|
|
||||||
### Download with Progress
|
|
||||||
|
|
||||||
Downloads show progress for large binaries:
|
|
||||||
|
|
||||||
```
|
|
||||||
Downloading barn-linux-x64...
|
|
||||||
[████████████████████░░░░░░░░░░] 67% (12.3 MB / 18.4 MB)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
- [Releasing](releasing.md) - How versions are published
|
- [Releasing](releasing.md) - How versions are published
|
||||||
- [Distribution](distribution.md) - Package manager alternatives
|
- [Distribution](distribution.md) - Installation methods by platform
|
||||||
+67
-484
@@ -8,524 +8,109 @@ This document describes package manager setup and installer creation for all sup
|
|||||||
|
|
||||||
| Platform | Package Format | Distribution Channel |
|
| Platform | Package Format | Distribution Channel |
|
||||||
|----------|---------------|---------------------|
|
|----------|---------------|---------------------|
|
||||||
| Windows | MSI installer | WinGet |
|
| Windows | Setup installer (.exe) | GitHub Releases |
|
||||||
| Linux (Debian/Ubuntu) | .deb | GitHub Releases, optional PPA |
|
| Linux | Native binary | GitHub Releases |
|
||||||
| Linux (Arch) | PKGBUILD | AUR |
|
|
||||||
| macOS | Formula | Homebrew tap |
|
| macOS | Formula | Homebrew tap |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Windows MSI
|
## Windows Setup Installer
|
||||||
|
|
||||||
### WiX Toolset Setup
|
### Download
|
||||||
|
|
||||||
Barn uses [WiX Toolset v4](https://wixtoolset.org/) to create MSI installers.
|
Download the latest setup installer from GitHub Releases:
|
||||||
|
|
||||||
Install WiX:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
dotnet tool install --global wix
|
|
||||||
```
|
|
||||||
|
|
||||||
### Package Structure
|
|
||||||
|
|
||||||
```
|
```
|
||||||
packaging/wix/
|
https://github.com/samson-media/barn/releases/download/v1.2.3/setup-barn-v1.2.3-windows-x64.exe
|
||||||
barn.wxs # WiX source file
|
|
||||||
license.rtf # License for installer
|
|
||||||
banner.png # Installer banner (optional)
|
|
||||||
dialog.png # Installer dialog background (optional)
|
|
||||||
```
|
|
||||||
|
|
||||||
### WiX Source File
|
|
||||||
|
|
||||||
File: `packaging/wix/barn.wxs`
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
|
|
||||||
<Package Name="Barn"
|
|
||||||
Version="!(bind.FileVersion.BarnExe)"
|
|
||||||
Manufacturer="Samson Media"
|
|
||||||
UpgradeCode="PUT-GUID-HERE"
|
|
||||||
Scope="perMachine">
|
|
||||||
|
|
||||||
<MajorUpgrade DowngradeErrorMessage="A newer version of Barn is already installed." />
|
|
||||||
<MediaTemplate EmbedCab="yes" />
|
|
||||||
|
|
||||||
<Feature Id="ProductFeature" Title="Barn" Level="1">
|
|
||||||
<ComponentGroupRef Id="ProductComponents" />
|
|
||||||
<ComponentGroupRef Id="ServiceComponents" />
|
|
||||||
</Feature>
|
|
||||||
|
|
||||||
<StandardDirectory Id="ProgramFiles64Folder">
|
|
||||||
<Directory Id="INSTALLFOLDER" Name="Barn">
|
|
||||||
<Component Id="BarnExe" Guid="PUT-GUID-HERE">
|
|
||||||
<File Id="BarnExe" Source="barn-windows-x64.exe" Name="barn.exe" KeyPath="yes" />
|
|
||||||
</Component>
|
|
||||||
|
|
||||||
<Component Id="PathEntry" Guid="PUT-GUID-HERE">
|
|
||||||
<Environment Id="PATH" Name="PATH" Value="[INSTALLFOLDER]"
|
|
||||||
Permanent="no" Part="last" Action="set" System="yes" />
|
|
||||||
</Component>
|
|
||||||
</Directory>
|
|
||||||
</StandardDirectory>
|
|
||||||
|
|
||||||
<ComponentGroup Id="ProductComponents">
|
|
||||||
<ComponentRef Id="BarnExe" />
|
|
||||||
<ComponentRef Id="PathEntry" />
|
|
||||||
</ComponentGroup>
|
|
||||||
|
|
||||||
<ComponentGroup Id="ServiceComponents">
|
|
||||||
<Component Id="BarnService" Directory="INSTALLFOLDER" Guid="PUT-GUID-HERE">
|
|
||||||
<ServiceInstall Id="BarnServiceInstall"
|
|
||||||
Type="ownProcess"
|
|
||||||
Name="BarnService"
|
|
||||||
DisplayName="Barn Job Daemon"
|
|
||||||
Description="Background service for managing media processing jobs"
|
|
||||||
Start="auto"
|
|
||||||
Account="LocalSystem"
|
|
||||||
ErrorControl="normal" />
|
|
||||||
<ServiceControl Id="StartBarnService"
|
|
||||||
Start="install"
|
|
||||||
Stop="both"
|
|
||||||
Remove="uninstall"
|
|
||||||
Name="BarnService"
|
|
||||||
Wait="yes" />
|
|
||||||
</Component>
|
|
||||||
</ComponentGroup>
|
|
||||||
</Package>
|
|
||||||
</Wix>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Building the MSI
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
cd packaging/wix
|
|
||||||
wix build -o barn-windows-x64.msi barn.wxs
|
|
||||||
```
|
|
||||||
|
|
||||||
### WinGet Submission
|
|
||||||
|
|
||||||
#### Manifest Structure
|
|
||||||
|
|
||||||
Create a manifest directory:
|
|
||||||
|
|
||||||
```
|
|
||||||
manifests/s/SamsonMedia/Barn/1.2.3/
|
|
||||||
SamsonMedia.Barn.yaml
|
|
||||||
SamsonMedia.Barn.installer.yaml
|
|
||||||
SamsonMedia.Barn.locale.en-US.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Version Manifest
|
|
||||||
|
|
||||||
File: `SamsonMedia.Barn.yaml`
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
PackageIdentifier: SamsonMedia.Barn
|
|
||||||
PackageVersion: 1.2.3
|
|
||||||
DefaultLocale: en-US
|
|
||||||
ManifestType: version
|
|
||||||
ManifestVersion: 1.6.0
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Installer Manifest
|
|
||||||
|
|
||||||
File: `SamsonMedia.Barn.installer.yaml`
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
PackageIdentifier: SamsonMedia.Barn
|
|
||||||
PackageVersion: 1.2.3
|
|
||||||
Platform:
|
|
||||||
- Windows.Desktop
|
|
||||||
MinimumOSVersion: 10.0.0.0
|
|
||||||
InstallerType: msi
|
|
||||||
Scope: machine
|
|
||||||
InstallModes:
|
|
||||||
- silent
|
|
||||||
- silentWithProgress
|
|
||||||
Installers:
|
|
||||||
- Architecture: x64
|
|
||||||
InstallerUrl: https://github.com/samson-media/barn/releases/download/v1.2.3/barn-windows-x64.msi
|
|
||||||
InstallerSha256: <SHA256_HASH>
|
|
||||||
ManifestType: installer
|
|
||||||
ManifestVersion: 1.6.0
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Locale Manifest
|
|
||||||
|
|
||||||
File: `SamsonMedia.Barn.locale.en-US.yaml`
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
PackageIdentifier: SamsonMedia.Barn
|
|
||||||
PackageVersion: 1.2.3
|
|
||||||
PackageLocale: en-US
|
|
||||||
Publisher: Samson Media
|
|
||||||
PackageName: Barn
|
|
||||||
PackageUrl: https://github.com/samson-media/barn
|
|
||||||
License: MIT
|
|
||||||
ShortDescription: Cross-platform job daemon for media processing
|
|
||||||
Description: A cross-platform service for managing long-running jobs involving media download, upload, and FFmpeg processing.
|
|
||||||
Tags:
|
|
||||||
- cli
|
|
||||||
- ffmpeg
|
|
||||||
- media
|
|
||||||
- daemon
|
|
||||||
- job-scheduler
|
|
||||||
ManifestType: defaultLocale
|
|
||||||
ManifestVersion: 1.6.0
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Submitting to WinGet
|
|
||||||
|
|
||||||
1. Fork [microsoft/winget-pkgs](https://github.com/microsoft/winget-pkgs)
|
|
||||||
2. Create branch: `barn-1.2.3`
|
|
||||||
3. Add manifest files to `manifests/s/SamsonMedia/Barn/1.2.3/`
|
|
||||||
4. Validate: `winget validate manifests/s/SamsonMedia/Barn/1.2.3/`
|
|
||||||
5. Create pull request
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Linux .deb (apt)
|
|
||||||
|
|
||||||
### Package Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
packaging/deb/
|
|
||||||
DEBIAN/
|
|
||||||
control
|
|
||||||
postinst
|
|
||||||
prerm
|
|
||||||
conffiles
|
|
||||||
usr/
|
|
||||||
bin/
|
|
||||||
barn
|
|
||||||
lib/
|
|
||||||
systemd/
|
|
||||||
system/
|
|
||||||
barn.service
|
|
||||||
etc/
|
|
||||||
barn/
|
|
||||||
barn.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
### Control File
|
|
||||||
|
|
||||||
File: `packaging/deb/DEBIAN/control`
|
|
||||||
|
|
||||||
```
|
|
||||||
Package: barn
|
|
||||||
Version: 1.2.3
|
|
||||||
Section: utils
|
|
||||||
Priority: optional
|
|
||||||
Architecture: amd64
|
|
||||||
Maintainer: Samson Media <support@samson-media.com>
|
|
||||||
Description: Cross-platform job daemon for media processing
|
|
||||||
A cross-platform service for managing long-running jobs involving
|
|
||||||
media download, upload, and FFmpeg processing with strong guarantees
|
|
||||||
around durability, observability, and crash recovery.
|
|
||||||
Homepage: https://github.com/samson-media/barn
|
|
||||||
Depends: libc6 (>= 2.31)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Post-Install Script
|
|
||||||
|
|
||||||
File: `packaging/deb/DEBIAN/postinst`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Reload systemd
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
# Enable and start service
|
|
||||||
systemctl enable barn.service
|
|
||||||
systemctl start barn.service
|
|
||||||
|
|
||||||
echo "Barn installed successfully. Service is running."
|
|
||||||
echo "Run 'barn status' to check job status."
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pre-Remove Script
|
|
||||||
|
|
||||||
File: `packaging/deb/DEBIAN/prerm`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Stop and disable service
|
|
||||||
systemctl stop barn.service || true
|
|
||||||
systemctl disable barn.service || true
|
|
||||||
|
|
||||||
echo "Barn service stopped."
|
|
||||||
```
|
|
||||||
|
|
||||||
### Systemd Service File
|
|
||||||
|
|
||||||
File: `packaging/deb/lib/systemd/system/barn.service`
|
|
||||||
|
|
||||||
```ini
|
|
||||||
[Unit]
|
|
||||||
Description=Barn Job Daemon
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
ExecStart=/usr/bin/barn service run
|
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5
|
|
||||||
User=root
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
```
|
|
||||||
|
|
||||||
### Building the .deb
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Set permissions
|
|
||||||
chmod 755 packaging/deb/DEBIAN/postinst
|
|
||||||
chmod 755 packaging/deb/DEBIAN/prerm
|
|
||||||
chmod 755 packaging/deb/usr/bin/barn
|
|
||||||
|
|
||||||
# Build package
|
|
||||||
dpkg-deb --build packaging/deb barn-linux-x64.deb
|
|
||||||
|
|
||||||
# Verify
|
|
||||||
dpkg-deb --info barn-linux-x64.deb
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
Users install directly from GitHub Releases:
|
1. Download `setup-barn-vX.X.X-windows-x64.exe` from the [releases page](https://github.com/samson-media/barn/releases/latest)
|
||||||
|
2. Run the installer (requires Administrator privileges)
|
||||||
|
3. The installer will:
|
||||||
|
- Install `barn.exe` to `C:\Program Files\Barn\`
|
||||||
|
- Add Barn to the system PATH
|
||||||
|
- Install and start the Barn Windows Service
|
||||||
|
|
||||||
```bash
|
### Silent Installation
|
||||||
# Download
|
|
||||||
wget https://github.com/samson-media/barn/releases/download/v1.2.3/barn-linux-x64.deb
|
|
||||||
|
|
||||||
# Install
|
For automated deployments:
|
||||||
sudo dpkg -i barn-linux-x64.deb
|
|
||||||
|
|
||||||
# Or with apt (handles dependencies)
|
```powershell
|
||||||
sudo apt install ./barn-linux-x64.deb
|
.\setup-barn-v1.2.3-windows-x64.exe /S
|
||||||
```
|
```
|
||||||
|
|
||||||
### Optional: Launchpad PPA
|
### Uninstallation
|
||||||
|
|
||||||
For automatic updates via apt:
|
Use Windows Settings → Apps → Barn, or run:
|
||||||
|
|
||||||
1. Create account at [Launchpad](https://launchpad.net/)
|
```powershell
|
||||||
2. Create PPA: `ppa:samson-media/barn`
|
"C:\Program Files\Barn\uninstall.exe" /S
|
||||||
3. Upload source package with `dput`
|
```
|
||||||
4. Users add: `sudo add-apt-repository ppa:samson-media/barn`
|
|
||||||
|
### Updating
|
||||||
|
|
||||||
|
To update Barn on Windows:
|
||||||
|
|
||||||
|
1. Download the latest setup installer
|
||||||
|
2. Run the installer - it will automatically stop the service, update the binary, and restart the service
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Linux PKGBUILD (pacman/AUR)
|
## Linux
|
||||||
|
|
||||||
### PKGBUILD File
|
Linux users install Barn by downloading the native binary directly from GitHub Releases.
|
||||||
|
|
||||||
File: `packaging/aur/PKGBUILD`
|
### Download
|
||||||
|
|
||||||
|
Download the appropriate binary for your architecture:
|
||||||
|
|
||||||
|
- **x86_64**: `barn-linux-x64`
|
||||||
|
- **ARM64**: `barn-linux-arm64`
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Maintainer: Samson Media <support@samson-media.com>
|
# Download (x86_64 example)
|
||||||
pkgname=barn
|
curl -LO https://github.com/samson-media/barn/releases/download/v1.2.3/barn-linux-x64
|
||||||
pkgver=1.2.3
|
|
||||||
pkgrel=1
|
|
||||||
pkgdesc="Cross-platform job daemon for media processing"
|
|
||||||
arch=('x86_64' 'aarch64')
|
|
||||||
url="https://github.com/samson-media/barn"
|
|
||||||
license=('MIT')
|
|
||||||
depends=('glibc')
|
|
||||||
provides=('barn')
|
|
||||||
conflicts=('barn-git')
|
|
||||||
source_x86_64=("${pkgname}-${pkgver}-x86_64::https://github.com/samson-media/barn/releases/download/v${pkgver}/barn-linux-x64")
|
|
||||||
source_aarch64=("${pkgname}-${pkgver}-aarch64::https://github.com/samson-media/barn/releases/download/v${pkgver}/barn-linux-arm64")
|
|
||||||
sha256sums_x86_64=('SKIP') # Replace with actual hash
|
|
||||||
sha256sums_aarch64=('SKIP') # Replace with actual hash
|
|
||||||
|
|
||||||
package() {
|
# Verify checksum
|
||||||
install -Dm755 "${srcdir}/${pkgname}-${pkgver}-${CARCH}" "${pkgdir}/usr/bin/barn"
|
curl -LO https://github.com/samson-media/barn/releases/download/v1.2.3/SHA256SUMS
|
||||||
install -Dm644 "${srcdir}/barn.service" "${pkgdir}/usr/lib/systemd/system/barn.service"
|
sha256sum -c SHA256SUMS --ignore-missing
|
||||||
}
|
|
||||||
|
# Install
|
||||||
|
chmod +x barn-linux-x64
|
||||||
|
sudo mv barn-linux-x64 /usr/local/bin/barn
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
barn --version
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install Script
|
### Setting Up the Service
|
||||||
|
|
||||||
File: `packaging/aur/barn.install`
|
After installing the binary, set up the systemd service:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
post_install() {
|
# Install the service
|
||||||
systemctl daemon-reload
|
barn service install
|
||||||
echo ":: Run 'systemctl enable --now barn.service' to start Barn"
|
|
||||||
}
|
|
||||||
|
|
||||||
post_upgrade() {
|
# Enable and start the service
|
||||||
systemctl daemon-reload
|
sudo systemctl enable barn
|
||||||
systemctl try-restart barn.service
|
sudo systemctl start barn
|
||||||
}
|
|
||||||
|
|
||||||
pre_remove() {
|
# Verify
|
||||||
systemctl stop barn.service || true
|
barn service status
|
||||||
systemctl disable barn.service || true
|
|
||||||
}
|
|
||||||
|
|
||||||
post_remove() {
|
|
||||||
systemctl daemon-reload
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### AUR Submission
|
### Updating
|
||||||
|
|
||||||
1. Create account at [AUR](https://aur.archlinux.org/)
|
To update Barn on Linux:
|
||||||
2. Add SSH key to account
|
|
||||||
3. Clone AUR package base:
|
|
||||||
```bash
|
|
||||||
git clone ssh://aur@aur.archlinux.org/barn.git
|
|
||||||
```
|
|
||||||
4. Add PKGBUILD and .SRCINFO:
|
|
||||||
```bash
|
|
||||||
makepkg --printsrcinfo > .SRCINFO
|
|
||||||
```
|
|
||||||
5. Commit and push:
|
|
||||||
```bash
|
|
||||||
git add PKGBUILD .SRCINFO barn.install
|
|
||||||
git commit -m "Update to version 1.2.3"
|
|
||||||
git push
|
|
||||||
```
|
|
||||||
|
|
||||||
### Updating AUR Package
|
1. Download the new binary from GitHub Releases
|
||||||
|
2. Stop the service: `sudo systemctl stop barn`
|
||||||
AUR updates are **automated** via GitHub Actions. See [CI/CD](ci-cd.md#aur-update-workflow) for the workflow details.
|
3. Replace the binary: `sudo mv barn-linux-x64 /usr/local/bin/barn`
|
||||||
|
4. Start the service: `sudo systemctl start barn`
|
||||||
If manual update is needed:
|
|
||||||
|
|
||||||
1. Update `pkgver` in PKGBUILD
|
|
||||||
2. Update SHA256 checksums
|
|
||||||
3. Regenerate .SRCINFO
|
|
||||||
4. Commit and push
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Clone the AUR repo
|
|
||||||
git clone ssh://aur@aur.archlinux.org/barn.git aur-barn
|
|
||||||
cd aur-barn
|
|
||||||
|
|
||||||
# Update version
|
|
||||||
sed -i "s/pkgver=.*/pkgver=1.2.4/" PKGBUILD
|
|
||||||
|
|
||||||
# Get new checksums from GitHub release
|
|
||||||
curl -sL https://github.com/samson-media/barn/releases/download/v1.2.4/SHA256SUMS
|
|
||||||
|
|
||||||
# Update checksums in PKGBUILD
|
|
||||||
# Edit sha256sums_x86_64 and sha256sums_aarch64
|
|
||||||
|
|
||||||
# Regenerate .SRCINFO
|
|
||||||
makepkg --printsrcinfo > .SRCINFO
|
|
||||||
|
|
||||||
# Commit and push
|
|
||||||
git add PKGBUILD .SRCINFO
|
|
||||||
git commit -m "Update to version 1.2.4"
|
|
||||||
git push
|
|
||||||
```
|
|
||||||
|
|
||||||
### Initial AUR Setup
|
|
||||||
|
|
||||||
Before the first release, create the AUR package:
|
|
||||||
|
|
||||||
1. **Create AUR Account**
|
|
||||||
- Register at https://aur.archlinux.org/register/
|
|
||||||
- Verify email and log in
|
|
||||||
|
|
||||||
2. **Add SSH Key**
|
|
||||||
```bash
|
|
||||||
ssh-keygen -t ed25519 -C "aur" -f ~/.ssh/aur
|
|
||||||
```
|
|
||||||
- Add public key at https://aur.archlinux.org/account/
|
|
||||||
- Configure SSH:
|
|
||||||
```
|
|
||||||
# ~/.ssh/config
|
|
||||||
Host aur.archlinux.org
|
|
||||||
IdentityFile ~/.ssh/aur
|
|
||||||
User aur
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Create Package Base**
|
|
||||||
```bash
|
|
||||||
git clone ssh://aur@aur.archlinux.org/barn.git
|
|
||||||
cd barn
|
|
||||||
# Directory will be empty for new packages
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **Add Package Files**
|
|
||||||
```bash
|
|
||||||
# Copy PKGBUILD, barn.install, barn.service from packaging/aur/
|
|
||||||
cp /path/to/packaging/aur/* .
|
|
||||||
|
|
||||||
# Generate .SRCINFO
|
|
||||||
makepkg --printsrcinfo > .SRCINFO
|
|
||||||
|
|
||||||
# Initial commit
|
|
||||||
git add PKGBUILD .SRCINFO barn.install barn.service
|
|
||||||
git commit -m "Initial package submission"
|
|
||||||
git push
|
|
||||||
```
|
|
||||||
|
|
||||||
5. **Verify Package**
|
|
||||||
- Check https://aur.archlinux.org/packages/barn
|
|
||||||
- Test installation:
|
|
||||||
```bash
|
|
||||||
yay -S barn # or paru -S barn
|
|
||||||
```
|
|
||||||
|
|
||||||
### AUR Best Practices
|
|
||||||
|
|
||||||
- **Test locally** before pushing: `makepkg -si`
|
|
||||||
- **Bump pkgrel** for packaging changes (same upstream version)
|
|
||||||
- **Reset pkgrel to 1** when pkgver changes
|
|
||||||
- **Respond to comments** on AUR package page
|
|
||||||
- **Flag out-of-date** packages if automation fails
|
|
||||||
|
|
||||||
### barn-git Package (Optional)
|
|
||||||
|
|
||||||
For users who want the latest development version, consider maintaining a `-git` package:
|
|
||||||
|
|
||||||
File: `packaging/aur-git/PKGBUILD`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Maintainer: Samson Media <support@samson-media.com>
|
|
||||||
pkgname=barn-git
|
|
||||||
pkgver=r123.abc1234
|
|
||||||
pkgrel=1
|
|
||||||
pkgdesc="Cross-platform job daemon for media processing (development version)"
|
|
||||||
arch=('x86_64' 'aarch64')
|
|
||||||
url="https://github.com/samson-media/barn"
|
|
||||||
license=('MIT')
|
|
||||||
depends=('glibc')
|
|
||||||
makedepends=('git' 'graalvm-jdk' 'gradle')
|
|
||||||
provides=('barn')
|
|
||||||
conflicts=('barn')
|
|
||||||
source=("git+https://github.com/samson-media/barn.git")
|
|
||||||
sha256sums=('SKIP')
|
|
||||||
|
|
||||||
pkgver() {
|
|
||||||
cd barn
|
|
||||||
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
|
||||||
}
|
|
||||||
|
|
||||||
build() {
|
|
||||||
cd barn
|
|
||||||
./gradlew nativeCompile
|
|
||||||
}
|
|
||||||
|
|
||||||
package() {
|
|
||||||
cd barn
|
|
||||||
install -Dm755 "build/native/nativeCompile/barn" "${pkgdir}/usr/bin/barn"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -676,10 +261,8 @@ barn --version
|
|||||||
|
|
||||||
After publishing a GitHub Release:
|
After publishing a GitHub Release:
|
||||||
|
|
||||||
1. **Windows**: Submit WinGet manifest PR
|
1. **Homebrew**: Formula auto-updates via GitHub Actions workflow
|
||||||
2. **Arch Linux**: Update AUR PKGBUILD
|
2. **Windows/Linux**: Binaries and setup installer available on GitHub Releases (manual download)
|
||||||
3. **Homebrew**: Formula auto-updates via workflow
|
|
||||||
4. **Debian**: .deb available on GitHub Releases
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+269
@@ -0,0 +1,269 @@
|
|||||||
|
# Barn Installer Script for Windows
|
||||||
|
# Usage: iwr -useb https://raw.githubusercontent.com/samson-media/barn/main/install.ps1 | iex
|
||||||
|
#
|
||||||
|
# This script installs the Barn job daemon and sets it up to run on startup.
|
||||||
|
# Requires: PowerShell 5.1+ and Administrator privileges (for Windows Service)
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$NoService,
|
||||||
|
[string]$InstallDir = "$env:ProgramFiles\barn",
|
||||||
|
[string]$BarnDir = "$env:LOCALAPPDATA\barn"
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
$Repo = "samson-media/barn"
|
||||||
|
$ServiceName = "barn"
|
||||||
|
$ServiceDisplayName = "Barn Job Daemon"
|
||||||
|
|
||||||
|
function Write-Info {
|
||||||
|
param([string]$Message)
|
||||||
|
Write-Host "[INFO] " -ForegroundColor Green -NoNewline
|
||||||
|
Write-Host $Message
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Warn {
|
||||||
|
param([string]$Message)
|
||||||
|
Write-Host "[WARN] " -ForegroundColor Yellow -NoNewline
|
||||||
|
Write-Host $Message
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Err {
|
||||||
|
param([string]$Message)
|
||||||
|
Write-Host "[ERROR] " -ForegroundColor Red -NoNewline
|
||||||
|
Write-Host $Message
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-Administrator {
|
||||||
|
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
|
||||||
|
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-LatestVersion {
|
||||||
|
Write-Info "Getting latest version..."
|
||||||
|
try {
|
||||||
|
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
|
||||||
|
$version = $release.tag_name
|
||||||
|
Write-Info "Latest version: $version"
|
||||||
|
return $version
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Err "Failed to get latest version: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-Binary {
|
||||||
|
param([string]$Version)
|
||||||
|
|
||||||
|
$binaryName = "barn-windows-x64.exe"
|
||||||
|
$downloadUrl = "https://github.com/$Repo/releases/download/$Version/$binaryName"
|
||||||
|
|
||||||
|
Write-Info "Downloading $binaryName..."
|
||||||
|
|
||||||
|
# Create install directory
|
||||||
|
if (-not (Test-Path $InstallDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$destPath = Join-Path $InstallDir "barn.exe"
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Download with progress
|
||||||
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $destPath -UseBasicParsing
|
||||||
|
$ProgressPreference = 'Continue'
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Err "Failed to download binary: $_"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify it works
|
||||||
|
try {
|
||||||
|
$versionOutput = & $destPath --version 2>&1
|
||||||
|
Write-Info "Installed: $versionOutput"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Err "Downloaded binary is not executable or corrupted"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Info "Installed barn to $destPath"
|
||||||
|
return $destPath
|
||||||
|
}
|
||||||
|
|
||||||
|
function Add-ToPath {
|
||||||
|
param([string]$Directory)
|
||||||
|
|
||||||
|
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
|
||||||
|
if ($currentPath -notlike "*$Directory*") {
|
||||||
|
Write-Info "Adding $Directory to system PATH..."
|
||||||
|
$newPath = "$currentPath;$Directory"
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $newPath, "Machine")
|
||||||
|
$env:Path = "$env:Path;$Directory"
|
||||||
|
Write-Info "Added to PATH. You may need to restart your terminal."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Info "$Directory is already in PATH"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-WindowsService {
|
||||||
|
param([string]$BinaryPath)
|
||||||
|
|
||||||
|
Write-Info "Setting up Windows Service..."
|
||||||
|
|
||||||
|
# Create barn data directory
|
||||||
|
if (-not (Test-Path $BarnDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $BarnDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if service already exists
|
||||||
|
$existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if ($existingService) {
|
||||||
|
Write-Info "Stopping existing service..."
|
||||||
|
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
|
||||||
|
Write-Info "Removing existing service..."
|
||||||
|
sc.exe delete $ServiceName | Out-Null
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the service using sc.exe
|
||||||
|
$binPath = "`"$BinaryPath`" service start --foreground --barn-dir `"$BarnDir`""
|
||||||
|
|
||||||
|
Write-Info "Creating service..."
|
||||||
|
$result = sc.exe create $ServiceName binPath= $binPath DisplayName= $ServiceDisplayName start= auto
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Err "Failed to create service: $result"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set description
|
||||||
|
sc.exe description $ServiceName "Cross-platform job daemon for media processing" | Out-Null
|
||||||
|
|
||||||
|
# Configure failure recovery (restart after 5 seconds)
|
||||||
|
sc.exe failure $ServiceName reset= 86400 actions= restart/5000/restart/5000/restart/5000 | Out-Null
|
||||||
|
|
||||||
|
Write-Info "Service created: $ServiceName"
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
Write-Info "Starting service..."
|
||||||
|
Start-Service -Name $ServiceName
|
||||||
|
|
||||||
|
# Verify it's running
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
$service = Get-Service -Name $ServiceName
|
||||||
|
if ($service.Status -eq "Running") {
|
||||||
|
Write-Info "Service is running"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Warn "Service may not have started correctly. Status: $($service.Status)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-ScheduledTask {
|
||||||
|
param([string]$BinaryPath)
|
||||||
|
|
||||||
|
Write-Info "Setting up Scheduled Task (user mode)..."
|
||||||
|
|
||||||
|
# Create barn data directory
|
||||||
|
if (-not (Test-Path $BarnDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $BarnDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$taskName = "BarnJobDaemon"
|
||||||
|
|
||||||
|
# Remove existing task if present
|
||||||
|
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
||||||
|
if ($existingTask) {
|
||||||
|
Write-Info "Removing existing scheduled task..."
|
||||||
|
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create action
|
||||||
|
$action = New-ScheduledTaskAction -Execute $BinaryPath -Argument "service start --foreground --barn-dir `"$BarnDir`""
|
||||||
|
|
||||||
|
# Create trigger (at logon)
|
||||||
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
|
||||||
|
|
||||||
|
# Create settings
|
||||||
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
|
||||||
|
|
||||||
|
# Register task
|
||||||
|
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description "Barn Job Daemon" | Out-Null
|
||||||
|
|
||||||
|
Write-Info "Scheduled task created: $taskName"
|
||||||
|
|
||||||
|
# Start the task now
|
||||||
|
Write-Info "Starting barn..."
|
||||||
|
Start-ScheduledTask -TaskName $taskName
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
Write-Info "Barn is running"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Main {
|
||||||
|
Write-Host "========================================"
|
||||||
|
Write-Host " Barn Installer for Windows"
|
||||||
|
Write-Host "========================================"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$isAdmin = Test-Administrator
|
||||||
|
|
||||||
|
if (-not $isAdmin) {
|
||||||
|
Write-Warn "Not running as Administrator."
|
||||||
|
Write-Warn "Will install for current user only (using Scheduled Task instead of Windows Service)."
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# Adjust install directory for non-admin
|
||||||
|
$InstallDir = Join-Path $env:LOCALAPPDATA "barn"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Info "Install directory: $InstallDir"
|
||||||
|
Write-Info "Data directory: $BarnDir"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$version = Get-LatestVersion
|
||||||
|
$binaryPath = Install-Binary -Version $version
|
||||||
|
|
||||||
|
if ($isAdmin) {
|
||||||
|
Add-ToPath -Directory $InstallDir
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Add to user PATH
|
||||||
|
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
|
if ($currentPath -notlike "*$InstallDir*") {
|
||||||
|
Write-Info "Adding $InstallDir to user PATH..."
|
||||||
|
$newPath = "$currentPath;$InstallDir"
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
|
||||||
|
$env:Path = "$env:Path;$InstallDir"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $NoService) {
|
||||||
|
if ($isAdmin) {
|
||||||
|
Install-WindowsService -BinaryPath $binaryPath
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Install-ScheduledTask -BinaryPath $binaryPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Info "Skipping service setup (use -NoService to disable)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "========================================"
|
||||||
|
Write-Info "Barn installation complete!"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Commands:"
|
||||||
|
Write-Host " barn status - Show job status"
|
||||||
|
Write-Host " barn run -- <cmd> - Run a command as a job"
|
||||||
|
Write-Host " barn service status - Show service status"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Data directory: $BarnDir"
|
||||||
|
Write-Host "========================================"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main
|
||||||
|
Main
|
||||||
Executable
+307
@@ -0,0 +1,307 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Barn Installer Script
|
||||||
|
# Usage: curl -fsSL https://raw.githubusercontent.com/samson-media/barn/main/install.sh | sh
|
||||||
|
#
|
||||||
|
# This script installs the Barn job daemon and sets it up to run on startup.
|
||||||
|
# Supports: Linux (systemd), macOS (launchd)
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
REPO="samson-media/barn"
|
||||||
|
INSTALL_DIR="/usr/local/bin"
|
||||||
|
BARN_DIR="" # Will be set based on OS
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Print functions
|
||||||
|
info() {
|
||||||
|
printf "${GREEN}[INFO]${NC} %s\n" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
printf "${YELLOW}[WARN]${NC} %s\n" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
printf "${RED}[ERROR]${NC} %s\n" "$1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect OS
|
||||||
|
detect_os() {
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Linux*) OS="linux" ;;
|
||||||
|
Darwin*) OS="macos" ;;
|
||||||
|
*) error "Unsupported operating system: $(uname -s)" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect architecture
|
||||||
|
detect_arch() {
|
||||||
|
case "$(uname -m)" in
|
||||||
|
x86_64|amd64) ARCH="x64" ;;
|
||||||
|
aarch64|arm64) ARCH="arm64" ;;
|
||||||
|
*) error "Unsupported architecture: $(uname -m)" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get latest release version
|
||||||
|
get_latest_version() {
|
||||||
|
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
error "Failed to get latest version"
|
||||||
|
fi
|
||||||
|
info "Latest version: $VERSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download and install binary
|
||||||
|
install_binary() {
|
||||||
|
BINARY_NAME="barn-${OS}-${ARCH}"
|
||||||
|
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}"
|
||||||
|
|
||||||
|
info "Downloading $BINARY_NAME..."
|
||||||
|
|
||||||
|
# Create temp directory
|
||||||
|
TMP_DIR=$(mktemp -d)
|
||||||
|
trap "rm -rf $TMP_DIR" EXIT
|
||||||
|
|
||||||
|
# Download binary
|
||||||
|
if ! curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/barn"; then
|
||||||
|
error "Failed to download binary from $DOWNLOAD_URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make executable
|
||||||
|
chmod +x "$TMP_DIR/barn"
|
||||||
|
|
||||||
|
# Verify it works
|
||||||
|
if ! "$TMP_DIR/barn" --version > /dev/null 2>&1; then
|
||||||
|
error "Downloaded binary is not executable or corrupted"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install to destination
|
||||||
|
if [ -w "$INSTALL_DIR" ]; then
|
||||||
|
mv "$TMP_DIR/barn" "$INSTALL_DIR/barn"
|
||||||
|
else
|
||||||
|
info "Installing to $INSTALL_DIR requires sudo..."
|
||||||
|
sudo mv "$TMP_DIR/barn" "$INSTALL_DIR/barn"
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Installed barn to $INSTALL_DIR/barn"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setup systemd service (Linux)
|
||||||
|
setup_systemd() {
|
||||||
|
info "Setting up systemd service..."
|
||||||
|
|
||||||
|
# Determine if we should use user or system service
|
||||||
|
if [ "$(id -u)" -eq 0 ]; then
|
||||||
|
# Running as root - install system service
|
||||||
|
SERVICE_FILE="/etc/systemd/system/barn.service"
|
||||||
|
BARN_DIR="/var/lib/barn"
|
||||||
|
USER_MODE=""
|
||||||
|
SYSTEMCTL_CMD="systemctl"
|
||||||
|
else
|
||||||
|
# Running as user - install user service
|
||||||
|
SERVICE_FILE="$HOME/.config/systemd/user/barn.service"
|
||||||
|
BARN_DIR="$HOME/.local/share/barn"
|
||||||
|
USER_MODE="--user"
|
||||||
|
SYSTEMCTL_CMD="systemctl --user"
|
||||||
|
|
||||||
|
# Create directory if needed
|
||||||
|
mkdir -p "$(dirname "$SERVICE_FILE")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create barn data directory
|
||||||
|
mkdir -p "$BARN_DIR"
|
||||||
|
|
||||||
|
# Generate service file
|
||||||
|
if [ -n "$USER_MODE" ]; then
|
||||||
|
# User service
|
||||||
|
cat > "$SERVICE_FILE" << EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Barn Job Daemon (User)
|
||||||
|
Documentation=https://github.com/samson-media/barn
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=$INSTALL_DIR/barn service start --foreground --barn-dir $BARN_DIR
|
||||||
|
ExecStop=$INSTALL_DIR/barn service stop --barn-dir $BARN_DIR
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
# System service
|
||||||
|
sudo tee "$SERVICE_FILE" > /dev/null << EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Barn Job Daemon
|
||||||
|
Documentation=https://github.com/samson-media/barn
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=$INSTALL_DIR/barn service start --foreground --barn-dir $BARN_DIR
|
||||||
|
ExecStop=$INSTALL_DIR/barn service stop --barn-dir $BARN_DIR
|
||||||
|
ExecReload=/bin/kill -HUP \$MAINPID
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
# Security hardening
|
||||||
|
NoNewPrivileges=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
ProtectHome=read-only
|
||||||
|
PrivateTmp=false
|
||||||
|
ReadWritePaths=$BARN_DIR
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
SyslogIdentifier=barn
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Created service file: $SERVICE_FILE"
|
||||||
|
|
||||||
|
# Reload systemd
|
||||||
|
$SYSTEMCTL_CMD daemon-reload
|
||||||
|
|
||||||
|
# Enable service
|
||||||
|
$SYSTEMCTL_CMD enable barn
|
||||||
|
info "Enabled barn service to start on boot"
|
||||||
|
|
||||||
|
# Start service
|
||||||
|
$SYSTEMCTL_CMD start barn
|
||||||
|
info "Started barn service"
|
||||||
|
|
||||||
|
# Show status
|
||||||
|
$SYSTEMCTL_CMD status barn --no-pager || true
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setup launchd service (macOS)
|
||||||
|
setup_launchd() {
|
||||||
|
info "Setting up launchd service..."
|
||||||
|
|
||||||
|
# Always install as user agent on macOS
|
||||||
|
PLIST_FILE="$HOME/Library/LaunchAgents/com.samsonmedia.barn.plist"
|
||||||
|
BARN_DIR="$HOME/Library/Application Support/barn"
|
||||||
|
LOGS_DIR="$BARN_DIR/logs"
|
||||||
|
|
||||||
|
# Create directories
|
||||||
|
mkdir -p "$(dirname "$PLIST_FILE")"
|
||||||
|
mkdir -p "$BARN_DIR"
|
||||||
|
mkdir -p "$LOGS_DIR"
|
||||||
|
|
||||||
|
# Generate plist file
|
||||||
|
cat > "$PLIST_FILE" << EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||||
|
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>com.samsonmedia.barn</string>
|
||||||
|
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>$INSTALL_DIR/barn</string>
|
||||||
|
<string>service</string>
|
||||||
|
<string>start</string>
|
||||||
|
<string>--foreground</string>
|
||||||
|
<string>--barn-dir</string>
|
||||||
|
<string>$BARN_DIR</string>
|
||||||
|
</array>
|
||||||
|
|
||||||
|
<key>RunAtLoad</key>
|
||||||
|
<true/>
|
||||||
|
|
||||||
|
<key>KeepAlive</key>
|
||||||
|
<true/>
|
||||||
|
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>$LOGS_DIR/barn.log</string>
|
||||||
|
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>$LOGS_DIR/barn.log</string>
|
||||||
|
|
||||||
|
<key>WorkingDirectory</key>
|
||||||
|
<string>$BARN_DIR</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
info "Created plist file: $PLIST_FILE"
|
||||||
|
|
||||||
|
# Unload if already loaded (ignore errors)
|
||||||
|
launchctl unload "$PLIST_FILE" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Load the service
|
||||||
|
launchctl load "$PLIST_FILE"
|
||||||
|
info "Loaded barn service into launchd"
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
launchctl start com.samsonmedia.barn
|
||||||
|
info "Started barn service"
|
||||||
|
|
||||||
|
# Verify it's running
|
||||||
|
sleep 2
|
||||||
|
if launchctl list | grep -q "com.samsonmedia.barn"; then
|
||||||
|
info "Barn service is running"
|
||||||
|
else
|
||||||
|
warn "Barn service may not have started correctly. Check logs at $LOGS_DIR/barn.log"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main installation function
|
||||||
|
main() {
|
||||||
|
echo "========================================"
|
||||||
|
echo " Barn Installer"
|
||||||
|
echo "========================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
detect_os
|
||||||
|
detect_arch
|
||||||
|
info "Detected: $OS-$ARCH"
|
||||||
|
|
||||||
|
get_latest_version
|
||||||
|
install_binary
|
||||||
|
|
||||||
|
# Setup service based on OS
|
||||||
|
case "$OS" in
|
||||||
|
linux)
|
||||||
|
if [ -d "/run/systemd/system" ]; then
|
||||||
|
setup_systemd
|
||||||
|
else
|
||||||
|
warn "systemd not detected. Barn installed but not configured to run on startup."
|
||||||
|
warn "You can manually run: barn service start"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
macos)
|
||||||
|
setup_launchd
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "========================================"
|
||||||
|
info "Barn installation complete!"
|
||||||
|
echo ""
|
||||||
|
echo "Commands:"
|
||||||
|
echo " barn status - Show job status"
|
||||||
|
echo " barn run -- <cmd> - Run a command as a job"
|
||||||
|
echo " barn service status - Show service status"
|
||||||
|
echo ""
|
||||||
|
echo "Data directory: $BARN_DIR"
|
||||||
|
echo "========================================"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main
|
||||||
|
main
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
; Barn Installer Script for Inno Setup
|
||||||
|
; This script generates a Windows setup.exe installer
|
||||||
|
; Build: iscc barn.iss (requires Inno Setup 6+)
|
||||||
|
|
||||||
|
#define AppName "Barn"
|
||||||
|
#define AppPublisher "Samson Media"
|
||||||
|
#define AppURL "https://github.com/samson-media/barn"
|
||||||
|
#define AppExeName "barn.exe"
|
||||||
|
|
||||||
|
; Version is passed from CI: iscc /DAppVersion=0.1.0 barn.iss
|
||||||
|
#ifndef AppVersion
|
||||||
|
#define AppVersion "0.0.0"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[Setup]
|
||||||
|
AppId={{7B8A9C5E-4D3F-2A1B-0E9D-8C7B6A5F4E3D}
|
||||||
|
AppName={#AppName}
|
||||||
|
AppVersion={#AppVersion}
|
||||||
|
AppVerName={#AppName} {#AppVersion}
|
||||||
|
AppPublisher={#AppPublisher}
|
||||||
|
AppPublisherURL={#AppURL}
|
||||||
|
AppSupportURL={#AppURL}/issues
|
||||||
|
DefaultDirName={autopf}\{#AppName}
|
||||||
|
DefaultGroupName={#AppName}
|
||||||
|
AllowNoIcons=yes
|
||||||
|
LicenseFile=..\LICENSE
|
||||||
|
OutputDir=..\dist
|
||||||
|
OutputBaseFilename=setup-barn-v{#AppVersion}-windows-x64
|
||||||
|
Compression=lzma2
|
||||||
|
SolidCompression=yes
|
||||||
|
WizardStyle=modern
|
||||||
|
PrivilegesRequired=admin
|
||||||
|
ArchitecturesAllowed=x64compatible
|
||||||
|
ArchitecturesInstallIn64BitMode=x64compatible
|
||||||
|
ChangesEnvironment=yes
|
||||||
|
|
||||||
|
[Languages]
|
||||||
|
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||||
|
|
||||||
|
[Tasks]
|
||||||
|
Name: "addtopath"; Description: "Add to PATH environment variable"; GroupDescription: "Additional options:"
|
||||||
|
Name: "installservice"; Description: "Install and start Windows Service"; GroupDescription: "Service options:"; Flags: checkedonce
|
||||||
|
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
|
||||||
|
|
||||||
|
[Files]
|
||||||
|
Source: "..\target\barn-windows-x64.exe"; DestDir: "{app}"; DestName: "{#AppExeName}"; Flags: ignoreversion
|
||||||
|
|
||||||
|
[Icons]
|
||||||
|
Name: "{group}\{#AppName} Status"; Filename: "{app}\{#AppExeName}"; Parameters: "status"
|
||||||
|
Name: "{group}\{#AppName} Service Status"; Filename: "{app}\{#AppExeName}"; Parameters: "service status"
|
||||||
|
Name: "{group}\Uninstall {#AppName}"; Filename: "{uninstallexe}"
|
||||||
|
Name: "{autodesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: desktopicon
|
||||||
|
|
||||||
|
[Registry]
|
||||||
|
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
|
||||||
|
ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
|
||||||
|
Tasks: addtopath; Check: NeedsAddPath('{app}')
|
||||||
|
|
||||||
|
[Run]
|
||||||
|
Filename: "{app}\{#AppExeName}"; Parameters: "service install"; \
|
||||||
|
StatusMsg: "Installing Windows Service..."; Tasks: installservice; Flags: runhidden
|
||||||
|
Filename: "{app}\{#AppExeName}"; Parameters: "service start"; \
|
||||||
|
StatusMsg: "Starting Barn service..."; Tasks: installservice; Flags: runhidden
|
||||||
|
|
||||||
|
[UninstallRun]
|
||||||
|
Filename: "{app}\{#AppExeName}"; Parameters: "service stop"; Flags: runhidden; RunOnceId: "StopService"
|
||||||
|
Filename: "{app}\{#AppExeName}"; Parameters: "service uninstall"; Flags: runhidden; RunOnceId: "UninstallService"
|
||||||
|
|
||||||
|
[Code]
|
||||||
|
function NeedsAddPath(Param: string): boolean;
|
||||||
|
var
|
||||||
|
OrigPath: string;
|
||||||
|
begin
|
||||||
|
if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
|
||||||
|
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
||||||
|
'Path', OrigPath)
|
||||||
|
then begin
|
||||||
|
Result := True;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
||||||
|
var
|
||||||
|
Path: string;
|
||||||
|
AppPath: string;
|
||||||
|
P: Integer;
|
||||||
|
begin
|
||||||
|
if CurUninstallStep = usPostUninstall then
|
||||||
|
begin
|
||||||
|
if RegQueryStringValue(HKEY_LOCAL_MACHINE,
|
||||||
|
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
||||||
|
'Path', Path) then
|
||||||
|
begin
|
||||||
|
AppPath := ExpandConstant('{app}');
|
||||||
|
P := Pos(';' + AppPath, Path);
|
||||||
|
if P > 0 then
|
||||||
|
begin
|
||||||
|
Delete(Path, P, Length(';' + AppPath));
|
||||||
|
RegWriteStringValue(HKEY_LOCAL_MACHINE,
|
||||||
|
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
||||||
|
'Path', Path);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.samsonmedia</groupId>
|
<groupId>com.samsonmedia</groupId>
|
||||||
<artifactId>barn</artifactId>
|
<artifactId>barn</artifactId>
|
||||||
<version>0.1.2</version>
|
<version>0.1.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Barn</name>
|
<name>Barn</name>
|
||||||
@@ -39,14 +39,13 @@
|
|||||||
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
|
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
|
||||||
<checkstyle-plugin.version>3.6.0</checkstyle-plugin.version>
|
<checkstyle-plugin.version>3.6.0</checkstyle-plugin.version>
|
||||||
<checkstyle.version>10.21.1</checkstyle.version>
|
<checkstyle.version>10.21.1</checkstyle.version>
|
||||||
<spotbugs-plugin.version>4.9.3.0</spotbugs-plugin.version>
|
<spotbugs-plugin.version>4.9.8.2</spotbugs-plugin.version>
|
||||||
<pmd-plugin.version>3.26.0</pmd-plugin.version>
|
|
||||||
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
|
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
|
||||||
<native-maven-plugin.version>0.10.4</native-maven-plugin.version>
|
<native-maven-plugin.version>0.10.4</native-maven-plugin.version>
|
||||||
|
|
||||||
<!-- Code Quality Thresholds -->
|
<!-- Code Quality Thresholds -->
|
||||||
<jacoco.line.coverage>0.68</jacoco.line.coverage>
|
<jacoco.line.coverage>0.68</jacoco.line.coverage>
|
||||||
<jacoco.branch.coverage>0.58</jacoco.branch.coverage>
|
<jacoco.branch.coverage>0.57</jacoco.branch.coverage>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -90,7 +89,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.spotbugs</groupId>
|
<groupId>com.github.spotbugs</groupId>
|
||||||
<artifactId>spotbugs-annotations</artifactId>
|
<artifactId>spotbugs-annotations</artifactId>
|
||||||
<version>4.8.6</version>
|
<version>4.9.8</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -287,31 +286,6 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- PMD - Static Analysis -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-pmd-plugin</artifactId>
|
|
||||||
<version>${pmd-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<rulesets>
|
|
||||||
<ruleset>config/pmd/ruleset.xml</ruleset>
|
|
||||||
</rulesets>
|
|
||||||
<failOnViolation>true</failOnViolation>
|
|
||||||
<printFailingErrors>true</printFailingErrors>
|
|
||||||
<includeTests>true</includeTests>
|
|
||||||
<targetJdk>${maven.compiler.target}</targetJdk>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>pmd-check</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- JaCoCo - Code Coverage -->
|
<!-- JaCoCo - Code Coverage -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
@@ -407,7 +381,6 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<checkstyle.skip>true</checkstyle.skip>
|
<checkstyle.skip>true</checkstyle.skip>
|
||||||
<spotbugs.skip>true</spotbugs.skip>
|
<spotbugs.skip>true</spotbugs.skip>
|
||||||
<pmd.skip>true</pmd.skip>
|
|
||||||
<jacoco.skip>true</jacoco.skip>
|
<jacoco.skip>true</jacoco.skip>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
@@ -432,11 +405,6 @@
|
|||||||
<artifactId>spotbugs-maven-plugin</artifactId>
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
<version>${spotbugs-plugin.version}</version>
|
<version>${spotbugs-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-pmd-plugin</artifactId>
|
|
||||||
<version>${pmd-plugin.version}</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -24,6 +21,7 @@ import com.samsonmedia.barn.ipc.IpcClient;
|
|||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
import com.samsonmedia.barn.util.DurationParser;
|
import com.samsonmedia.barn.util.DurationParser;
|
||||||
@@ -41,7 +39,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class CleanCommand extends BaseCommand {
|
public class CleanCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CleanCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(CleanCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--all"}, description = "Remove all completed jobs regardless of age")
|
@Option(names = {"--all"}, description = "Remove all completed jobs regardless of age")
|
||||||
private boolean all;
|
private boolean all;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.samsonmedia.barn.cli;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.CleanupConfig;
|
import com.samsonmedia.barn.config.CleanupConfig;
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
@@ -71,7 +72,7 @@ public class ConfigInitCommand extends BaseCommand {
|
|||||||
sb.append("[service]\n");
|
sb.append("[service]\n");
|
||||||
sb.append("# Logging verbosity: debug, info, warn, error\n");
|
sb.append("# Logging verbosity: debug, info, warn, error\n");
|
||||||
sb.append(String.format("log_level = \"%s\"%n",
|
sb.append(String.format("log_level = \"%s\"%n",
|
||||||
ServiceConfig.DEFAULT_LOG_LEVEL.toString().toLowerCase()));
|
ServiceConfig.DEFAULT_LOG_LEVEL.toString().toLowerCase(Locale.ROOT)));
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
sb.append("# Maximum jobs running simultaneously\n");
|
sb.append("# Maximum jobs running simultaneously\n");
|
||||||
sb.append(String.format("max_concurrent_jobs = %d%n", ServiceConfig.DEFAULT_MAX_CONCURRENT_JOBS));
|
sb.append(String.format("max_concurrent_jobs = %d%n", ServiceConfig.DEFAULT_MAX_CONCURRENT_JOBS));
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.samsonmedia.barn.cli;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -49,8 +50,7 @@ public class ConfigShowCommand extends BaseCommand {
|
|||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case HUMAN -> outputHumanFormat(config, effectiveConfigFile);
|
case HUMAN -> outputHumanFormat(config, effectiveConfigFile);
|
||||||
case JSON -> output(toMap(config));
|
case JSON, XML -> output(toMap(config));
|
||||||
case XML -> output(toMap(config));
|
|
||||||
default -> outputHumanFormat(config, effectiveConfigFile);
|
default -> outputHumanFormat(config, effectiveConfigFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class ConfigShowCommand extends BaseCommand {
|
|||||||
|
|
||||||
// Service section
|
// Service section
|
||||||
sb.append("[service]\n");
|
sb.append("[service]\n");
|
||||||
sb.append(String.format("log_level = %s%n", config.service().logLevel().toString().toLowerCase()));
|
sb.append(String.format("log_level = %s%n", config.service().logLevel().toString().toLowerCase(Locale.ROOT)));
|
||||||
sb.append(String.format("max_concurrent_jobs = %d%n", config.service().maxConcurrentJobs()));
|
sb.append(String.format("max_concurrent_jobs = %d%n", config.service().maxConcurrentJobs()));
|
||||||
sb.append(String.format("heartbeat_interval_seconds = %d%n", config.service().heartbeatIntervalSeconds()));
|
sb.append(String.format("heartbeat_interval_seconds = %d%n", config.service().heartbeatIntervalSeconds()));
|
||||||
sb.append(String.format("ipc_socket = %s%n", config.service().ipcSocket()));
|
sb.append(String.format("ipc_socket = %s%n", config.service().ipcSocket()));
|
||||||
@@ -136,7 +136,7 @@ public class ConfigShowCommand extends BaseCommand {
|
|||||||
|
|
||||||
private Map<String, Object> buildServiceSection(Config config) {
|
private Map<String, Object> buildServiceSection(Config config) {
|
||||||
Map<String, Object> service = new LinkedHashMap<>();
|
Map<String, Object> service = new LinkedHashMap<>();
|
||||||
service.put("log_level", config.service().logLevel().toString().toLowerCase());
|
service.put("log_level", config.service().logLevel().toString().toLowerCase(Locale.ROOT));
|
||||||
service.put("max_concurrent_jobs", config.service().maxConcurrentJobs());
|
service.put("max_concurrent_jobs", config.service().maxConcurrentJobs());
|
||||||
service.put("heartbeat_interval_seconds", config.service().heartbeatIntervalSeconds());
|
service.put("heartbeat_interval_seconds", config.service().heartbeatIntervalSeconds());
|
||||||
service.put("ipc_socket", config.service().ipcSocket().toString());
|
service.put("ipc_socket", config.service().ipcSocket().toString());
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -225,7 +226,7 @@ public class ConfigValidateCommand extends BaseCommand {
|
|||||||
if (section.containsKey(key)) {
|
if (section.containsKey(key)) {
|
||||||
Object value = section.get(key);
|
Object value = section.get(key);
|
||||||
if (!(value instanceof Boolean)) {
|
if (!(value instanceof Boolean)) {
|
||||||
String strValue = value.toString().toLowerCase();
|
String strValue = value.toString().toLowerCase(Locale.ROOT);
|
||||||
if (!strValue.equals("true") && !strValue.equals("false")) {
|
if (!strValue.equals("true") && !strValue.equals("false")) {
|
||||||
errors.add(new ValidationError(0, key,
|
errors.add(new ValidationError(0, key,
|
||||||
"Invalid value for '" + key + "': must be true or false"));
|
"Invalid value for '" + key + "': must be true or false"));
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import java.time.ZoneId;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
@@ -26,6 +24,7 @@ import com.samsonmedia.barn.ipc.IpcException;
|
|||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobManifest;
|
import com.samsonmedia.barn.jobs.JobManifest;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
@@ -42,7 +41,7 @@ import picocli.CommandLine.Parameters;
|
|||||||
)
|
)
|
||||||
public class DescribeCommand extends BaseCommand {
|
public class DescribeCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DescribeCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(DescribeCommand.class);
|
||||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||||
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
.withZone(ZoneId.systemDefault());
|
.withZone(ZoneId.systemDefault());
|
||||||
@@ -169,7 +168,7 @@ public class DescribeCommand extends BaseCommand {
|
|||||||
sb.append("================================================================================\n");
|
sb.append("================================================================================\n");
|
||||||
|
|
||||||
// Basic info
|
// Basic info
|
||||||
sb.append("State: ").append(job.state().toString().toLowerCase()).append("\n");
|
sb.append("State: ").append(job.state().toString().toLowerCase(Locale.ROOT)).append("\n");
|
||||||
if (job.tag() != null) {
|
if (job.tag() != null) {
|
||||||
sb.append("Tag: ").append(job.tag()).append("\n");
|
sb.append("Tag: ").append(job.tag()).append("\n");
|
||||||
}
|
}
|
||||||
@@ -239,7 +238,7 @@ public class DescribeCommand extends BaseCommand {
|
|||||||
|
|
||||||
// Job details
|
// Job details
|
||||||
response.put("id", job.id());
|
response.put("id", job.id());
|
||||||
response.put("state", job.state().toString().toLowerCase());
|
response.put("state", job.state().toString().toLowerCase(Locale.ROOT));
|
||||||
response.put("tag", job.tag());
|
response.put("tag", job.tag());
|
||||||
response.put("command", job.command());
|
response.put("command", job.command());
|
||||||
response.put("createdAt", job.createdAt());
|
response.put("createdAt", job.createdAt());
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.time.ZoneId;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
@@ -145,7 +146,7 @@ public class HumanFormatter implements OutputFormatter {
|
|||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
rows.add(List.of(
|
rows.add(List.of(
|
||||||
job.id(),
|
job.id(),
|
||||||
job.state().toString().toLowerCase(),
|
job.state().toString().toLowerCase(Locale.ROOT),
|
||||||
job.tag() != null ? job.tag() : "-",
|
job.tag() != null ? job.tag() : "-",
|
||||||
formatTimestamp(job.createdAt()),
|
formatTimestamp(job.createdAt()),
|
||||||
job.exitCode() != null ? job.exitCode().toString() : "-"
|
job.exitCode() != null ? job.exitCode().toString() : "-"
|
||||||
@@ -229,7 +230,7 @@ public class HumanFormatter implements OutputFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String colorizeState(JobState state) {
|
private String colorizeState(JobState state) {
|
||||||
return colorizeState(state, state.toString().toLowerCase());
|
return colorizeState(state, state.toString().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String colorizeState(JobState state, String text) {
|
private String colorizeState(JobState state, String text) {
|
||||||
@@ -237,7 +238,7 @@ public class HumanFormatter implements OutputFormatter {
|
|||||||
case QUEUED -> colorize(text, CYAN);
|
case QUEUED -> colorize(text, CYAN);
|
||||||
case RUNNING -> colorize(text, YELLOW);
|
case RUNNING -> colorize(text, YELLOW);
|
||||||
case SUCCEEDED -> colorize(text, GREEN);
|
case SUCCEEDED -> colorize(text, GREEN);
|
||||||
case FAILED -> colorize(text, RED);
|
case FAILED, KILLED -> colorize(text, RED);
|
||||||
case CANCELED -> text;
|
case CANCELED -> text;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
@@ -18,6 +15,7 @@ import com.samsonmedia.barn.ipc.IpcClient;
|
|||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
@@ -35,7 +33,7 @@ import picocli.CommandLine.Parameters;
|
|||||||
)
|
)
|
||||||
public class KillCommand extends BaseCommand {
|
public class KillCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(KillCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(KillCommand.class);
|
||||||
|
|
||||||
@Parameters(index = "0", description = "Job ID")
|
@Parameters(index = "0", description = "Job ID")
|
||||||
private String jobId;
|
private String jobId;
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
@@ -18,6 +16,7 @@ import com.samsonmedia.barn.ipc.IpcClient;
|
|||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
@@ -37,7 +36,7 @@ import picocli.CommandLine.Parameters;
|
|||||||
)
|
)
|
||||||
public class RunCommand extends BaseCommand {
|
public class RunCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(RunCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(RunCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--tag", "-t"}, description = "Tag for filtering jobs")
|
@Option(names = {"--tag", "-t"}, description = "Tag for filtering jobs")
|
||||||
private String tag;
|
private String tag;
|
||||||
@@ -190,7 +189,7 @@ public class RunCommand extends BaseCommand {
|
|||||||
sb.append("Job created: ").append(job.id()).append("\n");
|
sb.append("Job created: ").append(job.id()).append("\n");
|
||||||
sb.append(" Command: ").append(String.join(" ", job.command())).append("\n");
|
sb.append(" Command: ").append(String.join(" ", job.command())).append("\n");
|
||||||
sb.append(" Tag: ").append(job.tag() != null ? job.tag() : "-").append("\n");
|
sb.append(" Tag: ").append(job.tag() != null ? job.tag() : "-").append("\n");
|
||||||
sb.append(" State: ").append(job.state().toString().toLowerCase());
|
sb.append(" State: ").append(job.state().toString().toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
getOut().println(sb.toString());
|
getOut().println(sb.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.config.OperatingSystem;
|
import com.samsonmedia.barn.config.OperatingSystem;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
||||||
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
||||||
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
||||||
@@ -33,7 +31,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceInstallCommand extends BaseCommand {
|
public class ServiceInstallCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceInstallCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceInstallCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--user"}, description = "Install as user service instead of system-wide")
|
@Option(names = {"--user"}, description = "Install as user service instead of system-wide")
|
||||||
private boolean userService;
|
private boolean userService;
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
@@ -26,7 +24,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceLogsCommand extends BaseCommand {
|
public class ServiceLogsCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceLogsCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceLogsCommand.class);
|
||||||
private static final String LOG_FILE_NAME = "barn.log";
|
private static final String LOG_FILE_NAME = "barn.log";
|
||||||
|
|
||||||
@Option(names = {"--follow", "-f"}, description = "Follow log output")
|
@Option(names = {"--follow", "-f"}, description = "Follow log output")
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package com.samsonmedia.barn.cli;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.ipc.IpcClient;
|
import com.samsonmedia.barn.ipc.IpcClient;
|
||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
@@ -25,7 +24,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceReloadCommand extends BaseCommand {
|
public class ServiceReloadCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceReloadCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceReloadCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--barn-dir"}, description = "Barn data directory", hidden = true)
|
@Option(names = {"--barn-dir"}, description = "Barn data directory", hidden = true)
|
||||||
private Path barnDir;
|
private Path barnDir;
|
||||||
@@ -49,7 +48,7 @@ public class ServiceReloadCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (IpcClient client = new IpcClient(socketPath)) {
|
try (IpcClient client = new IpcClient(socketPath)) {
|
||||||
String result = client.send("reload", null, String.class);
|
client.send("reload", null, String.class);
|
||||||
getOut().println("Configuration reloaded");
|
getOut().println("Configuration reloaded");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
@@ -75,7 +74,7 @@ public class ServiceReloadCommand extends BaseCommand {
|
|||||||
long pid = Long.parseLong(pidStr);
|
long pid = Long.parseLong(pidStr);
|
||||||
|
|
||||||
// On Unix, we can send SIGHUP. On Windows, this won't work.
|
// On Unix, we can send SIGHUP. On Windows, this won't work.
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||||
if (os.contains("windows")) {
|
if (os.contains("windows")) {
|
||||||
outputError("Reload via signal not supported on Windows. IPC socket required.");
|
outputError("Reload via signal not supported on Windows. IPC socket required.");
|
||||||
return EXIT_ERROR;
|
return EXIT_ERROR;
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.execution.ProcessUtils;
|
import com.samsonmedia.barn.execution.ProcessUtils;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
@@ -24,7 +22,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceRestartCommand extends BaseCommand {
|
public class ServiceRestartCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceRestartCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceRestartCommand.class);
|
||||||
private static final long DEFAULT_WAIT_SECONDS = 30;
|
private static final long DEFAULT_WAIT_SECONDS = 30;
|
||||||
|
|
||||||
@Option(names = {"--force", "-f"}, description = "Force immediate restart")
|
@Option(names = {"--force", "-f"}, description = "Force immediate restart")
|
||||||
|
|||||||
@@ -5,12 +5,10 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.Config;
|
import com.samsonmedia.barn.config.Config;
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.config.ConfigLoader;
|
import com.samsonmedia.barn.config.ConfigLoader;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.service.BarnService;
|
import com.samsonmedia.barn.service.BarnService;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
@@ -26,7 +24,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceStartCommand extends BaseCommand {
|
public class ServiceStartCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceStartCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceStartCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--foreground", "-f"}, description = "Run in foreground (don't daemonize)")
|
@Option(names = {"--foreground", "-f"}, description = "Run in foreground (don't daemonize)")
|
||||||
private boolean foreground;
|
private boolean foreground;
|
||||||
|
|||||||
@@ -11,14 +11,12 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.config.OperatingSystem;
|
import com.samsonmedia.barn.config.OperatingSystem;
|
||||||
import com.samsonmedia.barn.ipc.IpcClient;
|
import com.samsonmedia.barn.ipc.IpcClient;
|
||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
||||||
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
||||||
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
||||||
@@ -38,7 +36,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceStatusCommand extends BaseCommand {
|
public class ServiceStatusCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceStatusCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceStatusCommand.class);
|
||||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||||
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
.withZone(ZoneId.systemDefault());
|
.withZone(ZoneId.systemDefault());
|
||||||
@@ -98,10 +96,11 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
int succeeded = countJobsByState(effectiveBarnDir, JobState.SUCCEEDED);
|
int succeeded = countJobsByState(effectiveBarnDir, JobState.SUCCEEDED);
|
||||||
int failed = countJobsByState(effectiveBarnDir, JobState.FAILED);
|
int failed = countJobsByState(effectiveBarnDir, JobState.FAILED);
|
||||||
int canceled = countJobsByState(effectiveBarnDir, JobState.CANCELED);
|
int canceled = countJobsByState(effectiveBarnDir, JobState.CANCELED);
|
||||||
|
int killed = countJobsByState(effectiveBarnDir, JobState.KILLED);
|
||||||
int total = countTotalJobs(effectiveBarnDir);
|
int total = countTotalJobs(effectiveBarnDir);
|
||||||
|
|
||||||
return ServiceStatus.running(pid, startTime, running, queued, succeeded, failed,
|
return ServiceStatus.running(pid, startTime, running, queued, succeeded, failed,
|
||||||
canceled, total, effectiveBarnDir, serviceManager);
|
canceled, killed, total, effectiveBarnDir, serviceManager);
|
||||||
}
|
}
|
||||||
} catch (IpcException e) {
|
} catch (IpcException e) {
|
||||||
LOG.debug("IPC failed, using basic status: {}", e.getMessage());
|
LOG.debug("IPC failed, using basic status: {}", e.getMessage());
|
||||||
@@ -115,9 +114,10 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
int succeeded = countJobsByState(effectiveBarnDir, JobState.SUCCEEDED);
|
int succeeded = countJobsByState(effectiveBarnDir, JobState.SUCCEEDED);
|
||||||
int failed = countJobsByState(effectiveBarnDir, JobState.FAILED);
|
int failed = countJobsByState(effectiveBarnDir, JobState.FAILED);
|
||||||
int canceled = countJobsByState(effectiveBarnDir, JobState.CANCELED);
|
int canceled = countJobsByState(effectiveBarnDir, JobState.CANCELED);
|
||||||
|
int killed = countJobsByState(effectiveBarnDir, JobState.KILLED);
|
||||||
|
|
||||||
return ServiceStatus.running(pid, startTime, running, queued, succeeded, failed, canceled,
|
return ServiceStatus.running(pid, startTime, running, queued, succeeded, failed, canceled,
|
||||||
total, effectiveBarnDir, serviceManager);
|
killed, total, effectiveBarnDir, serviceManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIntValue(Map<String, Object> map, String key, int defaultValue) {
|
private int getIntValue(Map<String, Object> map, String key, int defaultValue) {
|
||||||
@@ -153,8 +153,7 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case HUMAN -> outputHumanFormat(status);
|
case HUMAN -> outputHumanFormat(status);
|
||||||
case JSON -> output(status.toMap());
|
case JSON, XML -> output(status.toMap());
|
||||||
case XML -> output(status.toMap());
|
|
||||||
default -> outputHumanFormat(status);
|
default -> outputHumanFormat(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,6 +181,7 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
sb.append(String.format(" Succeeded: %d%n", status.succeededJobs));
|
sb.append(String.format(" Succeeded: %d%n", status.succeededJobs));
|
||||||
sb.append(String.format(" Failed: %d%n", status.failedJobs));
|
sb.append(String.format(" Failed: %d%n", status.failedJobs));
|
||||||
sb.append(String.format(" Canceled: %d%n", status.canceledJobs));
|
sb.append(String.format(" Canceled: %d%n", status.canceledJobs));
|
||||||
|
sb.append(String.format(" Killed: %d%n", status.killedJobs));
|
||||||
sb.append(String.format(" Total: %d%n", status.totalJobs));
|
sb.append(String.format(" Total: %d%n", status.totalJobs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,13 +254,14 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
final int succeededJobs;
|
final int succeededJobs;
|
||||||
final int failedJobs;
|
final int failedJobs;
|
||||||
final int canceledJobs;
|
final int canceledJobs;
|
||||||
|
final int killedJobs;
|
||||||
final int totalJobs;
|
final int totalJobs;
|
||||||
final Path dataDir;
|
final Path dataDir;
|
||||||
final String serviceManager;
|
final String serviceManager;
|
||||||
|
|
||||||
private ServiceStatus(boolean running, long pid, Instant startedAt, long uptimeSeconds,
|
private ServiceStatus(boolean running, long pid, Instant startedAt, long uptimeSeconds,
|
||||||
int runningJobs, int queuedJobs, int succeededJobs, int failedJobs, int canceledJobs,
|
int runningJobs, int queuedJobs, int succeededJobs, int failedJobs, int canceledJobs,
|
||||||
int totalJobs, Path dataDir, String serviceManager) {
|
int killedJobs, int totalJobs, Path dataDir, String serviceManager) {
|
||||||
this.running = running;
|
this.running = running;
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
this.startedAt = startedAt;
|
this.startedAt = startedAt;
|
||||||
@@ -270,21 +271,22 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
this.succeededJobs = succeededJobs;
|
this.succeededJobs = succeededJobs;
|
||||||
this.failedJobs = failedJobs;
|
this.failedJobs = failedJobs;
|
||||||
this.canceledJobs = canceledJobs;
|
this.canceledJobs = canceledJobs;
|
||||||
|
this.killedJobs = killedJobs;
|
||||||
this.totalJobs = totalJobs;
|
this.totalJobs = totalJobs;
|
||||||
this.dataDir = dataDir;
|
this.dataDir = dataDir;
|
||||||
this.serviceManager = serviceManager;
|
this.serviceManager = serviceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ServiceStatus stopped(Path dataDir, String serviceManager) {
|
static ServiceStatus stopped(Path dataDir, String serviceManager) {
|
||||||
return new ServiceStatus(false, 0, null, 0, 0, 0, 0, 0, 0, 0, dataDir, serviceManager);
|
return new ServiceStatus(false, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, dataDir, serviceManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ServiceStatus running(long pid, Instant startedAt, int runningJobs, int queuedJobs,
|
static ServiceStatus running(long pid, Instant startedAt, int runningJobs, int queuedJobs,
|
||||||
int succeededJobs, int failedJobs, int canceledJobs, int totalJobs,
|
int succeededJobs, int failedJobs, int canceledJobs, int killedJobs, int totalJobs,
|
||||||
Path dataDir, String serviceManager) {
|
Path dataDir, String serviceManager) {
|
||||||
long uptime = Duration.between(startedAt, Instant.now()).getSeconds();
|
long uptime = Duration.between(startedAt, Instant.now()).getSeconds();
|
||||||
return new ServiceStatus(true, pid, startedAt, uptime, runningJobs, queuedJobs,
|
return new ServiceStatus(true, pid, startedAt, uptime, runningJobs, queuedJobs,
|
||||||
succeededJobs, failedJobs, canceledJobs, totalJobs, dataDir, serviceManager);
|
succeededJobs, failedJobs, canceledJobs, killedJobs, totalJobs, dataDir, serviceManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> toMap() {
|
Map<String, Object> toMap() {
|
||||||
@@ -303,6 +305,7 @@ public class ServiceStatusCommand extends BaseCommand {
|
|||||||
jobs.put("succeeded", succeededJobs);
|
jobs.put("succeeded", succeededJobs);
|
||||||
jobs.put("failed", failedJobs);
|
jobs.put("failed", failedJobs);
|
||||||
jobs.put("canceled", canceledJobs);
|
jobs.put("canceled", canceledJobs);
|
||||||
|
jobs.put("killed", killedJobs);
|
||||||
jobs.put("total", totalJobs);
|
jobs.put("total", totalJobs);
|
||||||
map.put("jobs", jobs);
|
map.put("jobs", jobs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.execution.ProcessUtils;
|
import com.samsonmedia.barn.execution.ProcessUtils;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
@@ -24,7 +22,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceStopCommand extends BaseCommand {
|
public class ServiceStopCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceStopCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceStopCommand.class);
|
||||||
private static final long DEFAULT_WAIT_SECONDS = 30;
|
private static final long DEFAULT_WAIT_SECONDS = 30;
|
||||||
|
|
||||||
@Option(names = {"--force", "-f"}, description = "Force immediate stop (SIGKILL)")
|
@Option(names = {"--force", "-f"}, description = "Force immediate stop (SIGKILL)")
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ package com.samsonmedia.barn.cli;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.OperatingSystem;
|
import com.samsonmedia.barn.config.OperatingSystem;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
import com.samsonmedia.barn.platform.linux.SystemdManager;
|
||||||
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
import com.samsonmedia.barn.platform.macos.LaunchdManager;
|
||||||
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
import com.samsonmedia.barn.platform.windows.WindowsServiceManager;
|
||||||
@@ -31,7 +29,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class ServiceUninstallCommand extends BaseCommand {
|
public class ServiceUninstallCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServiceUninstallCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ServiceUninstallCommand.class);
|
||||||
|
|
||||||
@Option(names = {"--user"}, description = "Uninstall user service instead of system-wide")
|
@Option(names = {"--user"}, description = "Uninstall user service instead of system-wide")
|
||||||
private boolean userService;
|
private boolean userService;
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -23,6 +21,7 @@ import com.samsonmedia.barn.ipc.IpcClient;
|
|||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ import picocli.CommandLine.Option;
|
|||||||
)
|
)
|
||||||
public class StatusCommand extends BaseCommand {
|
public class StatusCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(StatusCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(StatusCommand.class);
|
||||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||||
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
.withZone(ZoneId.systemDefault());
|
.withZone(ZoneId.systemDefault());
|
||||||
@@ -203,7 +202,7 @@ public class StatusCommand extends BaseCommand {
|
|||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
sb.append(String.format("%-" + idWidth + "s %-9s %-" + tagWidth + "s %-19s %-4s %-8s%n",
|
sb.append(String.format("%-" + idWidth + "s %-9s %-" + tagWidth + "s %-19s %-4s %-8s%n",
|
||||||
job.id(),
|
job.id(),
|
||||||
job.state().toString().toLowerCase(),
|
job.state().toString().toLowerCase(Locale.ROOT),
|
||||||
job.tag() != null ? job.tag() : "-",
|
job.tag() != null ? job.tag() : "-",
|
||||||
formatTimestamp(job.createdAt()),
|
formatTimestamp(job.createdAt()),
|
||||||
job.exitCode() != null ? job.exitCode().toString() : "-",
|
job.exitCode() != null ? job.exitCode().toString() : "-",
|
||||||
@@ -262,7 +261,7 @@ public class StatusCommand extends BaseCommand {
|
|||||||
if (!first) {
|
if (!first) {
|
||||||
summary.append(", ");
|
summary.append(", ");
|
||||||
}
|
}
|
||||||
summary.append(count).append(" ").append(s.toString().toLowerCase());
|
summary.append(count).append(" ").append(s.toString().toLowerCase(Locale.ROOT));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,7 +279,7 @@ public class StatusCommand extends BaseCommand {
|
|||||||
summary.put("total", jobs.size());
|
summary.put("total", jobs.size());
|
||||||
|
|
||||||
for (JobState s : JobState.values()) {
|
for (JobState s : JobState.values()) {
|
||||||
summary.put(s.toString().toLowerCase(), counts.getOrDefault(s, 0L));
|
summary.put(s.toString().toLowerCase(Locale.ROOT), counts.getOrDefault(s, 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
return summary;
|
return summary;
|
||||||
|
|||||||
@@ -13,14 +13,12 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.ConfigDefaults;
|
import com.samsonmedia.barn.config.ConfigDefaults;
|
||||||
import com.samsonmedia.barn.ipc.IpcClient;
|
import com.samsonmedia.barn.ipc.IpcClient;
|
||||||
import com.samsonmedia.barn.ipc.IpcException;
|
import com.samsonmedia.barn.ipc.IpcException;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.monitoring.UsageLogger;
|
import com.samsonmedia.barn.monitoring.UsageLogger;
|
||||||
import com.samsonmedia.barn.monitoring.UsageRecord;
|
import com.samsonmedia.barn.monitoring.UsageRecord;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
@@ -39,7 +37,7 @@ import picocli.CommandLine.Parameters;
|
|||||||
)
|
)
|
||||||
public class UsageCommand extends BaseCommand {
|
public class UsageCommand extends BaseCommand {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UsageCommand.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(UsageCommand.class);
|
||||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter
|
||||||
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
.withZone(ZoneId.systemDefault());
|
.withZone(ZoneId.systemDefault());
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.samsonmedia.barn.cli;
|
|||||||
import java.lang.reflect.RecordComponent;
|
import java.lang.reflect.RecordComponent;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
@@ -92,7 +93,7 @@ public class XmlFormatter implements OutputFormatter {
|
|||||||
|
|
||||||
sb.append(indent).append("<job>\n");
|
sb.append(indent).append("<job>\n");
|
||||||
sb.append(childIndent).append("<id>").append(escapeXml(job.id())).append("</id>\n");
|
sb.append(childIndent).append("<id>").append(escapeXml(job.id())).append("</id>\n");
|
||||||
sb.append(childIndent).append("<state>").append(job.state().toString().toLowerCase())
|
sb.append(childIndent).append("<state>").append(job.state().toString().toLowerCase(Locale.ROOT))
|
||||||
.append("</state>\n");
|
.append("</state>\n");
|
||||||
|
|
||||||
// Command as nested elements
|
// Command as nested elements
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ public final class ConfigDefaults {
|
|||||||
/**
|
/**
|
||||||
* Gets the default IPC socket path.
|
* Gets the default IPC socket path.
|
||||||
*
|
*
|
||||||
|
* <p>Windows 10 version 1803+ supports Unix domain sockets with file paths.
|
||||||
|
*
|
||||||
* @return the default IPC socket path
|
* @return the default IPC socket path
|
||||||
*/
|
*/
|
||||||
public static Path getDefaultIpcSocket() {
|
public static Path getDefaultIpcSocket() {
|
||||||
return switch (OperatingSystem.current()) {
|
return switch (OperatingSystem.current()) {
|
||||||
case WINDOWS -> Path.of("\\\\.\\pipe\\barn");
|
case WINDOWS -> Path.of(System.getenv("TEMP"), "barn", "barn.sock");
|
||||||
case LINUX, MACOS -> Path.of("/tmp/barn/barn.sock");
|
case LINUX, MACOS -> Path.of("/tmp/barn/barn.sock");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and validates Barn configuration from files and environment variables.
|
* Loads and validates Barn configuration from files and environment variables.
|
||||||
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public final class ConfigLoader {
|
public final class ConfigLoader {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ConfigLoader.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ConfigLoader.class);
|
||||||
private static final String ENV_PREFIX = "BARN_";
|
private static final String ENV_PREFIX = "BARN_";
|
||||||
|
|
||||||
private final Map<String, String> environment;
|
private final Map<String, String> environment;
|
||||||
@@ -159,8 +159,8 @@ public final class ConfigLoader {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String section = remainder.substring(0, underscoreIndex).toLowerCase();
|
String section = remainder.substring(0, underscoreIndex).toLowerCase(Locale.ROOT);
|
||||||
String configKey = remainder.substring(underscoreIndex + 1).toLowerCase();
|
String configKey = remainder.substring(underscoreIndex + 1).toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
LOG.debug("Applying environment override: {}={}", key, value);
|
LOG.debug("Applying environment override: {}={}", key, value);
|
||||||
data.computeIfAbsent(section, k -> new HashMap<>())
|
data.computeIfAbsent(section, k -> new HashMap<>())
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.samsonmedia.barn.config;
|
package com.samsonmedia.barn.config;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log level for the Barn service.
|
* Log level for the Barn service.
|
||||||
*/
|
*/
|
||||||
@@ -21,7 +23,7 @@ public enum LogLevel {
|
|||||||
throw new IllegalArgumentException("Log level cannot be null or blank");
|
throw new IllegalArgumentException("Log level cannot be null or blank");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return valueOf(value.trim().toUpperCase());
|
return valueOf(value.trim().toUpperCase(Locale.ROOT));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid log level: '" + value + "'. Valid values are: debug, info, warn, error");
|
"Invalid log level: '" + value + "'. Valid values are: debug, info, warn, error");
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.samsonmedia.barn.config;
|
package com.samsonmedia.barn.config;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the operating system Barn is running on.
|
* Represents the operating system Barn is running on.
|
||||||
*/
|
*/
|
||||||
@@ -23,7 +25,7 @@ public enum OperatingSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static OperatingSystem detect() {
|
private static OperatingSystem detect() {
|
||||||
String osName = System.getProperty("os.name", "").toLowerCase();
|
String osName = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
|
||||||
if (osName.contains("win")) {
|
if (osName.contains("win")) {
|
||||||
return WINDOWS;
|
return WINDOWS;
|
||||||
} else if (osName.contains("mac") || osName.contains("darwin")) {
|
} else if (osName.contains("mac") || osName.contains("darwin")) {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.samsonmedia.barn.execution;
|
package com.samsonmedia.barn.execution;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.config.Config;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.jobs.RetryCalculator;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
@@ -23,17 +24,19 @@ import com.samsonmedia.barn.state.JobState;
|
|||||||
* <li>Its process is no longer alive (or PID is unknown)</li>
|
* <li>Its process is no longer alive (or PID is unknown)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p>Orphaned jobs are marked as failed with a symbolic exit code.
|
* <p>Orphaned jobs are marked as KILLED and automatically scheduled for retry
|
||||||
|
* if retries are configured and not exhausted.
|
||||||
*/
|
*/
|
||||||
public class CrashRecovery {
|
public class CrashRecovery {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CrashRecovery.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(CrashRecovery.class);
|
||||||
private static final String ORPHANED_EXIT_CODE = "orphaned_process";
|
private static final String KILLED_ERROR = "Process killed - daemon restarted";
|
||||||
private static final String ORPHANED_ERROR = "Process orphaned - daemon restarted";
|
|
||||||
|
|
||||||
private final JobRepository repository;
|
private final JobRepository repository;
|
||||||
private final HeartbeatChecker heartbeatChecker;
|
private final HeartbeatChecker heartbeatChecker;
|
||||||
private final BarnDirectories dirs;
|
private final BarnDirectories dirs;
|
||||||
|
private final RetryCalculator retryCalculator;
|
||||||
|
private final int maxRetries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a CrashRecovery instance.
|
* Creates a CrashRecovery instance.
|
||||||
@@ -41,11 +44,16 @@ public class CrashRecovery {
|
|||||||
* @param repository the job repository
|
* @param repository the job repository
|
||||||
* @param heartbeatChecker the heartbeat checker
|
* @param heartbeatChecker the heartbeat checker
|
||||||
* @param dirs the directory manager
|
* @param dirs the directory manager
|
||||||
|
* @param config the configuration
|
||||||
*/
|
*/
|
||||||
public CrashRecovery(JobRepository repository, HeartbeatChecker heartbeatChecker, BarnDirectories dirs) {
|
public CrashRecovery(JobRepository repository, HeartbeatChecker heartbeatChecker, BarnDirectories dirs,
|
||||||
|
Config config) {
|
||||||
this.repository = Objects.requireNonNull(repository, "repository must not be null");
|
this.repository = Objects.requireNonNull(repository, "repository must not be null");
|
||||||
this.heartbeatChecker = Objects.requireNonNull(heartbeatChecker, "heartbeatChecker must not be null");
|
this.heartbeatChecker = Objects.requireNonNull(heartbeatChecker, "heartbeatChecker must not be null");
|
||||||
this.dirs = Objects.requireNonNull(dirs, "dirs must not be null");
|
this.dirs = Objects.requireNonNull(dirs, "dirs must not be null");
|
||||||
|
Objects.requireNonNull(config, "config must not be null");
|
||||||
|
this.retryCalculator = new RetryCalculator(config.jobs());
|
||||||
|
this.maxRetries = config.jobs().maxRetries();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,6 +136,18 @@ public class CrashRecovery {
|
|||||||
private void recoverJob(Job job) throws IOException {
|
private void recoverJob(Job job) throws IOException {
|
||||||
LOG.info("Recovering orphaned job: {} (PID: {})", job.id(), job.pid());
|
LOG.info("Recovering orphaned job: {} (PID: {})", job.id(), job.pid());
|
||||||
|
|
||||||
repository.markFailed(job.id(), ORPHANED_EXIT_CODE, ORPHANED_ERROR);
|
// Mark the job as killed
|
||||||
|
repository.markKilled(job.id(), KILLED_ERROR);
|
||||||
|
|
||||||
|
// Check if we should auto-retry
|
||||||
|
if (maxRetries > 0 && job.retryCount() < maxRetries) {
|
||||||
|
// Schedule retry with exponential backoff
|
||||||
|
Instant retryAt = Instant.now().plus(retryCalculator.calculateDelay(job.retryCount()));
|
||||||
|
repository.scheduleRetry(job.id(), retryAt, null, KILLED_ERROR);
|
||||||
|
LOG.info("Job {} scheduled for auto-retry at {} (attempt {})",
|
||||||
|
job.id(), retryAt, job.retryCount() + 1);
|
||||||
|
} else {
|
||||||
|
LOG.info("Job {} will not be retried (retries exhausted or disabled)", job.id());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,11 @@ import java.time.Instant;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.JobsConfig;
|
import com.samsonmedia.barn.config.JobsConfig;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
import com.samsonmedia.barn.jobs.RetryCalculator;
|
import com.samsonmedia.barn.jobs.RetryCalculator;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.monitoring.UsageMonitor;
|
import com.samsonmedia.barn.monitoring.UsageMonitor;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ import com.samsonmedia.barn.state.BarnDirectories;
|
|||||||
*/
|
*/
|
||||||
public class JobRunner {
|
public class JobRunner {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JobRunner.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(JobRunner.class);
|
||||||
private static final String STDOUT_LOG = "stdout.log";
|
private static final String STDOUT_LOG = "stdout.log";
|
||||||
private static final String STDERR_LOG = "stderr.log";
|
private static final String STDERR_LOG = "stderr.log";
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.Config;
|
import com.samsonmedia.barn.config.Config;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
@@ -31,7 +29,7 @@ import com.samsonmedia.barn.state.JobState;
|
|||||||
*/
|
*/
|
||||||
public class JobScheduler {
|
public class JobScheduler {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JobScheduler.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(JobScheduler.class);
|
||||||
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(1);
|
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(1);
|
||||||
private static final Duration DEFAULT_SHUTDOWN_TIMEOUT = Duration.ofMinutes(5);
|
private static final Duration DEFAULT_SHUTDOWN_TIMEOUT = Duration.ofMinutes(5);
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes processes and captures their output.
|
* Executes processes and captures their output.
|
||||||
@@ -21,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class ProcessExecutor {
|
public class ProcessExecutor {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ProcessExecutor.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ProcessExecutor.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command and returns the process.
|
* Executes a command and returns the process.
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitors a running process and emits events.
|
* Monitors a running process and emits events.
|
||||||
@@ -20,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class ProcessMonitor {
|
public class ProcessMonitor {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ProcessMonitor.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ProcessMonitor.class);
|
||||||
private static final Duration DEFAULT_HEARTBEAT_INTERVAL = Duration.ofSeconds(10);
|
private static final Duration DEFAULT_HEARTBEAT_INTERVAL = Duration.ofSeconds(10);
|
||||||
|
|
||||||
private final Duration heartbeatInterval;
|
private final Duration heartbeatInterval;
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ package com.samsonmedia.barn.execution;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cross-platform process utilities.
|
* Cross-platform process utilities.
|
||||||
@@ -13,7 +12,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public final class ProcessUtils {
|
public final class ProcessUtils {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ProcessUtils.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(ProcessUtils.class);
|
||||||
|
|
||||||
private ProcessUtils() {
|
private ProcessUtils() {
|
||||||
// Utility class - prevent instantiation
|
// Utility class - prevent instantiation
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import java.nio.file.StandardOpenOption;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock to ensure only one scheduler runs at a time.
|
* Lock to ensure only one scheduler runs at a time.
|
||||||
@@ -21,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public final class SchedulerLock implements Closeable {
|
public final class SchedulerLock implements Closeable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SchedulerLock.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(SchedulerLock.class);
|
||||||
|
|
||||||
private final Path lockFile;
|
private final Path lockFile;
|
||||||
private final FileChannel channel;
|
private final FileChannel channel;
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ import java.nio.channels.SocketChannel;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IPC client for communicating with the barn service.
|
* IPC client for communicating with the barn service.
|
||||||
@@ -29,7 +28,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|||||||
*/
|
*/
|
||||||
public class IpcClient implements AutoCloseable {
|
public class IpcClient implements AutoCloseable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(IpcClient.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(IpcClient.class);
|
||||||
private static final int DEFAULT_TIMEOUT_MS = 30000;
|
private static final int DEFAULT_TIMEOUT_MS = 30000;
|
||||||
|
|
||||||
private final Path socketPath;
|
private final Path socketPath;
|
||||||
@@ -177,7 +176,7 @@ public class IpcClient implements AutoCloseable {
|
|||||||
* @return the default socket path
|
* @return the default socket path
|
||||||
*/
|
*/
|
||||||
public static Path getDefaultSocketPath() {
|
public static Path getDefaultSocketPath() {
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||||
if (os.contains("win")) {
|
if (os.contains("win")) {
|
||||||
// Windows - use temp directory (named pipes require JNI)
|
// Windows - use temp directory (named pipes require JNI)
|
||||||
return Path.of(System.getProperty("java.io.tmpdir"), "barn", "barn.sock");
|
return Path.of(System.getProperty("java.io.tmpdir"), "barn", "barn.sock");
|
||||||
|
|||||||
@@ -18,12 +18,10 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IPC server for receiving requests from CLI clients.
|
* IPC server for receiving requests from CLI clients.
|
||||||
@@ -32,7 +30,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|||||||
*/
|
*/
|
||||||
public class IpcServer {
|
public class IpcServer {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(IpcServer.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(IpcServer.class);
|
||||||
|
|
||||||
private final Path socketPath;
|
private final Path socketPath;
|
||||||
private final RequestHandler handler;
|
private final RequestHandler handler;
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.samsonmedia.barn.config.JobsConfig;
|
import com.samsonmedia.barn.config.JobsConfig;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.AtomicFiles;
|
import com.samsonmedia.barn.state.AtomicFiles;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
@@ -30,7 +28,7 @@ import com.samsonmedia.barn.state.StateFiles;
|
|||||||
*/
|
*/
|
||||||
public class JobRepository {
|
public class JobRepository {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JobRepository.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(JobRepository.class);
|
||||||
private static final String MANIFEST_FILE = "manifest.json";
|
private static final String MANIFEST_FILE = "manifest.json";
|
||||||
|
|
||||||
private final BarnDirectories dirs;
|
private final BarnDirectories dirs;
|
||||||
@@ -257,6 +255,27 @@ public class JobRepository {
|
|||||||
LOG.info("Job {} failed: {}", id, symbolicCode);
|
LOG.info("Job {} failed: {}", id, symbolicCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a job as killed (orphaned when service was terminated).
|
||||||
|
*
|
||||||
|
* @param id the job ID
|
||||||
|
* @param error the error message
|
||||||
|
* @throws IOException if update fails
|
||||||
|
*/
|
||||||
|
public void markKilled(String id, String error) throws IOException {
|
||||||
|
Objects.requireNonNull(id, "id must not be null");
|
||||||
|
|
||||||
|
StateFiles stateFiles = new StateFiles(dirs.getJobDir(id));
|
||||||
|
|
||||||
|
updateState(id, JobState.KILLED);
|
||||||
|
stateFiles.writeFinishedAt(Instant.now());
|
||||||
|
if (error != null) {
|
||||||
|
stateFiles.writeError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Job {} killed: {}", id, error);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules a job for retry.
|
* Schedules a job for retry.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ import com.samsonmedia.barn.state.JobState;
|
|||||||
* <p>Valid transitions:
|
* <p>Valid transitions:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>QUEUED → RUNNING, FAILED, CANCELED</li>
|
* <li>QUEUED → RUNNING, FAILED, CANCELED</li>
|
||||||
* <li>RUNNING → SUCCEEDED, FAILED, CANCELED</li>
|
* <li>RUNNING → SUCCEEDED, FAILED, CANCELED, KILLED</li>
|
||||||
* <li>FAILED → QUEUED (for retry)</li>
|
* <li>FAILED → QUEUED (for retry)</li>
|
||||||
* <li>SUCCEEDED → (none, terminal)</li>
|
* <li>SUCCEEDED → (none, terminal)</li>
|
||||||
* <li>CANCELED → (none, terminal)</li>
|
* <li>CANCELED → (none, terminal)</li>
|
||||||
|
* <li>KILLED → QUEUED (for retry)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public final class JobStateMachine {
|
public final class JobStateMachine {
|
||||||
|
|
||||||
private static final Map<JobState, Set<JobState>> VALID_TRANSITIONS = Map.of(
|
private static final Map<JobState, Set<JobState>> VALID_TRANSITIONS = Map.of(
|
||||||
JobState.QUEUED, Set.of(JobState.RUNNING, JobState.FAILED, JobState.CANCELED),
|
JobState.QUEUED, Set.of(JobState.RUNNING, JobState.FAILED, JobState.CANCELED),
|
||||||
JobState.RUNNING, Set.of(JobState.SUCCEEDED, JobState.FAILED, JobState.CANCELED),
|
JobState.RUNNING, Set.of(JobState.SUCCEEDED, JobState.FAILED, JobState.CANCELED, JobState.KILLED),
|
||||||
JobState.FAILED, Set.of(JobState.QUEUED), // For retry
|
JobState.FAILED, Set.of(JobState.QUEUED), // For retry
|
||||||
JobState.SUCCEEDED, Set.of(),
|
JobState.SUCCEEDED, Set.of(),
|
||||||
JobState.CANCELED, Set.of()
|
JobState.CANCELED, Set.of(),
|
||||||
|
JobState.KILLED, Set.of(JobState.QUEUED) // For retry
|
||||||
);
|
);
|
||||||
|
|
||||||
private JobStateMachine() {
|
private JobStateMachine() {
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package com.samsonmedia.barn.logging;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple logger for Barn that can be globally disabled for CLI commands.
|
||||||
|
*
|
||||||
|
* <p>CLI commands should not produce any log output to avoid breaking
|
||||||
|
* JSON/XML output. The service enables logging on startup.
|
||||||
|
*/
|
||||||
|
public final class BarnLogger {
|
||||||
|
|
||||||
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
|
private static volatile boolean enabled = false;
|
||||||
|
private static volatile Level level = Level.INFO;
|
||||||
|
private static volatile PrintStream output = System.err;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log levels supported by BarnLogger.
|
||||||
|
*/
|
||||||
|
public enum Level {
|
||||||
|
DEBUG(0), INFO(1), WARN(2), ERROR(3), OFF(4);
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
Level(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isEnabled(Level threshold) {
|
||||||
|
return this.value >= threshold.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private BarnLogger(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BarnLogger getLogger(Class<?> clazz) {
|
||||||
|
return new BarnLogger(clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BarnLogger getLogger(String name) {
|
||||||
|
return new BarnLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables logging globally. Called by the service on startup.
|
||||||
|
*/
|
||||||
|
public static void enable() {
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables logging globally. Default state for CLI commands.
|
||||||
|
*/
|
||||||
|
public static void disable() {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the global log level.
|
||||||
|
*/
|
||||||
|
public static void setLevel(Level newLevel) {
|
||||||
|
level = newLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current global log level.
|
||||||
|
*
|
||||||
|
* @return the current log level
|
||||||
|
*/
|
||||||
|
public static Level getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the output stream for logs.
|
||||||
|
*/
|
||||||
|
public static void setOutput(PrintStream stream) {
|
||||||
|
output = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a trace-level message. Mapped to DEBUG level.
|
||||||
|
*/
|
||||||
|
public void trace(String message, Object... args) {
|
||||||
|
log(Level.DEBUG, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(String message, Object... args) {
|
||||||
|
log(Level.DEBUG, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String message, Object... args) {
|
||||||
|
log(Level.INFO, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn(String message, Object... args) {
|
||||||
|
log(Level.WARN, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String message, Object... args) {
|
||||||
|
log(Level.ERROR, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an error message with a throwable.
|
||||||
|
*
|
||||||
|
* @param message the message to log
|
||||||
|
* @param t the throwable to log
|
||||||
|
*/
|
||||||
|
public void error(String message, Throwable t) {
|
||||||
|
if (!enabled || !Level.ERROR.isEnabled(level)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String timestamp = LocalDateTime.now().format(FORMATTER);
|
||||||
|
output.println(String.format("%s [%s] ERROR %s - %s",
|
||||||
|
timestamp, Thread.currentThread().getName(), name, message));
|
||||||
|
if (t != null) {
|
||||||
|
t.printStackTrace(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
return enabled && Level.DEBUG.isEnabled(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInfoEnabled() {
|
||||||
|
return enabled && Level.INFO.isEnabled(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(Level msgLevel, String message, Object... args) {
|
||||||
|
if (!enabled || !msgLevel.isEnabled(level)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String timestamp = LocalDateTime.now().format(FORMATTER);
|
||||||
|
String formattedMessage = formatMessage(message, args);
|
||||||
|
output.println(String.format("%s [%s] %-5s %s - %s",
|
||||||
|
timestamp, Thread.currentThread().getName(), msgLevel, name, formattedMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatMessage(String message, Object... args) {
|
||||||
|
if (args == null || args.length == 0) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
// Simple {} placeholder replacement like SLF4J
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int argIndex = 0;
|
||||||
|
int i = 0;
|
||||||
|
while (i < message.length()) {
|
||||||
|
if (i < message.length() - 1 && message.charAt(i) == '{' && message.charAt(i + 1) == '}') {
|
||||||
|
if (argIndex < args.length) {
|
||||||
|
sb.append(args[argIndex++]);
|
||||||
|
} else {
|
||||||
|
sb.append("{}");
|
||||||
|
}
|
||||||
|
i += 2;
|
||||||
|
} else {
|
||||||
|
sb.append(message.charAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,6 @@ import java.time.Duration;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +13,7 @@ import com.samsonmedia.barn.jobs.Job;
|
|||||||
*/
|
*/
|
||||||
public final class JobLogEvents {
|
public final class JobLogEvents {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JobLogEvents.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(JobLogEvents.class);
|
||||||
|
|
||||||
private JobLogEvents() {
|
private JobLogEvents() {
|
||||||
// Utility class
|
// Utility class
|
||||||
|
|||||||
@@ -5,14 +5,8 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.LogLevel;
|
import com.samsonmedia.barn.config.LogLevel;
|
||||||
|
|
||||||
import ch.qos.logback.classic.Level;
|
|
||||||
import ch.qos.logback.classic.Logger;
|
|
||||||
import ch.qos.logback.classic.LoggerContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration utilities for the logging system.
|
* Configuration utilities for the logging system.
|
||||||
*
|
*
|
||||||
@@ -25,17 +19,15 @@ public final class LoggingConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the root log level at runtime.
|
* Sets the root log level at runtime and enables logging.
|
||||||
*
|
*
|
||||||
* @param level the log level to set
|
* @param level the log level to set
|
||||||
* @throws NullPointerException if level is null
|
* @throws NullPointerException if level is null
|
||||||
*/
|
*/
|
||||||
public static void setLogLevel(LogLevel level) {
|
public static void setLogLevel(LogLevel level) {
|
||||||
Objects.requireNonNull(level, "level must not be null");
|
Objects.requireNonNull(level, "level must not be null");
|
||||||
|
BarnLogger.enable();
|
||||||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
BarnLogger.setLevel(toBarnLoggerLevel(level));
|
||||||
Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
|
|
||||||
rootLogger.setLevel(toLogbackLevel(level));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,9 +36,7 @@ public final class LoggingConfig {
|
|||||||
* @return the current log level
|
* @return the current log level
|
||||||
*/
|
*/
|
||||||
public static LogLevel getLogLevel() {
|
public static LogLevel getLogLevel() {
|
||||||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
return fromBarnLoggerLevel(BarnLogger.getLevel());
|
||||||
Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
|
|
||||||
return fromLogbackLevel(rootLogger.getLevel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,28 +69,21 @@ public final class LoggingConfig {
|
|||||||
return Path.of(System.getProperty("java.io.tmpdir"), "barn", "logs");
|
return Path.of(System.getProperty("java.io.tmpdir"), "barn", "logs");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Level toLogbackLevel(LogLevel level) {
|
private static BarnLogger.Level toBarnLoggerLevel(LogLevel level) {
|
||||||
return switch (level) {
|
return switch (level) {
|
||||||
case DEBUG -> Level.DEBUG;
|
case DEBUG -> BarnLogger.Level.DEBUG;
|
||||||
case INFO -> Level.INFO;
|
case INFO -> BarnLogger.Level.INFO;
|
||||||
case WARN -> Level.WARN;
|
case WARN -> BarnLogger.Level.WARN;
|
||||||
case ERROR -> Level.ERROR;
|
case ERROR -> BarnLogger.Level.ERROR;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LogLevel fromLogbackLevel(Level level) {
|
private static LogLevel fromBarnLoggerLevel(BarnLogger.Level level) {
|
||||||
if (level == null || level.equals(Level.INFO)) {
|
return switch (level) {
|
||||||
return LogLevel.INFO;
|
case DEBUG -> LogLevel.DEBUG;
|
||||||
}
|
case INFO -> LogLevel.INFO;
|
||||||
if (level.equals(Level.DEBUG) || level.equals(Level.TRACE)) {
|
case WARN -> LogLevel.WARN;
|
||||||
return LogLevel.DEBUG;
|
case ERROR, OFF -> LogLevel.ERROR;
|
||||||
}
|
};
|
||||||
if (level.equals(Level.WARN)) {
|
|
||||||
return LogLevel.WARN;
|
|
||||||
}
|
|
||||||
if (level.equals(Level.ERROR) || level.equals(Level.OFF)) {
|
|
||||||
return LogLevel.ERROR;
|
|
||||||
}
|
|
||||||
return LogLevel.INFO;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,13 @@ import java.io.InputStreamReader;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects resource usage metrics for a process.
|
* Collects resource usage metrics for a process.
|
||||||
@@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class UsageCollector {
|
public class UsageCollector {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UsageCollector.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(UsageCollector.class);
|
||||||
private static final int COMMAND_TIMEOUT_SECONDS = 5;
|
private static final int COMMAND_TIMEOUT_SECONDS = 5;
|
||||||
|
|
||||||
private final boolean isWindows;
|
private final boolean isWindows;
|
||||||
@@ -32,7 +32,7 @@ public class UsageCollector {
|
|||||||
* Creates a new UsageCollector.
|
* Creates a new UsageCollector.
|
||||||
*/
|
*/
|
||||||
public UsageCollector() {
|
public UsageCollector() {
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||||
this.isWindows = os.contains("win");
|
this.isWindows = os.contains("win");
|
||||||
this.isMac = os.contains("mac");
|
this.isMac = os.contains("mac");
|
||||||
this.isLinux = os.contains("linux");
|
this.isLinux = os.contains("linux");
|
||||||
@@ -254,7 +254,8 @@ public class UsageCollector {
|
|||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
|
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(process.getInputStream(), java.nio.charset.StandardCharsets.UTF_8))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
output.append(line).append("\n");
|
output.append(line).append("\n");
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes usage records to a CSV file.
|
* Writes usage records to a CSV file.
|
||||||
@@ -18,7 +17,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class UsageLogger implements Closeable {
|
public class UsageLogger implements Closeable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UsageLogger.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(UsageLogger.class);
|
||||||
|
|
||||||
/** Default filename for usage logs. */
|
/** Default filename for usage logs. */
|
||||||
public static final String USAGE_LOG_FILENAME = "usage.csv";
|
public static final String USAGE_LOG_FILENAME = "usage.csv";
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitors resource usage for a process over time.
|
* Monitors resource usage for a process over time.
|
||||||
@@ -20,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class UsageMonitor implements Closeable {
|
public class UsageMonitor implements Closeable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UsageMonitor.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(UsageMonitor.class);
|
||||||
|
|
||||||
/** Default collection interval in seconds. */
|
/** Default collection interval in seconds. */
|
||||||
public static final int DEFAULT_INTERVAL_SECONDS = 5;
|
public static final int DEFAULT_INTERVAL_SECONDS = 5;
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages Linux systemd service operations.
|
* Manages Linux systemd service operations.
|
||||||
@@ -22,7 +21,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class SystemdManager {
|
public class SystemdManager {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SystemdManager.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(SystemdManager.class);
|
||||||
private static final String SERVICE_NAME = "barn.service";
|
private static final String SERVICE_NAME = "barn.service";
|
||||||
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages macOS launchd service operations.
|
* Manages macOS launchd service operations.
|
||||||
@@ -20,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class LaunchdManager {
|
public class LaunchdManager {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(LaunchdManager.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(LaunchdManager.class);
|
||||||
private static final String LABEL = "com.samsonmedia.barn";
|
private static final String LABEL = "com.samsonmedia.barn";
|
||||||
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import java.io.InputStreamReader;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages Windows service operations using sc.exe.
|
* Manages Windows service operations using sc.exe.
|
||||||
@@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class WindowsServiceManager {
|
public class WindowsServiceManager {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WindowsServiceManager.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(WindowsServiceManager.class);
|
||||||
private static final String SERVICE_NAME = "barn";
|
private static final String SERVICE_NAME = "barn";
|
||||||
private static final String DISPLAY_NAME = "Barn Job Daemon";
|
private static final String DISPLAY_NAME = "Barn Job Daemon";
|
||||||
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
private static final long COMMAND_TIMEOUT_SECONDS = 30;
|
||||||
@@ -70,7 +70,7 @@ public class WindowsServiceManager {
|
|||||||
* @return true if Windows services are supported
|
* @return true if Windows services are supported
|
||||||
*/
|
*/
|
||||||
public static boolean hasWindowsServices() {
|
public static boolean hasWindowsServices() {
|
||||||
String osName = System.getProperty("os.name", "").toLowerCase();
|
String osName = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
|
||||||
return osName.contains("windows");
|
return osName.contains("windows");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import java.io.IOException;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.samsonmedia.barn.config.Config;
|
import com.samsonmedia.barn.config.Config;
|
||||||
@@ -23,6 +21,8 @@ import com.samsonmedia.barn.ipc.IpcException;
|
|||||||
import com.samsonmedia.barn.ipc.IpcServer;
|
import com.samsonmedia.barn.ipc.IpcServer;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
|
import com.samsonmedia.barn.logging.LoggingConfig;
|
||||||
import com.samsonmedia.barn.state.BarnDirectories;
|
import com.samsonmedia.barn.state.BarnDirectories;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ import com.samsonmedia.barn.state.JobState;
|
|||||||
*/
|
*/
|
||||||
public class BarnService {
|
public class BarnService {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BarnService.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(BarnService.class);
|
||||||
|
|
||||||
private final Config config;
|
private final Config config;
|
||||||
private final BarnDirectories dirs;
|
private final BarnDirectories dirs;
|
||||||
@@ -69,7 +69,7 @@ public class BarnService {
|
|||||||
|
|
||||||
Duration heartbeatThreshold = Duration.ofSeconds(config.service().staleHeartbeatThresholdSeconds());
|
Duration heartbeatThreshold = Duration.ofSeconds(config.service().staleHeartbeatThresholdSeconds());
|
||||||
HeartbeatChecker heartbeatChecker = new HeartbeatChecker(heartbeatThreshold);
|
HeartbeatChecker heartbeatChecker = new HeartbeatChecker(heartbeatThreshold);
|
||||||
this.crashRecovery = new CrashRecovery(repository, heartbeatChecker, dirs);
|
this.crashRecovery = new CrashRecovery(repository, heartbeatChecker, dirs, config);
|
||||||
|
|
||||||
this.shutdownLatch = new CountDownLatch(1);
|
this.shutdownLatch = new CountDownLatch(1);
|
||||||
this.running = new AtomicBoolean(false);
|
this.running = new AtomicBoolean(false);
|
||||||
@@ -87,6 +87,9 @@ public class BarnService {
|
|||||||
throw new IllegalStateException("Service already running");
|
throw new IllegalStateException("Service already running");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable logging for the service (CLI commands have logging OFF by default)
|
||||||
|
LoggingConfig.setLogLevel(config.service().logLevel());
|
||||||
|
|
||||||
LOG.info("Starting Barn service");
|
LOG.info("Starting Barn service");
|
||||||
|
|
||||||
// 1. Initialize directories
|
// 1. Initialize directories
|
||||||
@@ -263,7 +266,7 @@ public class BarnService {
|
|||||||
tag = (String) map.get("tag");
|
tag = (String) map.get("tag");
|
||||||
String stateStr = (String) map.get("state");
|
String stateStr = (String) map.get("state");
|
||||||
if (stateStr != null) {
|
if (stateStr != null) {
|
||||||
state = JobState.valueOf(stateStr.toUpperCase());
|
state = JobState.valueOf(stateStr.toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
limit = (Integer) map.get("limit");
|
limit = (Integer) map.get("limit");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.samsonmedia.barn.config.CleanupConfig;
|
import com.samsonmedia.barn.config.CleanupConfig;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import com.samsonmedia.barn.state.JobState;
|
import com.samsonmedia.barn.state.JobState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +21,7 @@ import com.samsonmedia.barn.state.JobState;
|
|||||||
*/
|
*/
|
||||||
public class CleanupScheduler {
|
public class CleanupScheduler {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CleanupScheduler.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(CleanupScheduler.class);
|
||||||
|
|
||||||
private final JobRepository repository;
|
private final JobRepository repository;
|
||||||
private final CleanupConfig config;
|
private final CleanupConfig config;
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import java.nio.file.StandardOpenOption;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import com.samsonmedia.barn.logging.BarnLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A file-based lock for coordinating access to resources.
|
* A file-based lock for coordinating access to resources.
|
||||||
@@ -20,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public final class FileLock implements AutoCloseable {
|
public final class FileLock implements AutoCloseable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(FileLock.class);
|
private static final BarnLogger LOG = BarnLogger.getLogger(FileLock.class);
|
||||||
|
|
||||||
private final Path lockFile;
|
private final Path lockFile;
|
||||||
private final FileChannel channel;
|
private final FileChannel channel;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.samsonmedia.barn.state;
|
package com.samsonmedia.barn.state;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the current state of a job in its lifecycle.
|
* Represents the current state of a job in its lifecycle.
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +19,10 @@ public enum JobState {
|
|||||||
FAILED,
|
FAILED,
|
||||||
|
|
||||||
/** Job was manually canceled. */
|
/** Job was manually canceled. */
|
||||||
CANCELED;
|
CANCELED,
|
||||||
|
|
||||||
|
/** Job was killed when the service was terminated unexpectedly. */
|
||||||
|
KILLED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a job state from a string (case-insensitive).
|
* Parses a job state from a string (case-insensitive).
|
||||||
@@ -31,10 +36,10 @@ public enum JobState {
|
|||||||
throw new IllegalArgumentException("Job state cannot be null or blank");
|
throw new IllegalArgumentException("Job state cannot be null or blank");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return valueOf(value.trim().toUpperCase());
|
return valueOf(value.trim().toUpperCase(Locale.ROOT));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Invalid job state: '" + value
|
||||||
"Invalid job state: '" + value + "'. Valid values are: queued, running, succeeded, failed, canceled");
|
+ "'. Valid values are: queued, running, succeeded, failed, canceled, killed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +49,7 @@ public enum JobState {
|
|||||||
* @return the state name in lowercase
|
* @return the state name in lowercase
|
||||||
*/
|
*/
|
||||||
public String toLowercase() {
|
public String toLowercase() {
|
||||||
return name().toLowerCase();
|
return name().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +58,7 @@ public enum JobState {
|
|||||||
* @return true if the job is in a terminal state
|
* @return true if the job is in a terminal state
|
||||||
*/
|
*/
|
||||||
public boolean isTerminal() {
|
public boolean isTerminal() {
|
||||||
return this == SUCCEEDED || this == FAILED || this == CANCELED;
|
return this == SUCCEEDED || this == FAILED || this == CANCELED || this == KILLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.samsonmedia.barn.util;
|
package com.samsonmedia.barn.util;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ public final class DurationParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long value = Long.parseLong(matcher.group(1));
|
long value = Long.parseLong(matcher.group(1));
|
||||||
String unit = matcher.group(2).toLowerCase();
|
String unit = matcher.group(2).toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
throw new IllegalArgumentException("Duration value must be positive: " + value);
|
throw new IllegalArgumentException("Duration value must be positive: " + value);
|
||||||
|
|||||||
+42
-168
@@ -1,187 +1,61 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcMessage",
|
"name": "ch.qos.logback.core.status.NopStatusListener",
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$RunJob",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$GetStatus",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$GetJob",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$KillJob",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$CleanJobs",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$GetServiceStatus",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$Shutdown",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcRequest$Reload",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcResponse$Ok",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.ipc.IpcResponse$Error",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.jobs.Job",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.jobs.JobManifest",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.state.JobState",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.execution.ResourceUsage",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.config.Config",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.config.ServiceConfig",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.config.StorageConfig",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.config.JobsConfig",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.samsonmedia.barn.config.CleanupConfig",
|
|
||||||
"allDeclaredConstructors": true,
|
|
||||||
"allPublicConstructors": true,
|
|
||||||
"allDeclaredMethods": true,
|
|
||||||
"allPublicMethods": true,
|
|
||||||
"allDeclaredFields": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "java.util.LinkedHashMap",
|
|
||||||
"allDeclaredConstructors": true,
|
"allDeclaredConstructors": true,
|
||||||
"allPublicConstructors": true
|
"allPublicConstructors": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "java.util.HashMap",
|
"name": "ch.qos.logback.core.helpers.NOPAppender",
|
||||||
"allDeclaredConstructors": true,
|
"allDeclaredConstructors": true,
|
||||||
"allPublicConstructors": true
|
"allPublicConstructors": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "java.util.ArrayList",
|
"name": "ch.qos.logback.core.FileAppender",
|
||||||
"allDeclaredConstructors": true,
|
"allDeclaredConstructors": true,
|
||||||
"allPublicConstructors": true
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "java.util.ImmutableCollections$ListN",
|
"name": "ch.qos.logback.core.rolling.RollingFileAppender",
|
||||||
"allDeclaredConstructors": true,
|
"allDeclaredConstructors": true,
|
||||||
"allPublicConstructors": true
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "java.util.ImmutableCollections$List12",
|
"name": "ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy",
|
||||||
"allDeclaredConstructors": true,
|
"allDeclaredConstructors": true,
|
||||||
"allPublicConstructors": true
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ch.qos.logback.classic.encoder.PatternLayoutEncoder",
|
||||||
|
"allDeclaredConstructors": true,
|
||||||
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ch.qos.logback.core.ConsoleAppender",
|
||||||
|
"allDeclaredConstructors": true,
|
||||||
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ch.qos.logback.classic.PatternLayout",
|
||||||
|
"allDeclaredConstructors": true,
|
||||||
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "net.logstash.logback.encoder.LogstashEncoder",
|
||||||
|
"allDeclaredConstructors": true,
|
||||||
|
"allPublicConstructors": true,
|
||||||
|
"allDeclaredMethods": true,
|
||||||
|
"allPublicMethods": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"resources": {
|
||||||
|
"includes": [
|
||||||
|
{"pattern": "logback.xml"},
|
||||||
|
{"pattern": "META-INF/.*"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"bundles": []
|
||||||
|
}
|
||||||
@@ -1,44 +1,24 @@
|
|||||||
<configuration>
|
<configuration debug="false">
|
||||||
<!-- Suppress logback's internal status messages -->
|
<!-- Suppress ALL logback output including internal status -->
|
||||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||||
|
|
||||||
<!-- Console appender for development/foreground -->
|
<!-- NOP appender - discards all logs -->
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="NOP" class="ch.qos.logback.core.helpers.NOPAppender"/>
|
||||||
<encoder>
|
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- File appender for daemon mode -->
|
<!-- File appender for service logging (only used when service enables it) -->
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||||
<file>${BARN_LOG_DIR:-/tmp/barn/logs}/barn.log</file>
|
<file>/tmp/barn/logs/barn.log</file>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
<append>true</append>
|
||||||
<fileNamePattern>${BARN_LOG_DIR:-/tmp/barn/logs}/barn.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
|
||||||
<maxFileSize>10MB</maxFileSize>
|
|
||||||
<maxHistory>7</maxHistory>
|
|
||||||
<totalSizeCap>100MB</totalSizeCap>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- JSON appender for structured logging -->
|
<!--
|
||||||
<appender name="JSON" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
Root logger OFF by default - CLI commands produce no log output.
|
||||||
<file>${BARN_LOG_DIR:-/tmp/barn/logs}/barn.json.log</file>
|
Service startup explicitly enables logging via LoggingConfig.
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
-->
|
||||||
<fileNamePattern>${BARN_LOG_DIR:-/tmp/barn/logs}/barn.json.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
<root level="OFF">
|
||||||
<maxFileSize>10MB</maxFileSize>
|
<appender-ref ref="NOP"/>
|
||||||
<maxHistory>7</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
|
||||||
<includeMdcKeyName>jobId</includeMdcKeyName>
|
|
||||||
<includeMdcKeyName>jobTag</includeMdcKeyName>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- Log to file only by default (CLI commands). Service foreground mode adds console programmatically -->
|
|
||||||
<root level="${BARN_LOG_LEVEL:-INFO}">
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Nested;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import com.samsonmedia.barn.config.Config;
|
||||||
import com.samsonmedia.barn.config.JobsConfig;
|
import com.samsonmedia.barn.config.JobsConfig;
|
||||||
import com.samsonmedia.barn.jobs.Job;
|
import com.samsonmedia.barn.jobs.Job;
|
||||||
import com.samsonmedia.barn.jobs.JobRepository;
|
import com.samsonmedia.barn.jobs.JobRepository;
|
||||||
@@ -33,7 +34,8 @@ class CrashRecoveryTest {
|
|||||||
private JobRepository repository;
|
private JobRepository repository;
|
||||||
private HeartbeatChecker heartbeatChecker;
|
private HeartbeatChecker heartbeatChecker;
|
||||||
private CrashRecovery crashRecovery;
|
private CrashRecovery crashRecovery;
|
||||||
private JobsConfig config;
|
private JobsConfig jobsConfig;
|
||||||
|
private Config config;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws IOException {
|
void setUp() throws IOException {
|
||||||
@@ -41,8 +43,9 @@ class CrashRecoveryTest {
|
|||||||
dirs.initialize();
|
dirs.initialize();
|
||||||
repository = new JobRepository(dirs);
|
repository = new JobRepository(dirs);
|
||||||
heartbeatChecker = new HeartbeatChecker(Duration.ofSeconds(30));
|
heartbeatChecker = new HeartbeatChecker(Duration.ofSeconds(30));
|
||||||
crashRecovery = new CrashRecovery(repository, heartbeatChecker, dirs);
|
config = Config.withDefaults();
|
||||||
config = JobsConfig.withDefaults();
|
crashRecovery = new CrashRecovery(repository, heartbeatChecker, dirs, config);
|
||||||
|
jobsConfig = JobsConfig.withDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@@ -50,19 +53,25 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructor_withNullRepository_shouldThrowException() {
|
void constructor_withNullRepository_shouldThrowException() {
|
||||||
assertThatThrownBy(() -> new CrashRecovery(null, heartbeatChecker, dirs))
|
assertThatThrownBy(() -> new CrashRecovery(null, heartbeatChecker, dirs, config))
|
||||||
.isInstanceOf(NullPointerException.class);
|
.isInstanceOf(NullPointerException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructor_withNullHeartbeatChecker_shouldThrowException() {
|
void constructor_withNullHeartbeatChecker_shouldThrowException() {
|
||||||
assertThatThrownBy(() -> new CrashRecovery(repository, null, dirs))
|
assertThatThrownBy(() -> new CrashRecovery(repository, null, dirs, config))
|
||||||
.isInstanceOf(NullPointerException.class);
|
.isInstanceOf(NullPointerException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructor_withNullDirs_shouldThrowException() {
|
void constructor_withNullDirs_shouldThrowException() {
|
||||||
assertThatThrownBy(() -> new CrashRecovery(repository, heartbeatChecker, null))
|
assertThatThrownBy(() -> new CrashRecovery(repository, heartbeatChecker, null, config))
|
||||||
|
.isInstanceOf(NullPointerException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void constructor_withNullConfig_shouldThrowException() {
|
||||||
|
assertThatThrownBy(() -> new CrashRecovery(repository, heartbeatChecker, dirs, null))
|
||||||
.isInstanceOf(NullPointerException.class);
|
.isInstanceOf(NullPointerException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +88,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withQueuedJobs_shouldNotRecover() throws IOException {
|
void recoverOrphanedJobs_withQueuedJobs_shouldNotRecover() throws IOException {
|
||||||
repository.create(List.of("echo", "test"), "test", config);
|
repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
|
|
||||||
List<Job> recovered = crashRecovery.recoverOrphanedJobs();
|
List<Job> recovered = crashRecovery.recoverOrphanedJobs();
|
||||||
|
|
||||||
@@ -88,7 +97,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withCompletedJobs_shouldNotRecover() throws IOException {
|
void recoverOrphanedJobs_withCompletedJobs_shouldNotRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
repository.markStarted(job.id(), 12345);
|
repository.markStarted(job.id(), 12345);
|
||||||
repository.markCompleted(job.id(), 0, null);
|
repository.markCompleted(job.id(), 0, null);
|
||||||
|
|
||||||
@@ -99,7 +108,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withRunningJobFreshHeartbeat_shouldNotRecover() throws IOException {
|
void recoverOrphanedJobs_withRunningJobFreshHeartbeat_shouldNotRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
repository.markStarted(job.id(), ProcessUtils.getCurrentPid()); // Use current PID (alive)
|
repository.markStarted(job.id(), ProcessUtils.getCurrentPid()); // Use current PID (alive)
|
||||||
repository.updateHeartbeat(job.id(), Instant.now()); // Fresh heartbeat
|
repository.updateHeartbeat(job.id(), Instant.now()); // Fresh heartbeat
|
||||||
|
|
||||||
@@ -110,7 +119,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withRunningJobStaleHeartbeatDeadProcess_shouldRecover() throws IOException {
|
void recoverOrphanedJobs_withRunningJobStaleHeartbeatDeadProcess_shouldRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
// Use a PID that's unlikely to exist (very high number)
|
// Use a PID that's unlikely to exist (very high number)
|
||||||
repository.markStarted(job.id(), 999999999L);
|
repository.markStarted(job.id(), 999999999L);
|
||||||
// Set a stale heartbeat
|
// Set a stale heartbeat
|
||||||
@@ -121,15 +130,15 @@ class CrashRecoveryTest {
|
|||||||
assertThat(recovered).hasSize(1);
|
assertThat(recovered).hasSize(1);
|
||||||
assertThat(recovered.get(0).id()).isEqualTo(job.id());
|
assertThat(recovered.get(0).id()).isEqualTo(job.id());
|
||||||
|
|
||||||
// Verify job is now marked as failed
|
// Verify job was killed and auto-retried (state is QUEUED with retry count incremented)
|
||||||
Job updatedJob = repository.findById(job.id()).orElseThrow();
|
Job updatedJob = repository.findById(job.id()).orElseThrow();
|
||||||
assertThat(updatedJob.state()).isEqualTo(JobState.FAILED);
|
assertThat(updatedJob.state()).isEqualTo(JobState.QUEUED);
|
||||||
assertThat(updatedJob.error()).contains("orphaned");
|
assertThat(updatedJob.retryCount()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withRunningJobNoHeartbeatDeadProcess_shouldRecover() throws IOException {
|
void recoverOrphanedJobs_withRunningJobNoHeartbeatDeadProcess_shouldRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
repository.markStarted(job.id(), 999999999L);
|
repository.markStarted(job.id(), 999999999L);
|
||||||
// Clear heartbeat to simulate crash before first heartbeat
|
// Clear heartbeat to simulate crash before first heartbeat
|
||||||
clearHeartbeat(job.id());
|
clearHeartbeat(job.id());
|
||||||
@@ -142,7 +151,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withRunningJobStaleHeartbeatAliveProcess_shouldNotRecover() throws IOException {
|
void recoverOrphanedJobs_withRunningJobStaleHeartbeatAliveProcess_shouldNotRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
// Use current process PID which is definitely alive
|
// Use current process PID which is definitely alive
|
||||||
repository.markStarted(job.id(), ProcessUtils.getCurrentPid());
|
repository.markStarted(job.id(), ProcessUtils.getCurrentPid());
|
||||||
// Set a stale heartbeat
|
// Set a stale heartbeat
|
||||||
@@ -156,7 +165,7 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_withRunningJobNoPid_shouldRecover() throws IOException {
|
void recoverOrphanedJobs_withRunningJobNoPid_shouldRecover() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
// Manually set running state without PID (simulates partial write)
|
// Manually set running state without PID (simulates partial write)
|
||||||
StateFiles stateFiles = new StateFiles(dirs.getJobDir(job.id()));
|
StateFiles stateFiles = new StateFiles(dirs.getJobDir(job.id()));
|
||||||
stateFiles.writeState(JobState.RUNNING);
|
stateFiles.writeState(JobState.RUNNING);
|
||||||
@@ -171,7 +180,7 @@ class CrashRecoveryTest {
|
|||||||
void recoverOrphanedJobs_withMultipleOrphanedJobs_shouldRecoverAll() throws IOException {
|
void recoverOrphanedJobs_withMultipleOrphanedJobs_shouldRecoverAll() throws IOException {
|
||||||
// Create 3 orphaned jobs
|
// Create 3 orphaned jobs
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Job job = repository.create(List.of("echo", "test" + i), "test", config);
|
Job job = repository.create(List.of("echo", "test" + i), "test", jobsConfig);
|
||||||
repository.markStarted(job.id(), 999999999L + i);
|
repository.markStarted(job.id(), 999999999L + i);
|
||||||
setStaleHeartbeat(job.id(), Duration.ofMinutes(5));
|
setStaleHeartbeat(job.id(), Duration.ofMinutes(5));
|
||||||
}
|
}
|
||||||
@@ -183,16 +192,41 @@ class CrashRecoveryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recoverOrphanedJobs_shouldSetCorrectExitCode() throws IOException {
|
void recoverOrphanedJobs_shouldSetCorrectExitCode() throws IOException {
|
||||||
Job job = repository.create(List.of("echo", "test"), "test", config);
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
repository.markStarted(job.id(), 999999999L);
|
repository.markStarted(job.id(), 999999999L);
|
||||||
setStaleHeartbeat(job.id(), Duration.ofMinutes(5));
|
setStaleHeartbeat(job.id(), Duration.ofMinutes(5));
|
||||||
|
|
||||||
crashRecovery.recoverOrphanedJobs();
|
crashRecovery.recoverOrphanedJobs();
|
||||||
|
|
||||||
Job updatedJob = repository.findById(job.id()).orElseThrow();
|
Job updatedJob = repository.findById(job.id()).orElseThrow();
|
||||||
// Exit code is stored as symbolic string, so we check error message
|
// Verify the job was killed and auto-retried (state is QUEUED with retry count incremented)
|
||||||
assertThat(updatedJob.error()).contains("orphaned");
|
assertThat(updatedJob.state()).isEqualTo(JobState.QUEUED);
|
||||||
assertThat(updatedJob.finishedAt()).isNotNull();
|
assertThat(updatedJob.retryCount()).isEqualTo(1);
|
||||||
|
assertThat(updatedJob.retryAt()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void recoverOrphanedJobs_withRetriesExhausted_shouldStayKilled() throws IOException {
|
||||||
|
// Create a config with maxRetries = 0 so no auto-retry
|
||||||
|
Config noRetryConfig = new Config(
|
||||||
|
config.service(),
|
||||||
|
new JobsConfig(config.jobs().defaultTimeoutSeconds(), 0, 1, 1.0, List.of()),
|
||||||
|
config.cleanup(),
|
||||||
|
config.storage()
|
||||||
|
);
|
||||||
|
CrashRecovery noRetryCrashRecovery = new CrashRecovery(
|
||||||
|
repository, heartbeatChecker, dirs, noRetryConfig);
|
||||||
|
|
||||||
|
Job job = repository.create(List.of("echo", "test"), "test", jobsConfig);
|
||||||
|
repository.markStarted(job.id(), 999999999L);
|
||||||
|
setStaleHeartbeat(job.id(), Duration.ofMinutes(5));
|
||||||
|
|
||||||
|
noRetryCrashRecovery.recoverOrphanedJobs();
|
||||||
|
|
||||||
|
Job updatedJob = repository.findById(job.id()).orElseThrow();
|
||||||
|
// With retries disabled, job should stay in KILLED state
|
||||||
|
assertThat(updatedJob.state()).isEqualTo(JobState.KILLED);
|
||||||
|
assertThat(updatedJob.error()).contains("killed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -227,6 +227,35 @@ class JobRepositoryTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class MarkKilled {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void markKilled_shouldSetKilledState() throws IOException {
|
||||||
|
Job job = repository.create(List.of("echo"), null, config);
|
||||||
|
repository.markStarted(job.id(), 12345L);
|
||||||
|
|
||||||
|
repository.markKilled(job.id(), "Process killed - daemon restarted");
|
||||||
|
|
||||||
|
Job updated = repository.findById(job.id()).orElseThrow();
|
||||||
|
assertThat(updated.state()).isEqualTo(JobState.KILLED);
|
||||||
|
assertThat(updated.error()).isEqualTo("Process killed - daemon restarted");
|
||||||
|
assertThat(updated.finishedAt()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void markKilled_withNullError_shouldSucceed() throws IOException {
|
||||||
|
Job job = repository.create(List.of("echo"), null, config);
|
||||||
|
repository.markStarted(job.id(), 12345L);
|
||||||
|
|
||||||
|
repository.markKilled(job.id(), null);
|
||||||
|
|
||||||
|
Job updated = repository.findById(job.id()).orElseThrow();
|
||||||
|
assertThat(updated.state()).isEqualTo(JobState.KILLED);
|
||||||
|
assertThat(updated.error()).isNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class ScheduleRetry {
|
class ScheduleRetry {
|
||||||
|
|
||||||
@@ -244,6 +273,21 @@ class JobRepositoryTest {
|
|||||||
assertThat(updated.retryCount()).isEqualTo(1);
|
assertThat(updated.retryCount()).isEqualTo(1);
|
||||||
assertThat(updated.retryAt()).isEqualTo(retryAt);
|
assertThat(updated.retryAt()).isEqualTo(retryAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void scheduleRetry_fromKilledState_shouldTransitionToQueued() throws IOException {
|
||||||
|
Job job = repository.create(List.of("echo"), null, config);
|
||||||
|
repository.markStarted(job.id(), 12345L);
|
||||||
|
repository.markKilled(job.id(), "Daemon restarted");
|
||||||
|
Instant retryAt = Instant.now().plusSeconds(30);
|
||||||
|
|
||||||
|
repository.scheduleRetry(job.id(), retryAt);
|
||||||
|
|
||||||
|
Job updated = repository.findById(job.id()).orElseThrow();
|
||||||
|
assertThat(updated.state()).isEqualTo(JobState.QUEUED);
|
||||||
|
assertThat(updated.retryCount()).isEqualTo(1);
|
||||||
|
assertThat(updated.retryAt()).isEqualTo(retryAt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
@@ -44,11 +44,28 @@ class JobStateMachineTest {
|
|||||||
JobStateMachine.validateTransition(JobState.RUNNING, JobState.CANCELED);
|
JobStateMachine.validateTransition(JobState.RUNNING, JobState.CANCELED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void running_toKilled_shouldBeValid() {
|
||||||
|
JobStateMachine.validateTransition(JobState.RUNNING, JobState.KILLED);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void failed_toQueued_shouldBeValid() {
|
void failed_toQueued_shouldBeValid() {
|
||||||
JobStateMachine.validateTransition(JobState.FAILED, JobState.QUEUED);
|
JobStateMachine.validateTransition(JobState.FAILED, JobState.QUEUED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void killed_toQueued_shouldBeValid() {
|
||||||
|
JobStateMachine.validateTransition(JobState.KILLED, JobState.QUEUED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void killed_toRunning_shouldThrowException() {
|
||||||
|
assertThatThrownBy(() ->
|
||||||
|
JobStateMachine.validateTransition(JobState.KILLED, JobState.RUNNING))
|
||||||
|
.isInstanceOf(IllegalStateException.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void queued_toSucceeded_shouldThrowException() {
|
void queued_toSucceeded_shouldThrowException() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
@@ -111,7 +128,9 @@ class JobStateMachineTest {
|
|||||||
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.SUCCEEDED)).isTrue();
|
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.SUCCEEDED)).isTrue();
|
||||||
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.FAILED)).isTrue();
|
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.FAILED)).isTrue();
|
||||||
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.CANCELED)).isTrue();
|
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.CANCELED)).isTrue();
|
||||||
|
assertThat(JobStateMachine.isValidTransition(JobState.RUNNING, JobState.KILLED)).isTrue();
|
||||||
assertThat(JobStateMachine.isValidTransition(JobState.FAILED, JobState.QUEUED)).isTrue();
|
assertThat(JobStateMachine.isValidTransition(JobState.FAILED, JobState.QUEUED)).isTrue();
|
||||||
|
assertThat(JobStateMachine.isValidTransition(JobState.KILLED, JobState.QUEUED)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -119,6 +138,7 @@ class JobStateMachineTest {
|
|||||||
assertThat(JobStateMachine.isValidTransition(JobState.QUEUED, JobState.SUCCEEDED)).isFalse();
|
assertThat(JobStateMachine.isValidTransition(JobState.QUEUED, JobState.SUCCEEDED)).isFalse();
|
||||||
assertThat(JobStateMachine.isValidTransition(JobState.SUCCEEDED, JobState.QUEUED)).isFalse();
|
assertThat(JobStateMachine.isValidTransition(JobState.SUCCEEDED, JobState.QUEUED)).isFalse();
|
||||||
assertThat(JobStateMachine.isValidTransition(JobState.CANCELED, JobState.RUNNING)).isFalse();
|
assertThat(JobStateMachine.isValidTransition(JobState.CANCELED, JobState.RUNNING)).isFalse();
|
||||||
|
assertThat(JobStateMachine.isValidTransition(JobState.KILLED, JobState.RUNNING)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,9 +158,9 @@ class JobStateMachineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void forRunning_shouldReturnSucceededFailedCanceled() {
|
void forRunning_shouldReturnSucceededFailedCanceledKilled() {
|
||||||
assertThat(JobStateMachine.getValidTransitions(JobState.RUNNING))
|
assertThat(JobStateMachine.getValidTransitions(JobState.RUNNING))
|
||||||
.containsExactlyInAnyOrder(JobState.SUCCEEDED, JobState.FAILED, JobState.CANCELED);
|
.containsExactlyInAnyOrder(JobState.SUCCEEDED, JobState.FAILED, JobState.CANCELED, JobState.KILLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -159,6 +179,12 @@ class JobStateMachineTest {
|
|||||||
assertThat(JobStateMachine.getValidTransitions(JobState.CANCELED)).isEmpty();
|
assertThat(JobStateMachine.getValidTransitions(JobState.CANCELED)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void forKilled_shouldReturnQueued() {
|
||||||
|
assertThat(JobStateMachine.getValidTransitions(JobState.KILLED))
|
||||||
|
.containsExactly(JobState.QUEUED);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withNull_shouldThrowException() {
|
void withNull_shouldThrowException() {
|
||||||
assertThatThrownBy(() -> JobStateMachine.getValidTransitions(null))
|
assertThatThrownBy(() -> JobStateMachine.getValidTransitions(null))
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class JobStateTest {
|
|||||||
assertThat(JobState.fromString("succeeded")).isEqualTo(JobState.SUCCEEDED);
|
assertThat(JobState.fromString("succeeded")).isEqualTo(JobState.SUCCEEDED);
|
||||||
assertThat(JobState.fromString("failed")).isEqualTo(JobState.FAILED);
|
assertThat(JobState.fromString("failed")).isEqualTo(JobState.FAILED);
|
||||||
assertThat(JobState.fromString("canceled")).isEqualTo(JobState.CANCELED);
|
assertThat(JobState.fromString("canceled")).isEqualTo(JobState.CANCELED);
|
||||||
|
assertThat(JobState.fromString("killed")).isEqualTo(JobState.KILLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -54,7 +55,7 @@ class JobStateTest {
|
|||||||
assertThatThrownBy(() -> JobState.fromString("invalid"))
|
assertThatThrownBy(() -> JobState.fromString("invalid"))
|
||||||
.isInstanceOf(IllegalArgumentException.class)
|
.isInstanceOf(IllegalArgumentException.class)
|
||||||
.hasMessageContaining("Invalid job state")
|
.hasMessageContaining("Invalid job state")
|
||||||
.hasMessageContaining("queued, running, succeeded, failed, canceled");
|
.hasMessageContaining("queued, running, succeeded, failed, canceled, killed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -64,6 +65,7 @@ class JobStateTest {
|
|||||||
assertThat(JobState.SUCCEEDED.toLowercase()).isEqualTo("succeeded");
|
assertThat(JobState.SUCCEEDED.toLowercase()).isEqualTo("succeeded");
|
||||||
assertThat(JobState.FAILED.toLowercase()).isEqualTo("failed");
|
assertThat(JobState.FAILED.toLowercase()).isEqualTo("failed");
|
||||||
assertThat(JobState.CANCELED.toLowercase()).isEqualTo("canceled");
|
assertThat(JobState.CANCELED.toLowercase()).isEqualTo("canceled");
|
||||||
|
assertThat(JobState.KILLED.toLowercase()).isEqualTo("killed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -71,6 +73,7 @@ class JobStateTest {
|
|||||||
assertThat(JobState.SUCCEEDED.isTerminal()).isTrue();
|
assertThat(JobState.SUCCEEDED.isTerminal()).isTrue();
|
||||||
assertThat(JobState.FAILED.isTerminal()).isTrue();
|
assertThat(JobState.FAILED.isTerminal()).isTrue();
|
||||||
assertThat(JobState.CANCELED.isTerminal()).isTrue();
|
assertThat(JobState.CANCELED.isTerminal()).isTrue();
|
||||||
|
assertThat(JobState.KILLED.isTerminal()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -90,5 +93,6 @@ class JobStateTest {
|
|||||||
assertThat(JobState.SUCCEEDED.isActive()).isFalse();
|
assertThat(JobState.SUCCEEDED.isActive()).isFalse();
|
||||||
assertThat(JobState.FAILED.isActive()).isFalse();
|
assertThat(JobState.FAILED.isActive()).isFalse();
|
||||||
assertThat(JobState.CANCELED.isActive()).isFalse();
|
assertThat(JobState.CANCELED.isActive()).isFalse();
|
||||||
|
assertThat(JobState.KILLED.isActive()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user