MCPcopy
hub / github.com/basecamp/once / run

Method run

internal/command/background_install.go:33–64  ·  view source on GitHub ↗

Private

(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

31// Private
32
33func (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

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
namespaceFlagFunction · 0.85
executablePathFunction · 0.85
IsInstalledMethod · 0.65
ServiceNameMethod · 0.65
InstallMethod · 0.65

Tested by

no test coverage detected