Documentation ¶
Index ¶
- Constants
- Variables
- func GetChildPidsFile() string
- func GetParentDir(p string) string
- func GetPidFile() string
- func GetTCPAddr() string
- func Run()
- func SetWorkDir(dir string) bool
- func Start(configPath string, deamon, forceLog bool)
- type CmdStatus
- type Command
- func (c *Command) ID() string
- func (c *Command) IsCron() bool
- func (c *Command) IsPause() bool
- func (c *Command) Kill() error
- func (c *Command) Name() string
- func (c *Command) Output() string
- func (c *Command) Pid() int
- func (c *Command) Process() *os.Process
- func (c *Command) Release() error
- func (c *Command) ResetPid()
- func (c *Command) SetCron(express string) *Command
- func (c *Command) SetID(id string)
- func (c *Command) SetName(name string) *Command
- func (c *Command) SetPause()
- func (c *Command) SetRun()
- func (c *Command) Singal(sig os.Signal) error
- func (c *Command) Start() int
- func (c *Command) TurnOffCron() bool
- func (c *Command) TurnOnCron() bool
- func (c *Command) Wait() (*os.ProcessState, error)
- type CopyState
- type ProcessConfig
- type RunningStatus
- type State
Constants ¶
View Source
const ( //ActReload 重新读取配置 并重新启动所有协程 ActReload = sigReload //ActExit 管理进程退出 ActExit = sigExit //ActStart 启动协程 ActStart = sigStart //ActExec 单独执行命令 ActExec = sigExec //ActPause 终端所有任务 ActPause = sigPause )
View Source
const ( ErrResCodeNo = iota //无错误 0 ErrResWrgMsg //消息结构不正确 1 ErrResUdfCtl //未定义的操作命令 2 ErrResMissCmd //缺少命令ID 3 ErrResStatNil //未获取到合法的参数 4 ErrResWrgSig //未定义的信号 5 ErrResCtlSig //缺少需要重启的命令id 6 )
定义一些常量 错误编号
View Source
const ( MsgSigCtl = "ctl" //控制 MsgSigStat = "stat" //查询 )
客户端操作命令常量
View Source
const ( //DefaultBrokenGap 默认的中断容忍间隔 DefaultBrokenGap int64 = 5 //DefaultHost 默认的tcp 主机地址 DefaultHost = "127.0.0.1" //DefaultPort 默认的tcp 端口 DefaultPort = "17101" //UnixSysRunDir uinx系的运行目录 UnixSysRunDir = "/var/run/" //UnixSysTmpDir unix系的临时目录 UnixSysTmpDir = "/tmp/" )
Variables ¶
View Source
var ( //SigMap 信号map SigMap map[string]int //StatArgsMap 信号参数map StatArgsMap []string )
View Source
var ( //DefaultLogPath 默认主程序日志打印位置 DefaultLogPath string //MainPid 主程序pid MainPid int //AutoStart 自动启动命令 AutoStart bool )
View Source
var ( //StateCopy 监控服务状态的备份 用于返回客户端查询请求 StateCopy CopyState //StartTime 监控服务启动时间 StartTime int64 //ReloadTime 监控服务重载的时间点 ReloadTime []int64 )
View Source
var ErrMsgMap = []string{
"success",
"wrong message",
"undefined ctl type",
"miss cmd id",
"found nil args",
"undefined signal",
"undefined restart cmd",
}
ErrMsgMap 错误编号对应的消息数组
Functions ¶
func SetWorkDir ¶
SetWorkDir 外部设置工作目录 如果是绝对路径 直接赋值 如果是相对路径 则按照当前目录为起始获取绝对路径
Types ¶
type CmdStatus ¶
type CmdStatus struct { ID string `json:"id"` //命令id Name string `json:"name"` //命令名称 Pid int `json:"pid"` //命令pid Cmd string `json:"cmd"` //命令的启动参数 Output string `json:"output"` //命令输出的打印位置 BkTimes int `json:"brokens"` //中断次数 LastBkTime string `json:"last_broken_time"` //上一次中断的时间 IsCron bool `json:"is_cron"` //是否是cron }
CmdStatus 单个子程序的运行状态信息
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command 执行命令的配置结构 重新封装了cmd
func NewCommand ¶
NewCommand 返回一个等待执行的cmd结构体
type CopyState ¶
type CopyState struct { TasksNum int //程序总的运行数量 RunningNum int //正在运行的命令数 BrokenNum int //由于崩溃或结束运行的命令数 RunningList map[string]*Command //正在运行的命令map BrokenList map[string]*Command //运行中断的命令map BrokenTries map[string]int //命令中断后在容忍间隔时间内的重试次数 BrokenPoints map[string]int64 //命令中断的时间点 CronState bool //是否已经开启cron协程 SecCronList map[string]*Command //秒级cron列表 MinCronList map[string]*Command //分钟级cron列表 }
CopyState 运行状态结构备份
type ProcessConfig ¶
type ProcessConfig struct { //ConfigPath 启动时使用的配置文件 ConfigPath string `json:"conf_path"` //TCPAddr Tcp启动地址 TCPAddr string `json:"tcp_addr"` //PidFile Pid文件地址 PidFile string `json:"pid_file"` //SockFile sock文件存储路径 SockFile string `json:"sock_file"` //ChdFile 子进程pid统一存储路径 ChdFile string `json:"child_pids"` //LogFile 主程序日志打印位置 LogFile string `json:"log_file"` // contains filtered or unexported fields }
ProcessConfig 主程序配置结构
type RunningStatus ¶
type RunningStatus struct { Pid int `json:"main_pid"` //主程序pid StartTime string `json:"start_time"` //主程序启动时间 ReloadTime []string `json:"reload_time_list"` //主程序重载配置时间列表 TotalTasks int `json:"task_total_num"` //可以启动的子程序总数 RunningTasks []string `json:"running_task_list"` //正在运行的子程序命令集合 TermTasks []string `json:"term_task_list"` //中断的子程序命令集合 RunningSeconds string `json:"running_seconds"` //程序运行时间 CronState bool `json:"cron_state"` //是否已经开启cron协程 SecCronList []string `json:"second_cron_list"` //秒级cron列表 MinCronList []string `json:"minute_cron_list"` //分钟级cron列表 }
RunningStatus 服务状态
type State ¶
type State struct { TasksNum int //程序总的运行数量 RunningNum int //正在运行的命令数 BrokenNum int //由于崩溃或结束运行的命令数 RunningList map[string]*Command //正在运行的命令map BrokenList map[string]*Command //运行中断的命令map BrokenTries map[string]int //命令中断后在容忍间隔时间内的重试次数 BrokenPoints map[string]int64 //命令中断的时间点 Numlock sync.Mutex //操作各数量变更的锁 CronState bool //是否已经开启cron协程 SecCronList map[string]*Command //秒级cron列表 MinCronList map[string]*Command //分钟级cron列表 IsRun bool //是否已经开始运行 }
State 状态机
var (
RunState *State //状态机实例
)
运行时的必要参数
Click to show internal directories.
Click to hide internal directories.