Simple process manager in lua designed to be used similar to supervisord, but simpler to run
Find a file
des 45c18f75d3 Add test.lua to project structure in README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 16:14:06 +08:00
docs Initial commit: coroutine-based process manager with fork/exec support 2026-03-13 23:49:12 +08:00
examples Initial commit: coroutine-based process manager with fork/exec support 2026-03-13 23:49:12 +08:00
.gitignore Initial commit: coroutine-based process manager with fork/exec support 2026-03-13 23:49:12 +08:00
pm Initial commit: coroutine-based process manager with fork/exec support 2026-03-13 23:49:12 +08:00
procman.lua Fix save() to use bracket notation for non-identifier process names 2026-03-20 16:07:47 +08:00
README.md Add test.lua to project structure in README 2026-03-20 16:14:06 +08:00
test.lua Add self-contained tests for save/load round-trip and key formatting 2026-03-20 16:11:24 +08:00

procman

A simple process manager written in Lua. Uses coroutines for scheduling and luaposix fork/exec/waitpid for managing real OS processes.

Features

  • Define, start, stop, and monitor shell commands
  • Auto-restart with configurable retry limits
  • Process definitions stored in a config file (procs.conf)
  • CLI for managing processes from the terminal
  • Supervised foreground mode with signal handling (Ctrl-C)
  • Per-process log files (stdout/stderr)
  • Also supports in-process Lua coroutine tasks via the library API

Requirements

Install on Arch Linux

sudo pacman -S lua lua-posix

Install via LuaRocks

luarocks install luaposix

Quick Start

# Define some processes
./pm define web 'python3 -m http.server 8080' --restart
./pm define worker 'bash worker.sh' --restart --max-restarts 5
./pm define backup 'rsync -a /data /backup'

# View defined processes
./pm list

# Run the supervisor (foreground, Ctrl-C to stop)
./pm run

CLI Usage

pm define <name> <command> [--restart] [--max-restarts N]
pm undef  <name>
pm start  <name | --all>
pm stop   <name | --all>
pm kill   <name | --all>
pm restart <name | --all>
pm status [name]
pm list
pm run    [--tick N]
pm logs   <name> [--follow | -f]
pm edit

See docs/cli.md for full CLI reference.

Library Usage

local ProcessManager = require("procman")
local pm = ProcessManager.new()

-- Define a shell command process
pm:define("web", "python3 -m http.server 8080", {
    auto_restart = true,
    max_restarts = 10,
})

-- Define a Lua coroutine process
pm:define_lua("heartbeat", function(ctx)
    while not ctx:should_stop() do
        print("alive")
        ctx:yield()
    end
end)

-- Start and run
pm:start("web")
pm:start("heartbeat")
pm:run({ tick_interval = 1 })

See docs/api.md for full library reference.

Project Structure

procman/
  pm              -- CLI entry point (executable)
  procman.lua     -- Core library module
  docs/
    design.md     -- Architecture and implementation details
    api.md        -- Library API reference
    cli.md        -- CLI usage reference
  test.lua        -- Self-contained test suite
  examples/
    demo.lua      -- Demo script (exec + lua processes)
    procs.conf    -- Sample process definition file

Tests

No external dependencies required. Run:

lua test.lua

Documentation

License

Public domain. Use as you like.