← Winnitude! Search  ·  Reader Mode (641 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 54 LINKS

GitHub - abiosoft/caddy-exec: Caddy v2 module for running one-off commands

Repository navigation

caddy-exec
Public

About

Caddy v2 module for running one-off commands

Topics

caddy caddy-module caddyserver command exec

Resources

Readme Apache-2.0 license Activity

Stars

156 stars

Watchers

2 watching

Forks

21 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page

Latest commit

 

History


37 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.gitignore .gitignore    
LICENSE LICENSE    
README.md README.md    
app.go app.go    
caddyfile.go caddyfile.go    
command.go command.go    
go.mod go.mod    
go.sum go.sum    
middleware.go middleware.go    
run.go run.go    

Repository files navigation

caddy-exec

Caddy v2 module for running one-off commands.

Installation

xcaddy build \
    --with github.com/abiosoft/caddy-exec

Usage

Commands can be configured to be triggered globally during startup/shutdown or by via a route.

They can also be configured to run in the background or foreground and to be terminated after a timeout.

⚠️ startup commands running on foreground will prevent Caddy from starting if they exit with an error.

Caddyfile

exec [<matcher>] [<command> [<args...>]] {
    command     <command> [<args...>]
    args        <args...>
    directory   <directory>
    timeout     <timeout>
    log         <log output module>
    err_log     <log output module>
    foreground
    pass_thru
    startup
    shutdown
}
  • matcher - Caddyfile matcher . When set, this command runs when there is an http request at the current route or the specified matcher. You may leverage other matchers to protect the endpoint.
  • command - command to run
  • args... - command arguments
  • directory - directory to run the command from
  • timeout - timeout to terminate the command's process. Default is 10s. A timeout of 0 runs indefinitely.
  • log - Caddy log output module for standard output log. Defaults to stderr.
  • err_log - Caddy log output module for standard error log. Defaults to the value of log (standard output log).
  • foreground - if present, runs the command in the foreground. For commands at http endpoints, the command will exit before the http request is responded to.
  • pass_thru - if present, enables pass-thru mode, which continues to the next HTTP handler in the route instead of responding directly
  • startup - if present, run the command at startup. Ignored in routes.
  • shutdown - if present, run the command at shutdown. Ignored in routes.

Example

exec can run at start via the global directive.

{
  exec hugo generate --destination=/home/user/site/public {
      timeout 0 # don't timeout
  }
}

exec can be the last action of a route block.

route /update {
    ... # other directives e.g. for authentication
    exec git pull origin master {
        log file /var/logs/hugo.log
    }
}

API/JSON

As a top level app for startup and shutdown commands.

As an handler within a route.

Dynamic Configuration

Caddy supports dynamic zero-downtime configuration reloads and it is possible to modify exec's configurations at runtime.

exec intelligently determines when Caddy is starting and shutting down. i.e. startup and shutdown commands do not get triggered during configuration reload, only during Caddy's actual startup and shutdown.

License

Apache 2

About

Caddy v2 module for running one-off commands

Topics

caddy caddy-module caddyserver command exec

Resources

Readme Apache-2.0 license Activity

Stars

156 stars

Watchers

2 watching

Forks

21 forks Report repository

Releases

Packages

Used by

Contributors

Languages