Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update install command args #16

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func init() {

includeShowFlagsForLda(ldaCmd)
includeShowFlagsForServe(serveCmd)
includeShowFlagsForInstall(installCmd)

cobra.OnInitialize(setupConfig)

Expand All @@ -114,6 +115,11 @@ func includeShowFlagsForServe(cmd *cobra.Command) {
cmd.Flags().StringP("port", "p", "8080", "Port to serve the frontend client")
}

func includeShowFlagsForInstall(cmd *cobra.Command) {
cmd.Flags().BoolP("auto-credentials", "a", false, "Try to automatically generate the credentails")
cmd.Flags().BoolP("workspace", "w", false, "Is collection executed in a DevZero workspace")
}

func setupConfig() {

// setting up the system configuration
Expand Down Expand Up @@ -261,17 +267,30 @@ func stop(_ *cobra.Command, _ []string) error {
return nil
}

func install(_ *cobra.Command, _ []string) error {
func install(cmd *cobra.Command, _ []string) error {

autoCredentials, err := cmd.Flags().GetBool("auto-credentials")
if err != nil {
logging.Log.Error().Err(err).Msg("Failed to get auto-credentials flag")
return errors.Wrap(err, "failed to get auto-credentials flag")
}

isWorkspace, err := cmd.Flags().GetBool("workspace")
if err != nil {
logging.Log.Error().Err(err).Msg("Failed to get workspace flag")
return errors.Wrap(err, "failed to get workspace flag")
}
user.ConfigureUserSystemInfo(user.Conf)

daemonConf := &daemon.Config{
ExePath: user.Conf.ExePath,
HomeDir: user.Conf.HomeDir,
IsRoot: user.Conf.IsRoot,
Os: config.OSType(user.Conf.Os),
SudoExecUser: user.Conf.User,
ShellLocation: user.Conf.ShellLocation,
ExePath: user.Conf.ExePath,
HomeDir: user.Conf.HomeDir,
IsRoot: user.Conf.IsRoot,
Os: config.OSType(user.Conf.Os),
SudoExecUser: user.Conf.User,
ShellLocation: user.Conf.ShellLocation,
AutoCredential: autoCredentials,
IsWorkspace: isWorkspace,
}
dmn := daemon.NewDaemon(daemonConf, logging.Log)

Expand Down
34 changes: 28 additions & 6 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
MacOSDaemonTemplateLocation = "services/lda.plist"
ServicePermission = 0644
DirPermission = 0755
BaseCollectCommand = "collect"
)

// Embedding scripts directory
Expand All @@ -36,12 +37,14 @@ var templateFS embed.FS

// Config is the configuration for the daemon service
type Config struct {
ExePath string
ShellLocation string
HomeDir string
Os config.OSType
IsRoot bool
SudoExecUser *user.User
ExePath string
ShellLocation string
HomeDir string
Os config.OSType
IsRoot bool
SudoExecUser *user.User
AutoCredential bool
IsWorkspace bool
}

// Daemon is the service that configures background service
Expand Down Expand Up @@ -90,6 +93,25 @@ func (d *Daemon) InstallDaemonConfiguration() error {
tmpConf["Group"] = group.Name
}

collectCmd := []string{
BaseCollectCommand,
}
if d.config.AutoCredential {
collectCmd = append(collectCmd, "-a")
}
if d.config.IsWorkspace {
collectCmd = append(collectCmd, "-w")
}

// create command from args in colllectCmd
var command string
for _, arg := range collectCmd {
command += arg + " "
}

tmpConf["CollectCommand"] = command
tmpConf["CollectCommandSplit"] = collectCmd

if err := tmpl.Execute(&content, tmpConf); err != nil {
d.logger.Err(err).Msg("Failed to execute daemon template")
return err
Expand Down
4 changes: 3 additions & 1 deletion daemon/services/lda.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<key>ProgramArguments</key>
<array>
<string>{{.BinaryPath}}</string>
<string>collect</string>
{{- range .CollectCommandSplit }}
<string>{{.}}</string>
{{- end }}
</array>
<key>RunAtLoad</key>
<true/>
Expand Down
2 changes: 1 addition & 1 deletion daemon/services/lda.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Environment="HOME={{.Home}}"
User={{.Username}}
Group={{.Group}}
Type=simple
ExecStart={{.BinaryPath}} collect
ExecStart={{.BinaryPath}} {{.CollectCommand}}
Restart=always
StandardOutput=file:/tmp/devzero.io.lda.out.log
StandardError=file:/tmp/devzero.io.lda.err.log
Expand Down
Loading