Documentation
¶
Index ¶
- Constants
- func AllowedEnvironment(envs []string) []string
- func ExitStatus(err error) (int, bool)
- func NewSubprocessLogger(ctx context.Context, getEnv func(string) string, component string) (_ log.Logger, _ io.Closer, returnedErr error)
- type Command
- type Option
- func WithCgroup(cgroupsManager cgroups.Manager, opts ...cgroups.AddCommandOption) Option
- func WithCommandGitVersion(gitCmdVersion string) Option
- func WithCommandName(commandName, subcommandName string) Option
- func WithCompletionErrorLogFilter(fn func(cmd *Command, stderr string) bool) Option
- func WithDir(dir string) Option
- func WithEnvironment(environment []string) Option
- func WithFinalizer(finalizer func(context.Context, *Command)) Option
- func WithReferenceBackend(refBackend git.ReferenceBackend) Option
- func WithSetupStdin() Option
- func WithSetupStdout() Option
- func WithStderr(stderr io.Writer) Option
- func WithStdin(stdin io.Reader) Option
- func WithStdout(stdout io.Writer) Option
- func WithSubprocessLogger(logConfig log.Config) Option
Constants ¶
const ( // EnvLogConfiguration is the environment variable under which the logging configuration is // passed to subprocesses. EnvLogConfiguration = "GITALY_LOG_CONFIGURATION" )
Variables ¶
This section is empty.
Functions ¶
func AllowedEnvironment ¶
AllowedEnvironment filters the given slice of environment variables and returns all variables which are allowed per the variables defined above. This is useful for constructing a base environment in which a command can be run.
func ExitStatus ¶
ExitStatus will return the exit-code from an error returned by Wait().
func NewSubprocessLogger ¶
func NewSubprocessLogger(ctx context.Context, getEnv func(string) string, component string) (_ log.Logger, _ io.Closer, returnedErr error)
NewSubprocessLogger returns a logger than can be used in a subprocess spawned by Gitaly. It extracts the log directory from the environment using getEnv and outputs logs in the given format log dir under a file defined by logFileName. If `GITALY_LOG_CONFIGURATION` is set, it outputs the logs to the file descriptor using the configuration from the environment variable.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command encapsulates a running exec.Cmd. The embedded exec.Cmd is terminated and reaped automatically when the context.Context that created it is canceled.
func New ¶
func New(ctx context.Context, logger log.Logger, nameAndArgs []string, opts ...Option) (_ *Command, returnedErr error)
New creates a Command from the given executable name and arguments On success, the Command contains a running subprocess. When ctx is canceled the embedded process will be terminated and reaped automatically.
func (*Command) Stdin ¶
func (c *Command) Stdin() io.WriteCloser
Stdin returns the commands stdin pipe.
func (*Command) Wait ¶
Wait calls Wait() on the exec.Cmd instance inside the command. This blocks until the command has finished and reports the command exit status via the error return value. Use ExitStatus to get the integer exit status from the error returned by Wait().
Wait returns a wrapped context error if the process was reaped due to the context being done.
type Option ¶
type Option func(cfg *config)
Option is an option that can be passed to `New()` for controlling how the command is being created.
func WithCgroup ¶
func WithCgroup(cgroupsManager cgroups.Manager, opts ...cgroups.AddCommandOption) Option
WithCgroup adds the spawned command to a Cgroup. The bucket used will be derived from the command's arguments and/or from the repository.
func WithCommandGitVersion ¶
WithCommandGitVersion overrides the "git_version" label used in metrics.
func WithCommandName ¶
WithCommandName overrides the "cmd" and "subcmd" label used in metrics.
func WithCompletionErrorLogFilter ¶
WithCompletionErrorLogFilter configures a function that should return true if an errored command should not produce logs.
func WithEnvironment ¶
WithEnvironment sets up environment variables that shall be set for the command.
func WithFinalizer ¶
WithFinalizer sets up the finalizer to be run when the command is being wrapped up. It will be called after `Wait()` has returned.
func WithReferenceBackend ¶
func WithReferenceBackend(refBackend git.ReferenceBackend) Option
WithReferenceBackend overrides the "reference_backend" label used in metrics.
func WithSetupStdin ¶
func WithSetupStdin() Option
WithSetupStdin instructs New() to configure the stdin pipe of the command it is creating. This allows you call Write() on the command as if it is an ordinary io.Writer, sending data directly to the stdin of the process.
func WithSetupStdout ¶
func WithSetupStdout() Option
WithSetupStdout instructs New() to configure the standard output pipe of the command it is creating. This allowsyou to call Read() on the command as if it is an ordinary io.Reader, reading output directly from the stdout of the process.
func WithStderr ¶
WithStderr sets up the command to write standard error to the given writer.
func WithStdout ¶
WithStdout sets up the command to write standard output to the given writer.
func WithSubprocessLogger ¶
WithSubprocessLogger sets up a goroutine that consumes logs from the subprocess through a pipe and outputs them in Logger's output.