Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Taskmaster

Rust process supervisor for the 42 Taskmaster project. It runs in the foreground, keeps configured jobs under supervision, logs lifecycle events, and provides an interactive control shell.

Evaluation status

The mandatory marking-sheet behaviors are implemented:

RequirementImplementation / proof
Control shellstatus, start, stop, restart, reload, exit
Config at launchTOML loader with validation
Hot reloadShell reload and external SIGHUP
Selective reloadUnchanged program groups keep their existing PIDs
LoggingSTART, STOP, RESTART, CRASH, FATAL, CONFIG_RELOAD
Required optionsAll options from the subject are represented below
Graceful stopConfigured signal, timeout, then SIGKILL escalation
Clean shutdownEvery attached process group is stopped before exit
Retry abortEarly failures become FATAL after startretries
Output handlingOmitted output paths discard; configured paths append

Only serde and toml are third-party dependencies. They are used exclusively for configuration parsing, as allowed by the subject. Signals, process groups, timestamps, shell parsing, and logging use the Rust standard library and small operating-system FFI declarations.

Build and run

cargo build --locked
cargo run -- config/evaluation.toml

The binary remains in the foreground:

./target/debug/taskmaster config/evaluation.toml

Control shell

status
start <program|all>
stop <program|all>
restart <program|all>
reload
history
help
quit
exit

status shows one row per configured instance with its PID, STARTING, RUNNING, STOPPED, or FATAL state, and uptime.

quit, exit, Ctrl-C, and SIGTERM stop the supervisor. Taskmaster sends each configured stop signal to the whole child process group, waits stoptime, then sends SIGKILL to any survivors. Descendants do not remain orphaned.

Hot reload

Both interfaces read the original config path again:

taskmaster> reload
kill -HUP <taskmaster-pid>

Reload is diff-based:

  • unchanged programs and their PIDs are preserved;
  • removed programs are stopped and removed;
  • added programs are registered and started when autostart = true;
  • changed programs are gracefully stopped, replaced, and restarted if they were active or are configured for autostart;
  • invalid replacement files are rejected before runtime state changes.

Configuration

[programs.worker]
cmd = "while true; do echo $MESSAGE; sleep 2; done"numprocs = 2autostart = trueautorestart = "unexpected"exitcodes = [0]
startretries = 3starttime = 1stopsignal = "TERM"stoptime = 2stdout = "/tmp/worker.out"stderr = "/tmp/worker.err"log = "/tmp/worker.lifecycle.log"workingdir = "/tmp"umask = 0o027
[programs.worker.env]
MESSAGE = "managed by taskmaster"
FieldMeaningDefault
cmdShell command used to launch the programrequired
numprocsInstances to create and supervise1
autostartStart when Taskmaster launchesfalse
autorestartalways, never, or unexpectednever
exitcodesExpected exit codes[0]
startretriesRetries after early startup failures0
starttimeSeconds required to reach RUNNING; 0 accepts immediate exit1
stopsignalGraceful stop signal name or numberTERM
stoptimeSeconds before SIGKILL; 0 escalates immediately5
stdoutAppend stdout to this file; omit to discarddiscard
stderrAppend stderr to this file; omit to discarddiscard
logPer-program lifecycle log; omit for global logglobal
envEnvironment variables for the childinherited environment
workingdirChild working directoryTaskmaster directory
umaskChild Unix umaskinherited umask

Commands are executed through /bin/sh -c on Unix and cmd.exe /S /C on Windows. Shell built-ins such as exit 42, quoting, environment expansion, and redirections therefore work as configuration commands.

Short-lived commands

A command such as ls exits before the default one-second starttime, so it is correctly treated as a startup failure. Configure starttime = 0 for intentional one-shot commands:

[programs.oneshot]
cmd = "ls -la"starttime = 0autorestart = "never"exitcodes = [0]

NUL is not a typo

NUL is the Windows null device, equivalent to /dev/null on Unix. Taskmaster selects the correct name at compile time.

Logging

The fallback log is ./logs/taskmaster.log. A program-specific log path overrides it for that program.

Logged events:

  • process start and PID;
  • graceful/manual stop;
  • unexpected exit or signal death;
  • automatic restart and reason;
  • retry exhaustion (FATAL and attempt count);
  • configuration reload and source path.

Evaluator proof

Run all unit tests:

cargo test --workspace

On Linux, run the end-to-end marking-sheet smoke test:

bash scripts/evaluator_smoke.sh

It proves:

  1. initial autostart;
  2. external SIGHUP reload;
  3. unchanged PID preservation;
  4. autostart of an added program;
  5. shell-command reload;
  6. removal of a program;
  7. accurate status output;
  8. shutdown through exit;
  9. no surviving supervised children.

Use config/evaluation.toml during the defense to demonstrate every required configuration option, retry exhaustion, and a short-lived command.

Project layout

  • bin/main.rs: startup, signal installation, shell, shutdown
  • crates/config: TOML model and validation
  • crates/process: spawning, process groups, lifecycle reconciliation, selective reload
  • crates/signals: SIGINT/SIGTERM/SIGHUP flags
  • crates/logger: lifecycle logging
  • crates/tui: interactive control shell
  • scripts/evaluator_smoke.sh: end-to-end evaluator proof

About

a supervisord in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages