From 6ccb6fff21c216222202d2640f1a290c5890819b Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 12 Jul 2022 20:46:15 -0600 Subject: [PATCH] cli: Add signal and exit code docs Also minor tweak to config comparison table --- src/docs/markdown/command-line.md | 34 ++++++++++++++++++++++++++++ src/docs/markdown/getting-started.md | 4 ++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/docs/markdown/command-line.md b/src/docs/markdown/command-line.md index c400088..4998e47 100644 --- a/src/docs/markdown/command-line.md +++ b/src/docs/markdown/command-line.md @@ -80,7 +80,11 @@ The ellipses `...` indicates a continuation, i.e. one or more parameters. - **[caddy version](#caddy-version)** Prints the version +- **[Signals](#signals)** + How Caddy handles signals +- **[Exit codes](#exit-codes)** + Emitted when the Caddy process exits ## Subcommands @@ -444,3 +448,33 @@ Validates a configuration file, then exits. This command deserializes the config
caddy version
Prints the version and exits. + + + +## Signals + +Caddy traps certain signals and ignores others. Signals can initiate specific process behavior. + +Signal | Behavior +-------|---------- +`SIGINT` | Graceful exit. Send signal again to force exit immediately. +`SIGQUIT` | Quits Caddy immediately, but still cleans up locks in storage because it is important. +`SIGTERM` | Graceful exit. +`SIGUSR1` | Ignored. For config updates, use the `caddy reload` command or [the API](/docs/api). +`SIGUSR2` | Ignored. +`SIGHUP` | Ignored. + +A graceful exit means that new connections are no longer accepted, and existing connections will be drained before the socket is closed. A grace period may apply (and is configurable). Once the grace period is up, connections will be forcefully terminated. Locks in storage and other resources that individual modules need to release are cleaned up during a graceful shutdown. + +## Exit codes + +Caddy returns a code when the process exits: + +Code | Meaning +-----|--------- +`0` | Normal exit. +`1` | Failed startup. **Do not automatically restart the process; it will likely error again unless changes are made.** +`2` | Forced quit. Caddy was forced to exit without cleaning up resources. +`3` | Failed quit. Caddy exited with some errors during cleanup. + +In bash, you can get the exit code of the last command with `echo $?`. \ No newline at end of file diff --git a/src/docs/markdown/getting-started.md b/src/docs/markdown/getting-started.md index 5aac550..60a2bbf 100644 --- a/src/docs/markdown/getting-started.md +++ b/src/docs/markdown/getting-started.md @@ -177,10 +177,10 @@ The Caddyfile seems easier than JSON, but should you always use it? There are pr JSON | Caddyfile -----|---------- -Full range of Caddy functionality | Most common parts of Caddy functionality Easy to generate | Easy to craft by hand -Easily programmable | Difficult to automate +Easily programmable | Awkward to automate Extremely expressive | Moderately expressive +Full range of Caddy functionality | Most of Caddy functionality Allows config traversal | Cannot traverse within Caddyfile Partial config changes | Whole config changes only Can be exported | Cannot be exported