Categorygithub.com/xmidt-org/dms
modulepackage
0.2.0
Repository: https://github.com/xmidt-org/dms.git
Documentation: pkg.go.dev

# README

dms

dms is a command-line dead man's switch that will trigger one or more actions unless postponed.

Build Status codecov.io Go Report Card Apache V2 License Quality Gate Status GitHub release

Table of Contents

Overview

dms is a command-line utility that will trigger one or more actions unless postponed by performing an HTTP PUT to its /postpone endpoint.

Usage

dms --help
Usage: dms --exec=EXEC,...

A dead man's switch which invokes one or more actions unless postponed on
regular intervals. To postpone the action(s), issue an HTTP PUT to **/postpone**,
with no body, to the configured listen address.

Flags:
  -h, --help             Show context-sensitive help.
  -e, --exec=EXEC,...    one or more commands to execute when the switch
                         triggers
  -d, --dir=STRING       the working directory for all commands
  -h, --http=":8080"     the HTTP listen address or port
  -t, --ttl=1m           the maximum interval for TTL updates to keep the switch
                         open
  -m, --misses=1         the maximum number of missed updates allowed before the
                         switch closes
      --debug            produce debug logging

Actions

Actions are supplied on the command line via --exec or -e. At least (1) action is required. When triggered, each action will be executed one at a time, in the order specified on the command line. After triggering actions, dms will exit.

dms --exec "echo 'here is just one action'"
dms --exec "echo '1'" --exec "echo '2'"

HTTP

The --http or -h options change the bind address for the HTTP server. The endpoint is always /postpone at this address. The PUT body is ignored.

Either a simple port or a golang network address is allowed:

dms --exec "echo 'oh noes!'" --http ":9100"
dms --exec "echo 'oh noes!'" --http 6600
dms --exec "echo 'oh noes!'" --http "localhost:11000"

The first line of output will give the HTTP address, port, and URL to use for postponing actions.

If no listen address is supplied, dms uses :8080. If the HTTP address has a port of 0, then a dynamically chosen port will be used.

Postpone endpoint

The /postpone endpoint accepts an optional source parameter. This can be any desired string. The primary use case for this parameter is to identify which tool or entity is postponing the actions. dms will include both the source and the HTTP request's RemoteAddr in its output:

dms --exec "echo 'hi there'"
PUT http://[::]:8080/postpone to postpone triggering actions
postponed [source=<unset>] [remoteaddr=[::1]:60842]
postponed [source=mytool] [remoteaddr=[::1]:60843]
postponed [source=anothertool] [remoteaddr=[::1]:60844]

TTL

By default, an HTTP PUT must be made to the /postpone endpoint every minute. This can be changed with --ttl or -t, passing a string that is in the same format as golang durations:

dms --exec "echo 'hi there'" --ttl 30s

Misses

dms will trigger its actions upon the first missed postpone. This can be changed with --misses or -m to allow one or more missed heartbeats. For example, this will allow (2) missed PUTs before triggering actions:

dms --exec "format c:" --misses 2

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

Install

go get -u github.com/xmidt-org/dms

Contributing

Refer to CONTRIBUTING.md.

# Functions

NewSwitch constructs a Switch using the given set of configuration options.
ParseExec parses the executable actions from a command line.
Trigger executes each action in sequence, providing a standard output format for each action.

# Constants

DefaultMaxMisses is the number of allowed missed postpones before triggering actions when the misses are not supplied or are nonpositive.
DefaultSource is the postpone source used when no source is supplied.
DefaultTTL is the time-to-live for switches when no TTL is supplied or when the TTL is nonpositive.
PostponePath is the URI path for the postpone handler.
SourceParameter is the name of the HTTP query or form parameter identifying the remote entity that is postponing action triggers.

# Variables

ErrActive is returned by Switch.Activate if a Switch is currently running.
ErrDeactivated is returned by Activate if Deactivate was called before actions were triggered.
ErrEmptyCommand is returned by ParseExec to indicate that an exec action was blank or had a blank command path.
ErrNotActive is returned by Switch.Cancel if a Switch is not running.

# Structs

No description provided by the author
DiscardLogger is a Logger that ignores all output.
No description provided by the author
PostponeRequest carries information about a postponement to a Switch.
ShutdownerAction allows an uber/fx.Shutdowner to be used as an Action.
Switch is a dead man's switch.
SwitchConfig represents the set of configurable options for a Switch.
SwitchConfigIn describes all the dependencies necessary for creating a SwitchConfig.
WriterLogger is a Logger that sends its output to a given io.Writer.

# Interfaces

Action represents something that will trigger unless postponed.
Logger is the logging interface expected by dms.
Postponer represents something that can postpone triggering actions.