LinuxCommandLibrary

foreman

Manage and provision servers' lifecycle

TLDR

Start an application with the Procfile in the current directory

$ foreman start
copy

Start an application with a specified Procfile
$ foreman start [[-f|--procfile]] [Procfile]
copy

Start a specific application
$ foreman start [process]
copy

Validate Procfile format
$ foreman check
copy

Run one-off commands with the process's environment
$ foreman run [command]
copy

Start all processes except the one named "worker"
$ foreman start [[-m|--formation]] all=1,[worker]=0
copy

SYNOPSIS

foreman [options] <command> [args]

PARAMETERS

-c, --concurrency COMMAND=COUNT
    Scale processes, e.g., web=2,worker=3

-d, --daemon
    Run detached as daemon process

-e, --env FILE
    Load environment from .env file

-f, --procfile FILE
    Specify alternate Procfile path (default: Procfile)

-p, --port PORT
    Base HTTP port (default: 5000)

--root PATH
    Application root directory (default: current)

-s, --single
    One worker per process type

-h, --help
    Show help

-v, --version
    Print version

DESCRIPTION

Foreman is a Ruby-based tool for managing and running applications defined in a Procfile. A Procfile lists processes like web servers, workers, and background jobs with commands to execute them. Foreman reads this file, starts all processes simultaneously, assigns dynamic ports (e.g., incrementing from a base port), multiplexes logs with color-coded output, and handles scaling.

Primarily used in development to mimic production environments, especially for Heroku apps. It supports environment variables via .env files, concurrency scaling, daemon mode, and exporting to systemd units. Run foreman start in a project directory with a Procfile to launch everything. Logs appear unified in the terminal, prefixed by process type.

Ideal for Rails, Node.js, Python apps. Install via gem install foreman. Supports foreman shell for interactive sessions, foreman run for one-off tasks, and foreman check for syntax validation.

CAVEATS

Requires Ruby and gem installation; not in standard distros. Dynamic ports may conflict; check logs for PID files in daemon mode.

COMMANDS

start: Launch processes.
run CMD: Execute one-off.
shell: Interactive shell.
check: Validate Procfile.
export format: Generate init scripts (e.g., systemd).

PROCFILE EXAMPLE

web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq

INSTALLATION

gem install foreman
Or via Bundler: gem 'foreman' in Gemfile.

HISTORY

Created by David Dollar in 2010 for Heroku Procfile compatibility. Maintained under ddollar/foreman on GitHub; version 0.87.2 as of 2023. Widely used in Ruby ecosystem.

SEE ALSO

systemd(1), nohup(1), screen(1)

Copied to clipboard