spm

package module
v0.0.0-...-46cfa11 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2017 License: MIT Imports: 17 Imported by: 0

README

spm - Simple Process Manager

spm is somewhere between systemd and foreman.

It runs as a daemon. You can start spm daemon by running spm command with no arguments. Once you done that you are ready to start and manage your jobs(processes) with spm commands. spm reads it's jobs from an extended Procfile syntax. You are eligible to start or stop jobs, see running jobs and their logs. Your processes executed as shell commands so you're allowed to use shell syntax in your Procfile.

Our extended version of Procfile syntax supports comments with # sign and multilines with \.

Why spm

All other foreman like process managers doesn't have a proper stop feature to end running jobs which spm has. spm works in a client/server convention, spm daemon listens for job commands(listed at spm -h) from it's clients through unix sockets. You are also able to use multiple Procfiles and start/stop multiple jobs in a Procfile which gives a huge flexiblity when you need to work with bunch of long running processes. Jobs are recognized by their names, make sure that your jobs has unique names otherwise spm will not start an already running job with same name that you started before.

Installation and Usage

$ go get github.com/ilgooz/spm/cmd/spm
$ spm -h

Simple Process Manager.

Usage: spm [OPTIONS] COMMAND [arg...]
       spm [ --help ]

Options:

  -f, --file=~/.Procfile    Location of Procfile
  -h, --help                Print usage

Commands:

    start           Start all jobs defined in Procfile
    start <jobs>    Starts jobs if present in Procfile
    stop            Stop all current jobs
    stop <jobs>     Stop jobs if currently running
    list            Lists all running jobs
    logs <job>      Prints last 200 lines of job's logfile 

Documentation can be found at https://github.com/ilgooz/spm

Example

Following Procfile has two jobs (tabs for legibility):

# Serve spm's github repository on local machine
repo:   rm -rf spm && \
        git clone https://github.com/ilgooz/spm.git && \
        http-server ./spm -p 8080

# Download and serve a webpage on local machine
apod: \

        # Create directory that will be served
        rm -rf astropix && \
        mkdir astropix && \
        cd astropix && \

        # Downloads the content of https://apod.nasa.gov/apod/astropix.html
        wget -A.jpg -e robots=off -k \ 
        --user-agent="Mozilla/5.0 (compatible; Konqueror/3.0.0/10; Linux)" \
        --no-check-certificate https://apod.nasa.gov/apod/astropix.html && \

        # Rename file as index
        mv $(ls *.html | head -1) index.html && \

        # Serve webpage
        http-server -p 8081

Suppose that we have the Procfile above inside a folder named test. After starting the daemon by spm command we will be able to run jobs, inside our Procfile, from the clients, namely, other terminal windows or tabs.

  1. Run spm command to start daemon:

    $ spm
    2016/11/07 22:20:22 spm.go:209: deamon started
    

  2. Run spm start (or a specific job e.g. spm start apod) command from different terminal tab. Since our Procfile reside in the folder named test, we have to define its path using -f flag:

    $ spm -f test start
    2016/11/07 22:20:23 spm.go:122: done
    

  3. Log files are being saved under /tmp folder with a job specific name, so that it's possible to see logs by spm logs <jobname> command:

    $ spm logs apod
    
  4. List all running jobs using spm list command:

    $ spm list
    
  5. Stop running jobs using spm stop command (or a specific job e.g. spm stop apod):

    $ spm stop
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Name    string
	Command string
	Logging *Logging

	NotifyEnd chan bool `json:"-"`
	Cmd       *exec.Cmd `json:"-"`
}

type Logging

type Logging struct {
	Prefix   string
	LogColor int
	Logfile  *os.File
}

func NewLogging

func NewLogging(name string) (*Logging, error)

func (*Logging) Close

func (l *Logging) Close() error

func (*Logging) Output

func (l *Logging) Output(in *bufio.Scanner) error

Output reads the in then writes into both stdout and logfile

func (*Logging) Write

func (l *Logging) Write(s string) error

Write writes given string into Logfile

type Manager

type Manager struct {
	Jobs map[string]Job
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) List

func (m *Manager) List() (jobs []string)

func (*Manager) ReadLog

func (m *Manager) ReadLog(job string, n int) (lines []string)

ReadLog reads last n lines of the file that corresponds to job.

func (*Manager) Start

func (m *Manager) Start(job Job)

func (*Manager) StartAll

func (m *Manager) StartAll(jobs []Job)

func (*Manager) Stop

func (m *Manager) Stop(job string)

func (*Manager) StopAll

func (m *Manager) StopAll()

type Message

type Message struct {
	// Command can be "empty", start, stop and etc.
	Command   string
	Arguments []string
	Jobs      []Job
	JobList   []string
	JobLogs   []string
}

type Parser

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

func NewParser

func NewParser(r io.Reader) *Parser

func (*Parser) Parse

func (p *Parser) Parse() (jobs []Job, err error)

type Socket

type Socket struct {
	// Message emits incoming messages from dialer or listener.
	Message chan Message

	// Connection emits connected dialers when Socket is a listener.
	Connection chan *Socket

	// Connections holds connected dialers when Socket is a listener.
	Connections []*Socket
	// contains filtered or unexported fields
}

func NewSocket

func NewSocket() *Socket

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Dial

func (s *Socket) Dial() error

func (*Socket) Listen

func (s *Socket) Listen() error

func (*Socket) Send

func (s *Socket) Send(m Message) error

Directories

Path Synopsis
cmd
spm

Jump to

Keyboard shortcuts

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