Skip to content

โšก Quick Start Guide

Get up and running with Sloth Runner in under 10 minutes! This guide will walk you through installation, basic usage, and your first distributed task execution.

๐Ÿš€ Installation

Option 1: Download Binary

# Download latest release
curl -L https://github.com/chalkan3-sloth/sloth-runner/releases/latest/download/sloth-runner-linux-amd64 -o sloth-runner
chmod +x sloth-runner
sudo mv sloth-runner /usr/local/bin/

Option 2: Build from Source

# Clone repository
git clone https://github.com/chalkan3-sloth/sloth-runner.git
cd sloth-runner

# Build binary
go build -o sloth-runner ./cmd/sloth-runner

# Add to PATH
export PATH=$PATH:$(pwd)

Option 3: Docker

# Pull official image
docker pull slothrunner/sloth-runner:latest

# Create alias for easy usage
alias sloth-runner='docker run --rm -v $(pwd):/workspace slothrunner/sloth-runner'

๐Ÿ“‹ Verify Installation

# Check version
sloth-runner --version

# View available commands
sloth-runner --help

Expected output:

Sloth Runner v2.0.0
A powerful task orchestration platform with Lua scripting

๐ŸŽฏ Your First Task

Create your first Lua task file:

# Create a simple task file
cat > hello-world.sloth << 'EOF'
-- Define individual tasks
local greet = task("greet")
    :description("Say hello to the world")
    :command(function(this, params)
        log.info("๐ŸŽ‰ Hello from Sloth Runner!")

        -- Get system information
        local hostname, _ = exec.run("hostname")
        local whoami, _ = exec.run("whoami")

        log.info("Running on: " .. hostname)
        log.info("User: " .. whoami)

        -- Use state management
        state.set("last_greeting", os.time())
        local count = state.increment("greeting_count", 1)

        log.info("This is greeting #" .. count)

        return true, "Hello World task completed successfully!"
    end)
    :build()

local system_info = task("system_info")
    :description("Display system metrics")
    :depends_on({"greet"})
    :command(function(this, params)
        log.info("๐Ÿ“Š System Information:")

        -- Get system metrics
        local cpu = metrics.system_cpu()
        local memory = metrics.system_memory()
        local disk = metrics.system_disk()

        log.info("CPU Usage: " .. string.format("%.1f%%", cpu))
        log.info("Memory: " .. string.format("%.1f%% (%.0f MB used)",
            memory.percent, memory.used_mb))
        log.info("Disk: " .. string.format("%.1f%% (%.1f GB used)",
            disk.percent, disk.used_gb))

        -- Record metrics
        metrics.gauge("quickstart_cpu", cpu)
        metrics.gauge("quickstart_memory", memory.percent)

        return true, "System info collected"
    end)
    :build()

-- Define workflow
workflow
    .define("hello_world")
    :description("My first Sloth Runner task")
    :version("1.0.0")
    :tasks({greet, system_info})
EOF

๐Ÿƒโ€โ™‚๏ธ Run Your First Task

# Execute the task
sloth-runner run -f hello-world.sloth

# Or run specific task
sloth-runner run -f hello-world.sloth -t greet

Expected output:

2024-01-15 10:30:00 INFO ๐ŸŽ‰ Hello from Sloth Runner!
2024-01-15 10:30:00 INFO Running on: my-computer
2024-01-15 10:30:00 INFO User: myuser
2024-01-15 10:30:00 INFO This is greeting #1
2024-01-15 10:30:01 INFO ๐Ÿ“Š System Information:
2024-01-15 10:30:01 INFO CPU Usage: 15.2%
2024-01-15 10:30:01 INFO Memory: 45.8% (7520 MB used)
2024-01-15 10:30:01 INFO Disk: 67.3% (234.5 GB used)
โœ… Task 'hello_world' completed successfully!

๐ŸŒ Setting Up Distributed Execution

Step 1: Start Master Server

# Start master on your main machine (e.g., 192.168.1.100)
sloth-runner master --port 50053 --bind-address 192.168.1.100

# Or with enhanced features
sloth-runner master --port 50053 --metrics-port 8080 --dashboard-port 3000

Step 2: Deploy Remote Agents

On remote machine 1 (192.168.1.101):

# Download sloth-runner binary to remote machine
scp sloth-runner user@192.168.1.101:/usr/local/bin/

# SSH and start agent
ssh user@192.168.1.101
sloth-runner agent start \
    --name agent-1 \
    --master 192.168.1.100:50053 \
    --port 50051 \
    --bind-address 192.168.1.101

On remote machine 2 (192.168.1.102):

# SSH and start agent  
ssh user@192.168.1.102
sloth-runner agent start \
    --name agent-2 \
    --master 192.168.1.100:50053 \
    --port 50051 \
    --bind-address 192.168.1.102

Step 3: Verify Agent Registration

# List registered agents
sloth-runner agent list --master 192.168.1.100:50053

Expected output:

Registered Agents:
  agent-1    192.168.1.101:50051    Active    2s ago
  agent-2    192.168.1.102:50051    Active    1s ago

Step 4: Run Distributed Tasks

# Execute command on specific agent
sloth-runner agent run agent-1 "echo 'Hello from Agent 1'" --master 192.168.1.100:50053

# Execute on all agents
sloth-runner agent run agent-1 "uptime" --master 192.168.1.100:50053 &
sloth-runner agent run agent-2 "uptime" --master 192.168.1.100:50053 &
wait

๐Ÿ“Š Exploring Advanced Features

State Management Example

-- Create state-demo.sloth
local setup_state = task("setup_state")
    :description("Initialize application state")
    :command(function(this, params)
        -- Initialize configuration
        state.set("app_config", {
            version = "1.0.0",
            environment = "development",
            debug = true
        })

        -- Set TTL for session data (5 minutes)
        state.set("session_token", "abc123xyz", 300)

        -- Initialize counters
        state.set("api_calls", 0)
        state.set("errors", 0)

        log.info("โœ… Application state initialized")
        return true, "State setup completed"
    end)
    :build()

local simulate_usage = task("simulate_usage")
    :description("Simulate application usage")
    :depends_on({"setup_state"})
    :command(function(this, params)
        -- Simulate API calls
        for i = 1, 10 do
            local calls = state.increment("api_calls", 1)

            -- Simulate occasional error
            if math.random(1, 10) > 8 then
                state.increment("errors", 1)
                log.warn("Simulated error occurred")
            end

            -- Add to processing queue
            state.list_push("processing_queue", {
                id = "req_" .. i,
                timestamp = os.time(),
                status = "pending"
            })

            exec.run("sleep 0.1") -- Small delay
        end

        local total_calls = state.get("api_calls")
        local total_errors = state.get("errors")
        local queue_size = state.list_length("processing_queue")

        log.info("๐Ÿ“Š Usage Summary:")
        log.info("  API Calls: " .. total_calls)
        log.info("  Errors: " .. total_errors)
        log.info("  Queue Size: " .. queue_size)

        return true, "Usage simulation completed"
    end)
    :build()

local process_queue = task("process_queue")
    :description("Process items in queue with locking")
    :depends_on({"simulate_usage"})
    :command(function(this, params)
        -- Process queue with distributed lock
        state.with_lock("queue_processing", function()
            log.info("๐Ÿ”’ Processing queue with exclusive lock...")

            local processed = 0
            while state.list_length("processing_queue") > 0 do
                local item = state.list_pop("processing_queue")
                log.info("Processing item: " .. item.id)
                processed = processed + 1
            end

            log.info("โœ… Processed " .. processed .. " items")
            state.set("last_processing_time", os.time())

        end, 30) -- 30 second timeout

        return true, "Queue processing completed"
    end)
    :build()

-- Define workflow
workflow
    .define("state_demo")
    :description("Demonstrate state management capabilities")
    :version("1.0.0")
    :tasks({setup_state, simulate_usage, process_queue})

Run the state demo:

sloth-runner run -f state-demo.sloth

Metrics Monitoring Example

-- Create metrics-demo.sloth
local collect_metrics = task("collect_metrics")
    :description("Collect system and custom metrics")
    :command(function(this, params)
        log.info("๐Ÿ“Š Collecting system metrics...")

        -- System metrics
        local cpu = metrics.system_cpu()
        local memory = metrics.system_memory()
        local disk = metrics.system_disk()

        log.info("System Status:")
        log.info("  CPU: " .. string.format("%.1f%%", cpu))
        log.info("  Memory: " .. string.format("%.1f%%", memory.percent))
        log.info("  Disk: " .. string.format("%.1f%%", disk.percent))

        -- Custom metrics
        metrics.gauge("demo_cpu_usage", cpu)
        metrics.counter("demo_executions", 1)

        -- Performance timer
        local processing_time = metrics.timer("data_processing", function()
            -- Simulate data processing
            local sum = 0
            for i = 1, 1000000 do
                sum = sum + math.sqrt(i)
            end
            return sum
        end)

        log.info("โฑ๏ธ Processing took: " .. string.format("%.2f ms", processing_time))

        -- Health check
        local health = metrics.health_status()
        log.info("๐Ÿฅ Overall health: " .. health.overall)

        -- Alert if CPU is high
        if cpu > 50 then
            metrics.alert("high_cpu_demo", {
                level = "warning",
                message = "CPU usage is elevated: " .. string.format("%.1f%%", cpu),
                value = cpu
            })
        end

        return true, "Metrics collection completed"
    end)
    :build()

-- Define workflow
workflow
    .define("metrics_demo")
    :description("Demonstrate metrics and monitoring")
    :version("1.0.0")
    :tasks({collect_metrics})

Run the metrics demo:

sloth-runner run -f metrics-demo.sloth

๐ŸŒ Access Web Dashboard

If you started the master with dashboard support:

# Open web dashboard
open http://192.168.1.100:3000

# View metrics endpoint
curl http://192.168.1.100:8080/metrics

# Check health status
curl http://192.168.1.100:8080/health

๐Ÿ“š What's Next?

Explore Core Concepts

  • ๐Ÿ“– Core Concepts - Understand tasks, workflows, and state
  • ๐Ÿ”ง CLI Commands - Master all available commands
  • ๐ŸŒ™ Lua API - Deep dive into scripting capabilities

Advanced Features

Cloud Integrations

Infrastructure as Code

  • ๐Ÿณ Docker - Container management
  • ๐Ÿ—๏ธ Pulumi - Modern infrastructure as code
  • ๐ŸŒ Terraform - Infrastructure provisioning

๐Ÿ†˜ Getting Help

Documentation

Community

Quick Troubleshooting

Agent won't connect to master?

# Check network connectivity
telnet 192.168.1.100 50053

# Verify master is running
sloth-runner agent list --master 192.168.1.100:50053

# Check firewall settings
sudo ufw status

Tasks failing with permission errors?

# Check user permissions
ls -la /usr/local/bin/sloth-runner

# Run with appropriate user
sudo -u myuser sloth-runner run -f task.sloth

State database issues?

# Check state database location
ls -la ~/.sloth-runner/

# View state statistics
sloth-runner state stats

# Clear corrupted state (careful!)
rm ~/.sloth-runner/state.db*

๐ŸŽ‰ Congratulations!

You've successfully: - โœ… Installed Sloth Runner - โœ… Executed your first task - โœ… Set up distributed agents - โœ… Explored state management - โœ… Monitored system metrics

You're now ready to build powerful, distributed task orchestration workflows with Sloth Runner! ๐Ÿš€

๐Ÿš€ Ready for More?

Explore advanced features and build production-ready workflows

Advanced Features โ†’ More Examples โ†’