Help us shape the future of Go! Take the 2026 Go Developer Survey

sprok

package module
v0.0.0-...-93fb8cf Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2015 License: Apache-2.0 Imports: 6 Imported by: 2

README

sprok

Simple Proc - start processes with complex command-lines using a trivial config file

This is a package for launching processes using simple config files rather than string concatenation and/or shell scripts.

Usage

Each config format is built into a separate binary.

go get github.com/tobert/sprok/sprok-json
go get github.com/tobert/sprok/sprok-toml
go get github.com/tobert/sprok/sprok-yaml


$GOPATH/bin/sprok-json process.json
$GOPATH/bin/sprok-toml process.toml
$GOPATH/bin/sprok-yaml process.yaml

Examples

If stdout/stderr/stdin are not set, they are not modified.

{
  "chdir": "/opt/cassandra",
  "env": {
    "FOO": "BAR"
  },
  "argv": [
    "/usr/bin/java",
    "-Xmx8G"
  ],
  "stdout": "/dev/null",
  "stderr": "/dev/null",
  "stdin": "/dev/null"
}
chdir: /opt/cassandra
env:
  FOO: BAR
argv:
  - /usr/bin/java
  - -Xmx8G
stdin: /dev/null
stdout: /var/log/mything/stdout
stderr: /var/log/mything/stderr

Rationale

There are many great process supervisors out there that do a nice job of forking a process and watching it. If that's what you need, you should use one.

What sprok provides is a way to launch a process with a single command with no shell scripts and no extra process. The process is defined in a configuration file and no shell-style string concatenation or parsing is used. The config data structures map directly onto the operating system's execve(3p) functionality.

TODO

  • figure out why sprok-toml crashes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

type Process struct {
	Chdir               string            `json:"chdir"  yaml:"chdir"`  // cd /tmp
	Env                 map[string]string `json:"env"    yaml:"env"`    // env FOO=BAR
	Argv                []string          `json:"argv"   yaml:"argv"`   // "/bin/dd" "if=/dev/zero" "count=10"
	Stdin               string            `json:"stdin"  yaml:"stdin"`  // <"/dev/null"
	Stdout              string            `json:"stdout" yaml:"stdout"` // >"zero.bin"
	Stderr              string            `json:"stderr" yaml:"stderr"` // 2>"errors.log"
	Uid                 int               `json:"uid"    yaml:"uid"`    // 1337
	Gid                 int               `json:"gid"    yaml:"gid"`    // 1337
	PreserveEnvironment bool              `json:"preserve_environment" yaml:"preserve_environment"`
}

Process is the configuration for running a process

func NewProcess

func NewProcess() Process

NewProcess returns a Process struct with the env map and argv allocated and all stdio pointed at /dev/null. argv is allocated with a length of 1 to hold the command. Use append to add arguments.

func (*Process) Exec

func (p *Process) Exec() error

Exec executes Argv with environment Env and file descriptors 1, 2, and 3 open on the files specified in Stdin, Stdout, and Stderr. When output files are unspecified or an empty string, the file descriptors are left unmodified. If argv[0] is stat-able (absolute or relative path), it is used as-is. When that fails the PATH searched using exec.LookPath().

func (*Process) String

func (p *Process) String() string

String returns the process settings as a Bourne shell command.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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