csghub-ctl is a command-line tool designed to interact with the omnibus csghub environment. It relies on the omnibus csghub runtime environment and cannot operate independently. This tool inherits the main client commands of the csghub services.
Example usage:
$ csghub-ctl --help
NAME:
csghub-ctl - A command-line tool to manage csghub services, with self-compiled and inheriting all other commands
USAGE:
csghub-ctl [global options] command [command options]
VERSION:
1.3.2
COMMANDS:
reconfigure Reconfigure all services based on the configuration file
praefect Commands for managing praefect service
consul Commands for managing consul service
psql Commands for managing postgresql service
patroni Commands for managing patroni service
mc Commands for managing minio service
kyml Checking if Kubernetes YAML resources exists.
creds Commands for fetch credentials.
tail Tail services logs
start Start service
stop Stop service
restart Restart service
status Show status of service
enable Enable a service
disable Disable a service
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
-
reconfigure
Used to configure custom services by rendering startup scripts and configuration files. -
tail
View service logs. -
kyml
Verify and Create YAML resource files for Kubernetes. -
creds
Get private credentials.
To add new inherited commands, follow these steps:
By default, during reconfigure, the service runs under a user with the same name as the service. To run under a different user (e.g., running patroni as user role postgres), add user mappings:
func MapUser(user string) string {
if u, ok := fixedUsers[user]; ok {
return u
}
return user
}Add an executor only if the client command requires a specific runtime environment (e.g., Python). If the client is a standalone binary, use the default CommandExecutor.
Example executors:
type CommandExecutor struct{}
func (e *CommandExecutor) Execute(cmd string, args []string) error {
execCmd := exec.Command(cmd, args...)
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
return execCmd.Run()
}
// PatroniExecutor — Executor for patronictl commands
type PatroniExecutor struct{}
func (e *PatroniExecutor) Execute(cmd string, args []string) error {
// Execute command using python3
pythonCmd := filepath.Join(clis.BasePath, "python3.11")
fullArgs := append([]string{cmd}, args...)
execCmd := exec.Command(pythonCmd, fullArgs...)
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
execCmdEnv, err := LoadEnvForService("patroni", execCmd)
if err != nil {
return err
}
return execCmdEnv.Run()
}Set the command help text boundaries for each service:
// Command help text patterns for each service
var serviceHelpPatterns = map[string]struct {
Begin string
End string
}{
"praefect": {
Begin: `^COMMANDS`,
End: `^GLOBAL OPTIONS`,
},
"patroni": {
Begin: `Commands:`,
End: `Output version`,
},
"consul": {
Begin: `^Available commands are`,
End: `^$`,
},
"mc": {
Begin: `^COMMANDS`,
End: `^GLOBAL FLAGS:`,
},
"postgresql": {
Begin: `^General options`,
End: `^For more information`,
},
"_default": {
Begin: `Commands:`,
End: `Flags:`,
},
}Example: Add Consul Command.
func ConsulCommand() *cli.Command {
return &cli.Command{
Name: "consul",
Usage: "Commands for managing consul service",
Subcommands: common.GetServiceSubcommands("consul", filepath.Join(common.BasePath, "consul")),
Action: runInheritedService(
"consul",
&common.CommandExecutor{},
),
}
}Example: inheriting the consul command.
func main() {
app := &cli.App{
Name: "csghub-ctl",
Version: "1.3.2",
Usage: "A command-line tool to manage csghub services, with self-compiled and inheriting all other commands",
Commands: []*cli.Command{
cmd.ConsulCommand(),
},
}
app.Commands = append(app.Commands,
cmd.ServiceCommands()...,
)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}To inherit commands for other services, simply replace "consul" with the desired service name.