cmd/ctrld: add commands to control ctrld as a system service

Supported actions:

 - start: install and start ctrld as a system service
 - stop: stop the ctrld service
 - restart: restart ctrld service
 - status: show status of ctrld service
 - uninstall: remove ctrld from system service
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2023-01-20 21:33:31 +07:00
1 parent 9e7578fb29
commit ec72af1916
8 files changed
+315 -39

No files matched your search

+16 -4
View File
@@ -6,6 +6,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
@@ -17,12 +18,23 @@ import (
"github.com/spf13/viper"
)
// SetConfigName set the config name that ctrld will look for.
func SetConfigName(v *viper.Viper, name string) {
v.SetConfigName(name)
configPath := "$HOME"
// viper has its own way to get user home directory: https://github.com/spf13/viper/blob/v1.14.0/util.go#L134
// To be consistent, we prefer os.UserHomeDir instead.
if homeDir, err := os.UserHomeDir(); err == nil {
configPath = homeDir
}
v.AddConfigPath(configPath)
v.AddConfigPath(".")
}
// InitConfig initializes default config values for given *viper.Viper instance.
func InitConfig(v *viper.Viper, name string) {
v.SetConfigName(name)
v.SetConfigType("toml")
v.AddConfigPath("$HOME/.ctrld")
v.AddConfigPath(".")
SetConfigName(v, name)
v.SetDefault("listener", map[string]*ListenerConfig{
"0": {