command

package module
v0.0.0-...-ac32e08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

caddy-command

Caddy v2 module for running one-off commands at an endpoint.

Installation

xcaddy build v2.0.0 \
    --with github.com/abiosoft/caddy-command

Usage

Caddyfile
command [<matcher>] <command> [args...] {
    args        args...
    directory   directory
    timeout     timeout
    foreground
}
  • command - the command to run
  • matcher - caddyfile matcher
  • args... - the command arguments
  • directory - the directory to run the command from
  • timeout - the timeout to terminate the command process. Default is 10s.
  • foreground - if present, waits for the command to exit before responding to the http request.
Example

command can be the last action of a route block.

route /generate {
    ... # other directives e.g. for authentication
    command hugo generate --destination=/home/user/site/public
}
API
...
{
  "handle": [
    {
      "handler": "subroute",
      "routes": [
        {
          "handle": [
            {
              "command": "hugo",
              "args": [
                "--destination=/home/user/site/public"
              ],
              "foreground": true,
              "handler": "command",
              "timeout": "5s"
            }
          ]
        }
      ]
    }
  ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// The command to run.
	Command string `json:"command,omitempty"`
	// The command args.
	Args []string `json:"args,omitempty"`
	// The directory to run the command from.
	// Defaults to current directory.
	Directory string `json:"directory,omitempty"`
	// If the command should run in the foreground.
	// Setting it makes the command run in the foreground.
	Foreground bool `json:"foreground,omitempty"`

	// Timeout for the command. The command will be killed
	// after timeout has elapsed if it is still running.
	// Defaults to 10s.
	Timeout string `json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

Command module implements an HTTP handler that runs a shell command.

func (Command) CaddyModule

func (Command) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Command) Provision

func (m *Command) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (Command) ServeHTTP

func (m Command) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Command) UnmarshalCaddyfile

func (m *Command) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile configures the plugin from Caddyfile. Syntax:

command [<matcher>] <command> [args...] {
    args        <text>...
    directory   <text>
    timeout     <duration>
    foreground
}

func (Command) Validate

func (m Command) Validate() error

Validate implements caddy.Validator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL