immortal: Index | Files

package immortal

import ""


Package Files

color.go config.go ctl.go daemon.go flags.go fork.go funcs.go logger.go parser.go process.go scandir_linux.go signals.go socket.go supervise.go watchpid_linux.go

func AbsSince Uses

func AbsSince(t time.Time) string

AbsSince return time since in format [days]d[hours]h[minutes]m[seconds.decisecond]s

func Fork Uses

func Fork() (int, error)

Fork crete a new process

func GetJSON Uses

func GetJSON(spath, path string, target interface{}) error

GetJSON unix socket web client

func GetSdir Uses

func GetSdir() string

GetSdir return the main supervise directory, defaults to /var/run/immortal

func GetUserSdir Uses

func GetUserSdir() (string, error)

GetUserSdir returns the $HOME/.immortal

func Green Uses

func Green(s string) string

Green return string in green

func NewLogger Uses

func NewLogger(cfg *Config, quit chan struct{}) *log.Logger

NewLogger return a Logger instance

func NewProcess Uses

func NewProcess(cfg *Config) *process

NewProcess return process instance

func NewStderrLogger Uses

func NewStderrLogger(cfg *Config) *log.Logger

NewStderrLogger return Logger instance

func Red Uses

func Red(s string) string

Red return string in red

func Supervise Uses

func Supervise(d *Daemon) error

Supervise keep daemon process up and running

func Yellow Uses

func Yellow(s string) string

Yellow return string in yellow

type Config Uses

type Config struct {
    Cmd        string            `yaml:"cmd" json:"cmd"`
    Cwd        string            `yaml:",omitempty" json:",omitempty"`
    Env        map[string]string `yaml:",omitempty" json:",omitempty"`
    Log        Log               `yaml:",omitempty" json:",omitempty"`
    Stderr     Log               `yaml:",omitempty" json:",omitempty"`
    Logger     string            `yaml:",omitempty" json:",omitempty"`
    Require    []string          `yaml:",omitempty"`
    RequireCmd string            `yaml:"require_cmd,omitempty"`
    PostExit   string            `yaml:"post_exit,omitempty"`
    User       string            `yaml:",omitempty" json:",omitempty"`
    Wait       uint              `yaml:",omitempty"`
    Retries    int               `yaml:",omitempty"`
    Pid        `yaml:",omitempty" json:",omitempty"`
    // contains filtered or unexported fields

Config yaml/command line configuration

func ParseArgs Uses

func ParseArgs(p Parser, fs *flag.FlagSet) (cfg *Config, err error)

ParseArgs parse command arguments

type Control Uses

type Control interface {
    GetStatus(socket string) (*Status, error)
    SendSignal(socket, signal string) (*SignalResponse, error)
    FindServices(dir string) ([]*ServiceStatus, error)
    PurgeServices(dir string) error
    Run(command string) ([]byte, error)

Control interface

type Controller Uses

type Controller struct{}

Controller implements Control

func (*Controller) FindServices Uses

func (c *Controller) FindServices(dir string) ([]*ServiceStatus, error)

FindServices return [name, socket path] of service

func (*Controller) GetStatus Uses

func (c *Controller) GetStatus(socket string) (*Status, error)

GetStatus returns service status in json format

func (*Controller) PurgeServices Uses

func (c *Controller) PurgeServices(dir string) error

PurgeServices remove unused service directory

func (*Controller) Run Uses

func (c *Controller) Run(command string) ([]byte, error)

Run executes a command and print combinedOutput

func (*Controller) SendSignal Uses

func (c *Controller) SendSignal(socket, signal string) (*SignalResponse, error)

SendSignal send signal to process

type Daemon Uses

type Daemon struct {
    // contains filtered or unexported fields

Daemon struct

func New Uses

func New(cfg *Config) (*Daemon, error)

New creates a new daemon

func (*Daemon) HandleSignal Uses

func (d *Daemon) HandleSignal(w http.ResponseWriter, r *http.Request)

HandleSignal send signals to the current process

func (*Daemon) HandleStatus Uses

func (d *Daemon) HandleStatus(w http.ResponseWriter, r *http.Request)

HandleStatus return process status

func (*Daemon) IsRunning Uses

func (d *Daemon) IsRunning(pid int) bool

IsRunning check if process is running

func (*Daemon) Listen Uses

func (d *Daemon) Listen() (err error)

Listen creates a unix socket used for control the daemon

func (*Daemon) ReadPidFile Uses

func (d *Daemon) ReadPidFile(pidfile string) (int, error)

ReadPidFile read pid from file if error returns pid 0

func (*Daemon) Run Uses

func (d *Daemon) Run(p Process) (*process, error)

Run returns a process instance

func (*Daemon) WatchPid Uses

func (d *Daemon) WatchPid(pid int, ch chan<- error)

WatchPid check pid changes

func (*Daemon) WritePid Uses

func (d *Daemon) WritePid(file string, pid int) error

WritePid write pid to file

type Flags Uses

type Flags struct {
    CheckConfig bool
    ChildPid    string
    Command     string
    Configfile  string
    Ctl         string
    Envdir      string
    FollowPid   string
    Logfile     string
    Logger      string
    Nodaemon    bool
    ParentPid   string
    Retries     int
    User        string
    Version     bool
    Wait        uint
    Wrkdir      string

Flags available command flags

type Log Uses

type Log struct {
    File      string `yaml:",omitempty"`
    Age       int    `yaml:",omitempty"`
    Num       int    `yaml:",omitempty"`
    Size      int    `yaml:",omitempty"`
    Timestamp bool   `yaml:",omitempty"`

Log struct run.yml

type LogWriter Uses

type LogWriter struct {
    // contains filtered or unexported fields

LogWriter implements Logger

func (*LogWriter) IsLogging Uses

func (l *LogWriter) IsLogging() bool

IsLogging return true if an availale logger exists

func (*LogWriter) Log Uses

func (l *LogWriter) Log(input io.ReadCloser)

Log write to the logger

type Logger Uses

type Logger interface {
    Log(input io.ReadCloser)
    IsLogging() bool

Logger interface

type Parse Uses

type Parse struct {
    UserLookup func(username string) (*user.User, error)

Parse implements parser

func (*Parse) Parse Uses

func (p *Parse) Parse(fs *flag.FlagSet) (*Flags, error)

Parse parse the command line flags

func (*Parse) Usage Uses

func (p *Parse) Usage(fs *flag.FlagSet) func()

Usage prints to standard error a usage message

type Parser Uses

type Parser interface {
    Parse(fs *flag.FlagSet) (*Flags, error)
    // contains filtered or unexported methods

Parser interface

type Pid Uses

type Pid struct {
    Follow string `yaml:",omitempty"`
    Parent string `yaml:",omitempty"`
    Child  string `yaml:",omitempty"`

Pid struct run.yml

type Process Uses

type Process interface {
    Kill() error
    Pid() int
    Signal(sig syscall.Signal) error
    Start() (*process, error)
    GetProcess() *process

Process interface

type ScanDir Uses

type ScanDir struct {
    // contains filtered or unexported fields

ScanDir struct

func NewScanDir Uses

func NewScanDir(path string) (*ScanDir, error)

NewScanDir returns ScanDir struct

func (*ScanDir) Scanner Uses

func (s *ScanDir) Scanner(ctl Control)

Scanner searches for run.yml if file changes it will reload(stop-start)

func (*ScanDir) Start Uses

func (s *ScanDir) Start(ctl Control)

Start scans directory every 5 seconds

type ServiceStatus Uses

type ServiceStatus struct {
    Name           string
    Socket         string
    Status         *Status
    SignalResponse *SignalResponse

ServiceStatus struct

type SignalResponse Uses

type SignalResponse struct {
    Err string

SignalResponse struct to return the error in json format

type Status Uses

type Status struct {
    Pid    int    `json:"pid"`
    Up     string `json:"up,omitempty"`
    Down   string `json:"down,omitempty"`
    Cmd    string `json:"cmd"`
    Fpid   bool   `json:"fpid"`
    Count  int    `json:"count"`
    Status string `json:"status,omitempty"`

Status struct

type Supervisor Uses

type Supervisor struct {
    // contains filtered or unexported fields

Supervisor for the process

func (*Supervisor) FollowPid Uses

func (s *Supervisor) FollowPid(err error)

FollowPid check if process still up and running if it is, follow the pid, monitor the existing pid created by the process instead of creating another process

func (*Supervisor) ReStart Uses

func (s *Supervisor) ReStart()

ReStart create a new process

func (*Supervisor) Start Uses

func (s *Supervisor) Start() error

Start loop forever

func (*Supervisor) Terminate Uses

func (s *Supervisor) Terminate(err error) bool

Terminate handle process termination

Package immortal imports 29 packages (graph). Updated 2019-12-10. Refresh now. Tools for package owners.