Private
(cmd *cobra.Command, args []string)
| 31 | // Private |
| 32 | |
| 33 | func (b *backgroundInstallCommand) run(cmd *cobra.Command, args []string) error { |
| 34 | if os.Getuid() != 0 { |
| 35 | return fmt.Errorf("must be run as root") |
| 36 | } |
| 37 | |
| 38 | ctx := context.Background() |
| 39 | namespace := namespaceFlag(cmd) |
| 40 | |
| 41 | execPath, err := executablePath() |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("finding executable path: %w", err) |
| 44 | } |
| 45 | |
| 46 | svc, err := service.New() |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | serviceName := namespace + backgroundServiceSuffix |
| 52 | |
| 53 | if svc.IsInstalled(serviceName) { |
| 54 | fmt.Printf("Service %s is already installed\n", svc.ServiceName(serviceName)) |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | if err := svc.Install(ctx, serviceName, execPath, namespace); err != nil { |
| 59 | return fmt.Errorf("installing service: %w", err) |
| 60 | } |
| 61 | |
| 62 | fmt.Printf("Installed and started %s\n", svc.ServiceName(serviceName)) |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | // Helpers |
| 67 |
nothing calls this directly
no test coverage detected