supd

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 35 Imported by: 0

README

Introduction

首先感谢原作者们的贡献,我一直使用python版的supervisor进行项目管理,期间为了性能与配置文件的统一曾尝试过使用go版本的supervisor,但前者的稳定性更好些,就一直没启用go版的supervisor,但我一直在关注着 ochinchina/supervisor

First of all, thanks to the contributions of the original authors, I have been using the python version of supervisor for project management. During this period, I tried to use the go version of supervisor for the unification of performance and configuration files, but the former is more stable, and I have not enabled the go version of supervisor, but I have been concerned about in ochinchina/supervisor.

最近因个人在物联网上应用得比较多些了,比较迫切需要一个进程管理软件进行统一管理,于是启用与调试了go版的supervisor,发现改改还是比较能解决问题,我本想直接为原库做些贡献,但随着调试的深入,发现自己不进行大改就比较难跟上项目应用的速度,因此只能进行了大改,大改了就比较难合并进原项目了,因此开启了本项目。

Recently, due to more personal applications on the Internet of Things, there is an urgent need for a process management software for unified management, so the go version of supervisor has been activated and debugged. It is found that the modification can solve the problem better. I wanted to contribute directly to the original library, but with the deepening of debugging, I found that I did not carry out much. It is more difficult to keep up with the speed of project application, so we can only make major changes, major changes will be more difficult to merge into the original project, so the project started.

Install

Install from source

# Need to install golang before building.

git clone https://github.com/gwaycc/supd.git
cd supd
. env.sh
cd cmd/supd
./setup.sh install # ./setup.sh clean # to remove install

Install from binary

Download binary package from https://github.com/gwaycc/supd/releases and decompress the package.

cd supd
./setup.sh install # ./setup.sh clean # to remove install

======================================================================================

Go Report Card

Why this project?

The python script supervisord is a powerful tool used by a lot of guys to manage the processes. I like the tool supervisord also.

But this tool requires us to install the big python environment. In some situation, for example in the docker environment, the python is too big for us.

In this project, the supervisord is re-implemented in go-lang. The compiled supervisord is very suitable for these environment that the python is not installed.

Compile the supervisord

Before compiling the supervisord, make sure the go-lang is installed in your environement.

To compile the go-lang version supervisord, run following commands (required go 1.11+):

  1. local: go build
  2. linux: env GOOS=linux GOARCH=amd64 go build -o supervisord_linux_amd64

Run the supervisord

After the supervisord binary is generated, create a supervisord configuration file and start the supervisord like below:

$ cat supervisor.conf
[program:test]
command = /your/program args
$ supervisord -c supervisor.conf

Run as daemon

Add the inet interface in your configuration:

[inet_http_server]
port=127.0.0.1:9002

then run

$ supervisord -c supervisor.conf -d

In order to controll the daemon, you can use $ supervisord ctl subcommand, available commands are: status, start, stop, shutdown, reload.

$ supervisord ctl status
$ supervisord ctl status program-1 program-2...
$ supervisord ctl status group:*
$ supervisord ctl stop program-1 program-2...
$ supervisord ctl stop group:*
$ supervisord ctl stop all
$ supervisord ctl start program-1 program-2...
$ supervisord ctl start group:*
$ supervisord ctl start all
$ supervisord ctl shutdown
$ supervisord ctl reload
$ supervisord ctl signal <signal_name> <process_name> <process_name> ...
$ supervisord ctl signal all
$ supervisord ctl pid <process_name>

the URL of supervisord in the "supervisor ctl" subcommand is dected in following order:

  • check if option -s or --serverurl is present, use this url
  • check if -c option is present and the "serverurl" in "supervisorctl" section is present, use the "serverurl" in section "supervisorctl"
  • return http://localhost:9002

Check the version

command "version" will show the current supervisor version.

$ supervisord version

Supported features

http server

the unix socket & TCP http server is supported. Basic auth is supported.

The unix socket setting is in the "unix_http_server" section. The TCP http server setting is in "inet_http_server" section.

If both "inet_http_server" and "unix_http_server" is not configured in the configuration file, no http server will be started.

supervisord information

The log & pid of supervisord process is supported by section "supervisord" setting.

program

the following features is supported in the "program:x" section:

  • program command
  • process name
  • numprocs
  • numprocs_start
  • autostart
  • startsecs
  • startretries
  • autorestart
  • exitcodes
  • stopsignal
  • stopwaitsecs
  • stdout_logfile
  • stdout_logfile_maxbytes
  • stdout_logfile_backups
  • redirect_stderr
  • stderr_logfile
  • stderr_logfile_maxbytes
  • stderr_logfile_backups
  • environment
  • priority
  • user
  • directory
  • stopasgroup
  • killasgroup
  • restartpause
program extends

Following new keys are supported by the [program:xxx] section:

  • depends_on: define program depends information. If program A depends on program B, C, the program B, C will be started before program A. Example:
[program:A]
depends_on = B, C

[program:B]
...
[program:C]
...
  • user: user in the section "program:xxx" now is extended to support group with format "user[:group]". So "user" can be configured as:
[program:xxx]
user = user_name
...

or

[program:xxx]
user = user_name:group_name
...
  • stopsignal list one or more stop signal can be configured. If more than one stopsignal is configured, when stoping the program, the supervisor will send the signals to the program one by one with interval "stopwaitsecs". If the program does not exit after all the signals sent to the program, the supervisor will kill the program

  • restart_when_binary_changed: a bool flag to control if the program should be restarted when the executable binary is changed

  • restart_directory_monitor: a path to be monitored for restarting purpose

  • restart_file_pattern: if a file is changed under restart_directory_monitor and the filename matches this pattern, the program will be restarted.

Group

the "group" section is supported and you can set "programs" item

Events

the supervisor 3.x defined events are supported partially. Now it supports following events:

  • all process state related events
  • process communication event
  • remote communication event
  • tick related events
  • process log related events

Logs

The logs ( field stdout_logfile, stderr_logfile ) from programs managed by the supervisord can be written to:

- /dev/null, ignore the log
- /dev/stdout, write log to stdout
- /dev/stderr, write log to stderr
- syslog, write the log to local syslog
- syslog @[protocol:]host[:port], write the log to remote syslog. protocol must be "tcp" or "udp", if missing, "udp" will be used. If port is missing, for "udp" protocol, it's value is 514 and for "tcp" protocol, it's value is 6514.
- file name, write log to a file

Mutiple log file can be configured for the stdout_logfile and stderr_logfile with delimeter ',', for example if want to a program write log to both stdout and test.log file, the stdout_logfile for the program can be configured as:

stdout_logfile = test.log, /dev/stdout

Usage from a Docker container

supervisord is compiled inside a Docker image to be used directly inside another image, from the Docker Hub version.

FROM debian:latest
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
CMD ["/usr/local/bin/supervisord"]

The MIT License (MIT)

Copyright (c)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	SUPERVISOR_VERSION = "3.0"
)
View Source
const VERSION = "1.0.5"

Variables

View Source
var (
	HttpMux = &HttpServeMux{}
)

Functions

func Deamonize

func Deamonize(proc func())

func GenTemplate

func GenTemplate(writer io.Writer) error

func JsonOutput

func JsonOutput(data interface{})

current only support ctl status

func LoadEnvFile

func LoadEnvFile()

func NewHttpBasicAuth

func NewHttpBasicAuth(user string, password string, handler http.Handler) *httpBasicAuth

func ReapZombie

func ReapZombie()

func Run

func Run()

func RunServer

func RunServer()

Types

type BaseChecker

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

func NewBaseChecker

func NewBaseChecker(includes []string, timeout int) *BaseChecker

func (*BaseChecker) Check

func (bc *BaseChecker) Check() bool

func (*BaseChecker) Write

func (bc *BaseChecker) Write(b []byte) (int, error)

type ContentChecker

type ContentChecker interface {
	Check() bool
}

type CtlCommand

type CtlCommand struct {
	ServerUrl string `short:"s" long:"serverurl" description:"URL on which supervisord server is listening"`
	User      string `short:"u" long:"user" description:"the user name"`
	Password  string `short:"P" long:"password" description:"the password"`
	Verbose   bool   `short:"v" long:"verbose" description:"Show verbose debug information"`
	Encode    string `short:"o" long:"output" description:"set output encode for ctl command, value is txt or json, default is txt"`

	Follow bool `short:"f" long:"follow" description:"The -f option causes tail to not stop when end of file is reached."`
}

func (*CtlCommand) Execute

func (x *CtlCommand) Execute(args []string) error

type DecodeCommand

type DecodeCommand struct {
	Key string `short:"k" long:"key" description:"Auth key input"`
	Out string `short:"o" long:"out" description:"File ouput"`
}

func (DecodeCommand) Execute

func (v DecodeCommand) Execute(args []string) error

type EncodeCommand

type EncodeCommand struct {
	Key string `short:"k" long:"key" description:"Auth key input"`
	Out string `short:"o" long:"out" description:"File ouput"`
}

func (EncodeCommand) Execute

func (v EncodeCommand) Execute(args []string) error

type GetEnvCommand added in v1.0.4

type GetEnvCommand struct {
}

func (*GetEnvCommand) Execute added in v1.0.4

func (c *GetEnvCommand) Execute(args []string) error

type HttpChecker

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

func NewHttpChecker

func NewHttpChecker(url string, timeout int) *HttpChecker

func (*HttpChecker) Check

func (hc *HttpChecker) Check() bool

type HttpServeMux

type HttpServeMux struct {
	http.ServeMux
}

func (*HttpServeMux) ServeHTTP

func (s *HttpServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type InitTemplateCommand

type InitTemplateCommand struct {
	OutFile string `short:"o" long:"output" description:"the output file name" required:"true"`
}

func (*InitTemplateCommand) Execute

func (x *InitTemplateCommand) Execute(args []string) error

type LogReadInfo

type LogReadInfo struct {
	Offset int
	Length int
}

type Options

type Options struct {
	Configuration string `short:"c" long:"configuration" description:"the configuration file"`
	Daemon        bool   `short:"d" long:"daemon" description:"run as daemon"`
	EnvFile       string `long:"env-file" description:"the environment file"`
}

type PidCommand

type PidCommand struct {
}

func (*PidCommand) Execute

func (c *PidCommand) Execute(args []string) error

type ProcessLogReadInfo

type ProcessLogReadInfo struct {
	Name   string
	Offset int
	Length int
}

type ProcessStdin

type ProcessStdin struct {
	Name  string
	Chars string
}

type ProcessTailLog

type ProcessTailLog struct {
	LogData  string
	Offset   int64
	Overflow bool
}

type RPCServer

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

func NewRPCServer

func NewRPCServer(s *Supervisor) *RPCServer

func (*RPCServer) ServeHTTP

func (p *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*RPCServer) StartInetHttpServer

func (p *RPCServer) StartInetHttpServer(user string, password string, listenAddr string)

func (*RPCServer) StartUnixHttpServer

func (p *RPCServer) StartUnixHttpServer(user string, password string, listenAddr string)

func (*RPCServer) Stop

func (p *RPCServer) Stop()

stop network listening

type ReloadCommand

type ReloadCommand struct {
}

func (*ReloadCommand) Execute

func (c *ReloadCommand) Execute(args []string) error

type RemoteCommEvent

type RemoteCommEvent struct {
	Type string
	Data string
}

type RestartCommand

type RestartCommand struct {
}

func (*RestartCommand) Execute

func (rc *RestartCommand) Execute(args []string) error

type ScriptChecker

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

func NewScriptChecker

func NewScriptChecker(args []string) *ScriptChecker

func (*ScriptChecker) Check

func (sc *ScriptChecker) Check() bool

type SetEnvCommand added in v1.0.4

type SetEnvCommand struct {
}

func (*SetEnvCommand) Execute added in v1.0.4

func (c *SetEnvCommand) Execute(args []string) error

type ShutdownCommand

type ShutdownCommand struct {
}

func (*ShutdownCommand) Execute

func (c *ShutdownCommand) Execute(args []string) error

type SignalCommand

type SignalCommand struct {
}

func (*SignalCommand) Execute

func (c *SignalCommand) Execute(args []string) error

type StartCommand

type StartCommand struct {
}

func (*StartCommand) Execute

func (c *StartCommand) Execute(args []string) error

type StartProcessArgs

type StartProcessArgs struct {
	Name string
	Wait bool `default:"true"`
}

type StateInfo

type StateInfo struct {
	Statecode int    `xml:"statecode"`
	Statename string `xml:"statename"`
}

type StatusCommand

type StatusCommand struct {
}

func (*StatusCommand) Execute

func (c *StatusCommand) Execute(args []string) error

type StopCommand

type StopCommand struct {
}

func (*StopCommand) Execute

func (c *StopCommand) Execute(args []string) error

type Supervisor

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

func NewSupervisor

func NewSupervisor(configFile string) *Supervisor

func (*Supervisor) AddProcessGroup

func (s *Supervisor) AddProcessGroup(args *struct{ Name string }, reply *rpcclient.StatusReply) error

func (*Supervisor) ClearLog

func (s *Supervisor) ClearLog(args *struct{}, reply *rpcclient.StatusReply) error

func (*Supervisor) GetAllProcessInfo

func (s *Supervisor) GetAllProcessInfo(args *struct{}, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) GetEnv added in v1.0.4

func (s *Supervisor) GetEnv(args *rpcclient.GetEnvArg, reply *rpcclient.GetEnvRet) error

func (*Supervisor) GetPID

func (s *Supervisor) GetPID(args *struct{}, reply *struct{ Pid int }) error

Get all the name of prorams

Return the name of all the programs

func (s *Supervisor) GetPrograms() []string {
	return s.config.GetProgramNames()
}

func (*Supervisor) GetProcessInfo

func (s *Supervisor) GetProcessInfo(args *struct{ Name string }, reply *rpcclient.ProcessInfoReply) error

func (*Supervisor) GetState

func (s *Supervisor) GetState(args *struct{}, reply *struct{ StateInfo StateInfo }) error

func (*Supervisor) GetSupervisorVersion

func (s *Supervisor) GetSupervisorVersion(args *rpcclient.GetVersionArg, reply *rpcclient.GetVersionRet) error

func (*Supervisor) GetVersion

func (s *Supervisor) GetVersion(args *rpcclient.GetVersionArg, reply *rpcclient.GetVersionRet) error

func (*Supervisor) ReadLog

func (s *Supervisor) ReadLog(args *LogReadInfo, reply *struct{ Log string }) error

func (*Supervisor) ReloadConfig

func (s *Supervisor) ReloadConfig(args *rpcclient.ReloadConfigArg, reply *rpcclient.ReloadConfigRet) error

func (*Supervisor) RemoveProcessGroup

func (s *Supervisor) RemoveProcessGroup(args *struct{ Name string }, reply *rpcclient.StatusReply) error

func (*Supervisor) Restart

func (s *Supervisor) Restart(args *struct{}, reply *rpcclient.StatusReply) error

func (*Supervisor) RestartAllProcesses

func (s *Supervisor) RestartAllProcesses(args *struct {
	Wait bool `default:"true"`
}, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) RestartProcess

func (s *Supervisor) RestartProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error

func (*Supervisor) SendProcessStdin

func (s *Supervisor) SendProcessStdin(args *ProcessStdin, reply *rpcclient.StatusReply) error

func (*Supervisor) SendRemoteCommEvent

func (s *Supervisor) SendRemoteCommEvent(args *RemoteCommEvent, reply *rpcclient.StatusReply) error

func (*Supervisor) SetEnv added in v1.0.4

func (s *Supervisor) SetEnv(args *rpcclient.SetEnvArg, reply *rpcclient.SetEnvRet) error

func (*Supervisor) Shutdown

func (s *Supervisor) Shutdown(args *struct{}, reply *rpcclient.StatusReply) error

func (*Supervisor) SignalAllProcesses

func (s *Supervisor) SignalAllProcesses(args *rpcclient.SignalAllProcessesArg, reply *rpcclient.SignalAllProcessesRet) error

func (*Supervisor) SignalProcess

func (s *Supervisor) SignalProcess(args *types.ProcessSignal, reply *rpcclient.StatusReply) error

func (*Supervisor) SignalProcessGroup

func (s *Supervisor) SignalProcessGroup(args *types.ProcessSignal, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) StartAllProcesses

func (s *Supervisor) StartAllProcesses(args *struct {
	Wait bool `default:"true"`
}, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) StartProcess

func (s *Supervisor) StartProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error

func (*Supervisor) StartProcessGroup

func (s *Supervisor) StartProcessGroup(args *StartProcessArgs, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) StopAllProcesses

func (s *Supervisor) StopAllProcesses(args *struct {
	Wait bool `default:"true"`
}, reply *rpcclient.AllProcessInfoReply) error

func (*Supervisor) StopProcess

func (s *Supervisor) StopProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error

func (*Supervisor) StopProcessGroup

func (s *Supervisor) StopProcessGroup(args *StartProcessArgs, reply *rpcclient.AllProcessInfoReply) error

type SupervisorRestful

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

func NewSupervisorRestful

func NewSupervisorRestful(supervisor *Supervisor) *SupervisorRestful

func (*SupervisorRestful) CreateProgramHandler

func (sr *SupervisorRestful) CreateProgramHandler() http.Handler

func (*SupervisorRestful) ListProgram

func (sr *SupervisorRestful) ListProgram(w http.ResponseWriter, req *http.Request)

list the status of all the programs

json array to present the status of all programs

func (*SupervisorRestful) ReadStdoutLog

func (sr *SupervisorRestful) ReadStdoutLog(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) Reload

func (sr *SupervisorRestful) Reload(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) Shutdown

func (sr *SupervisorRestful) Shutdown(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) StartProgram

func (sr *SupervisorRestful) StartProgram(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) StartPrograms

func (sr *SupervisorRestful) StartPrograms(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) StopProgram

func (sr *SupervisorRestful) StopProgram(w http.ResponseWriter, req *http.Request)

func (*SupervisorRestful) StopPrograms

func (sr *SupervisorRestful) StopPrograms(w http.ResponseWriter, req *http.Request)

type TailCommand

type TailCommand struct {
	Follow bool `short:"f" description:"The -f option causes tail to not stop when end of file is reached."`
}

func (*TailCommand) Execute

func (c *TailCommand) Execute(args []string) error

type TcpChecker

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

func NewTcpChecker

func NewTcpChecker(host string, port int, includes []string, timeout int) *TcpChecker

func (*TcpChecker) Check

func (tc *TcpChecker) Check() bool

type VersionCommand

type VersionCommand struct {
}

func (VersionCommand) Execute

func (v VersionCommand) Execute(args []string) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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