gpm

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

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

Go to latest
Published: Jan 7, 2019 License: MIT Imports: 10 Imported by: 0

README

GPM - The lightweight process manager

GPM is an extremely lightweight process manager.
It's easy to configure and has no external dependencies, making it an obvious choice for contains.
GPM runs on any Platform, not just Linux or Windows.

Features

GPM comes with a pretty short list of core features:

Automatic restart

Automatically restart a process whenever it dies.

Inter-dependencies

Have a setup script that needs to run before other process can run? Just have them depend on each other, and GPM will handle the rest

Graceful shutdown

GPM will pass along interrupts, and give child processes a chance to shutdown. Are they not down after 7 seconds, then they will be force killed.

Stdout/stderr handling

All output to stdout/stderr from child-processes will appear in GPM's stdout/stderr, allowing for better log tailing when running in contains, or simply for easier overview.

Configuration

GPM attempts to keep the configuration to a minimum, however some configuration is required for GPM to be able to figure out what processes should be run.

Make a file config.json where you want to run GPM from.

An extremely simply configuration file, that just runs an echo command once looks like this:

[
  {
    "name": "echo",
    "command": "echo 'this is a test'"
  }
]

Here is a table of all the possible options per process.

Key Description Required
name This is the name of the process, used when resolving dependencies, and for writing to the log. Yes
command This is the actual terminal command to run. Write here exactly like you would on your normal terminal. Does not support piping between processes. Yes
autoRestart Set to true to have the process automatically be restarted when it closes. Mutually exclusive with after No
after The name of the process, this process should be run after. Mutually exclusive with autoRestart No
workDir The working directory of the process when executed No

A more involved example:

[
  {
    "name": "echo",
    "command": "echo 'this is a test'"
  },
  {
    "name": "gfs",
    "command": "gfs-windows-x64.exe",
    "autoRestart": true,
    "after": "echo"
  },
  {
    "name": "echo2",
    "command": "echo 'this is echo 2'",
    "after": "echo"
  },
  {
    "name": "echo3",
    "command": "echo this is echo 3",
    "after": "echo2"
  }
]

This starts a single echo process that write 'this is a test' to the terminal. Then it starts a GFS process. At the same time another echo process is started, writing 'this is echo 2' to the terminal. Then yet another echo process start, that write 'this is echo 3' to the terminal.

Should the GFS process ever stop, then GPM will handle starting it again.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tokenize

func Tokenize(s string) (tokens []string)

Tokenises the given string as command line arguments

func ValidateNoCircular

func ValidateNoCircular(process *Process, name string) (stack string)

Checks if a given process is part of a circular dependency chain

func ValidateNoDependOnAutoRestart

func ValidateNoDependOnAutoRestart(process *Process) error

func ValidateNoDuplicates

func ValidateNoDuplicates(processes []*Process) error

Checks for dublicates. We can't have multiple processes with the same name, as we then can't build a dependency tree

Types

type Process

type Process struct {
	// The name of the process
	Name string
	// The command to run
	Command string
	// The args to pass along to the command
	Args []string
	// If the process should be automatically restarted if it stops
	AutoRestart bool
	// Proccesses that should be run after this process
	Before []*Process

	// The name of the directory the process should be run in
	WorkingDirectory string
	// contains filtered or unexported fields
}

Describes a single process

func (*Process) Run

func (p *Process) Run(ctx context.Context) error

Runs the actual process

type ProcessManager

type ProcessManager struct {
	// contains filtered or unexported fields
}

The main process manager, managing processes

func NewProcessManager

func NewProcessManager() *ProcessManager

func (*ProcessManager) BuildProcessTree

func (p *ProcessManager) BuildProcessTree(processes []*Process) error

Builds a process tree to run, as processes can have inter-dependencies

func (*ProcessManager) BuildProcesses

func (p *ProcessManager) BuildProcesses(processJsons []*processJson) error

func (*ProcessManager) ParseConfig

func (p *ProcessManager) ParseConfig(data string) error

func (*ProcessManager) ParseConfigFile

func (p *ProcessManager) ParseConfigFile(pathToConfigFile string) error

func (*ProcessManager) StartProcesses

func (p *ProcessManager) StartProcesses(ctx context.Context) error

Directories

Path Synopsis
cmd
gpm

Jump to

Keyboard shortcuts

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