Documentation
¶
Overview ¶
Package svc owns the supervisor daemon implementation: the Supervisor type that loads configuration, manages processes and exposes the RPC service; the HTTP/RPC server that publishes it; the REST program API; and the daemon-mode wrapper that double-forks the process.
All of these used to live in the supd root package; they are extracted here so the ctl/ package can import svc.Supervisor directly and so the root package can shrink to a thin entry point.
Index ¶
- Constants
- Variables
- func Daemonize(proc func())
- func FindSupervisordConf() (string, error)
- func LoadEnvFile(path string)
- func NewHttpBasicAuth(user string, password string, handler http.Handler) *httpBasicAuth
- type HttpServeMux
- type LogReadInfo
- type Options
- type ProcessLogReadInfo
- type ProcessStdin
- type ProcessTailLog
- type RPCServer
- type RemoteCommEvent
- type Server
- type StartProcessArgs
- type StateInfo
- type Supervisor
- func (s *Supervisor) AddProcessGroup(args *struct{ Name string }, reply *rpcclient.StatusReply) error
- func (s *Supervisor) ClearLog(args *struct{}, reply *rpcclient.StatusReply) error
- func (s *Supervisor) GetAllProcessInfo(args *struct{}, reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) GetEnv(args *rpcclient.GetEnvArg, reply *rpcclient.GetEnvRet) error
- func (s *Supervisor) GetIncludeDir(args *struct{}, reply *rpcclient.IncludeDirReply) error
- func (s *Supervisor) GetPID(args *struct{}, reply *struct{ Pid int }) error
- func (s *Supervisor) GetProcessInfo(args *struct{ Name string }, reply *rpcclient.ProcessInfoReply) error
- func (s *Supervisor) GetState(args *struct{}, reply *struct{ StateInfo StateInfo }) error
- func (s *Supervisor) GetSupervisorVersion(args *rpcclient.GetVersionArg, reply *rpcclient.GetVersionRet) error
- func (s *Supervisor) GetVersion(args *rpcclient.GetVersionArg, reply *rpcclient.GetVersionRet) error
- func (s *Supervisor) Install(args *rpcclient.InstallArg, reply *rpcclient.InstallRet) error
- func (s *Supervisor) ReadLog(args *LogReadInfo, reply *struct{ Log string }) error
- func (s *Supervisor) ReloadConfig(args *rpcclient.ReloadConfigArg, reply *rpcclient.ReloadConfigRet) error
- func (s *Supervisor) Remove(args *rpcclient.RemoveArg, reply *rpcclient.RemoveRet) error
- func (s *Supervisor) RemoveProcessGroup(args *struct{ Name string }, reply *rpcclient.StatusReply) error
- func (s *Supervisor) Restart(args *struct{}, reply *rpcclient.StatusReply) error
- func (s *Supervisor) RestartAllProcesses(args ..., reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) RestartProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error
- func (s *Supervisor) SendProcessStdin(args *ProcessStdin, reply *rpcclient.StatusReply) error
- func (s *Supervisor) SendRemoteCommEvent(args *RemoteCommEvent, reply *rpcclient.StatusReply) error
- func (s *Supervisor) SetEnv(args *rpcclient.SetEnvArg, reply *rpcclient.SetEnvRet) error
- func (s *Supervisor) Shutdown(args *struct{}, reply *rpcclient.StatusReply) error
- func (s *Supervisor) SignalAllProcesses(args *rpcclient.SignalAllProcessesArg, reply *rpcclient.SignalAllProcessesRet) error
- func (s *Supervisor) SignalProcess(args *types.ProcessSignal, reply *rpcclient.StatusReply) error
- func (s *Supervisor) SignalProcessGroup(args *types.ProcessSignal, reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) StartAllProcesses(args ..., reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) StartProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error
- func (s *Supervisor) StartProcessGroup(args *StartProcessArgs, reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) StopAllProcesses(args ..., reply *rpcclient.AllProcessInfoReply) error
- func (s *Supervisor) StopProcess(args *StartProcessArgs, reply *rpcclient.StatusReply) error
- func (s *Supervisor) StopProcessGroup(args *StartProcessArgs, reply *rpcclient.AllProcessInfoReply) error
- type SupervisorRestful
- func (sr *SupervisorRestful) CreateProgramHandler() http.Handler
- func (sr *SupervisorRestful) ListProgram(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) ReadStdoutLog(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) Reload(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) Shutdown(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) StartProgram(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) StartPrograms(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) StopProgram(w http.ResponseWriter, req *http.Request)
- func (sr *SupervisorRestful) StopPrograms(w http.ResponseWriter, req *http.Request)
Constants ¶
const (
SUPERVISOR_VERSION = "3.0"
)
Variables ¶
var (
HttpMux = &HttpServeMux{}
)
Functions ¶
func Daemonize ¶
func Daemonize(proc func())
Daemonize is a thin wrapper that double-forks the current process and runs proc in the child. Equivalent to the historical Deamonize() in the root package's daemonize.go. The unusual spelling is preserved so the public symbol stays backwards compatible with the original shell wrappers.
func FindSupervisordConf ¶
FindSupervisordConf searches well-known locations for the supervisor configuration file. Mirrors the legacy findSupervisordConf() in main.go 1. $CWD/supervisord.conf 2. $CWD/etc/supervisord.conf 3. /etc/supervisord.conf 4. /etc/supervisor/supervisord.conf (since Supervisor 3.3.0) 5. ../etc/supervisord.conf (relative to the executable) 6. ../supervisord.conf (relative to the executable)
The hard-coded paths above are adjusted to the supd defaults:
$CWD/supd.ini, $CWD/etc/supd.ini, /etc/supd/supd.ini, ../etc/supd.ini, ../supd.ini.
func LoadEnvFile ¶
func LoadEnvFile(path string)
LoadEnvFile reads key=value pairs from path (one per line) and applies them to the current process environment. Lines starting with `#` are comments. Lines may optionally start with `export ` (matches the historical shell-source semantics). Equivalent to the function that used to live in main.go.
Types ¶
type HttpServeMux ¶
func (*HttpServeMux) ServeHTTP ¶
func (s *HttpServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
type LogReadInfo ¶
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"`
}
Options mirrors the root-package flag struct used by the daemon entry. Kept here so the daemon startup logic can be moved wholesale out of the root package.
type ProcessLogReadInfo ¶
type ProcessStdin ¶
type ProcessTailLog ¶
type RPCServer ¶
type RPCServer struct {
// contains filtered or unexported fields
}
func NewRPCServer ¶
func NewRPCServer(s *Supervisor) *RPCServer
func (*RPCServer) StartInetHttpServer ¶
func (*RPCServer) StartUnixHttpServer ¶
type RemoteCommEvent ¶
type Server ¶
type Server struct {
// EnvFile is the path to an optional env-file (equivalent to the
// historical options.EnvFile root-package field). May be empty.
EnvFile string
// ConfigPath, when non-empty, is used as the configuration file
// regardless of FindSupervisordConf() auto-detection. Equivalent to
// options.Configuration in the legacy code.
ConfigPath string
}
Server is the public entry point used by the root supd package to start the daemon. It wraps the legacy free-function RunServer() from main.go behind a value so callers can configure supervisor / signal handling without exposing the internal Supervisor type at the root package level.
func NewServer ¶
func NewServer() *Server
NewServer returns a Server ready to have its Run method called.
func (*Server) Run ¶
Run executes the legacy RunServer flow: an infinite loop that reloads the supervisor configuration on each iteration, restarting processes when the binary is replaced. It blocks until the process is killed.
Callers that need custom signal / zombie handling should construct a Server, set EnvFile / ConfigPath, then call Run.
type StartProcessArgs ¶
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) GetIncludeDir ¶
func (s *Supervisor) GetIncludeDir(args *struct{}, reply *rpcclient.IncludeDirReply) 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) Install ¶
func (s *Supervisor) Install(args *rpcclient.InstallArg, reply *rpcclient.InstallRet) 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) 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)