2021-06-20 23:01:44 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-03-25 13:21:04 +01:00
|
|
|
"context"
|
2021-06-20 23:01:44 +02:00
|
|
|
"runtime"
|
2022-03-08 14:47:55 +01:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2021-06-20 23:01:44 +02:00
|
|
|
)
|
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
var installCmd = &cobra.Command{
|
|
|
|
Use: "install",
|
|
|
|
Short: "installs wiretrustee service",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
SetFlagsFromEnvVars()
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
svcConfig := newSVCConfig()
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
svcConfig.Arguments = []string{
|
|
|
|
"service",
|
|
|
|
"run",
|
|
|
|
"--config",
|
|
|
|
configPath,
|
|
|
|
"--log-level",
|
|
|
|
logLevel,
|
|
|
|
}
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
// Respected only by systemd systems
|
|
|
|
svcConfig.Dependencies = []string{"After=network.target syslog.target"}
|
|
|
|
}
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-25 13:21:04 +01:00
|
|
|
ctx, cancel := context.WithCancel(cmd.Context())
|
|
|
|
|
|
|
|
s, err := newSVC(newProgram(ctx, cancel), svcConfig)
|
2022-03-08 14:47:55 +01:00
|
|
|
if err != nil {
|
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return err
|
|
|
|
}
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
err = s.Install()
|
|
|
|
if err != nil {
|
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cmd.Println("Wiretrustee service has been installed")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
var uninstallCmd = &cobra.Command{
|
|
|
|
Use: "uninstall",
|
|
|
|
Short: "uninstalls wiretrustee service from system",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
SetFlagsFromEnvVars()
|
2021-06-20 23:01:44 +02:00
|
|
|
|
2022-03-25 13:21:04 +01:00
|
|
|
ctx, cancel := context.WithCancel(cmd.Context())
|
|
|
|
|
|
|
|
s, err := newSVC(newProgram(ctx, cancel), newSVCConfig())
|
2022-03-08 14:47:55 +01:00
|
|
|
if err != nil {
|
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.Uninstall()
|
|
|
|
if err != nil {
|
|
|
|
cmd.PrintErrln(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd.Println("Wiretrustee has been uninstalled")
|
|
|
|
},
|
|
|
|
}
|