Skip to content

Commit

Permalink
don't ask user to reload systemd service when running in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jan 29, 2025
1 parent 5178a91 commit 9189d19
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 23 deletions.
4 changes: 3 additions & 1 deletion cmd/crowdsec-cli/clicapi/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func (cli *cliCapi) register(ctx context.Context, capiUserPrefix string, outputF
fmt.Println(string(apiConfigDump))
}

log.Warning(reload.Message)
if reload.UserMessage() != "" {
log.Warning(reload.UserMessage())
}

return nil
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/crowdsec-cli/cliconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ Enable given information push to the central API. Allows to empower the console`
log.Infof("%v have been enabled", args)
}

log.Info(reload.Message)
if reload.UserMessage() != "" {
log.Info(reload.UserMessage())
}

return nil
},
Expand Down Expand Up @@ -248,7 +250,9 @@ Disable given information push to the central API.`,
log.Infof("%v have been disabled", args)
}

log.Info(reload.Message)
if reload.UserMessage() != "" {
log.Info(reload.UserMessage())
}

return nil
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/clihub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (cli *cliHub) upgrade(ctx context.Context, yes bool, dryRun bool, force boo
return err
}

if plan.ReloadNeeded {
fmt.Println("\n" + reload.Message)
if plan.ReloadNeeded && reload.UserMessage() != "" {
fmt.Println("\n" + reload.UserMessage())

Check warning on line 197 in cmd/crowdsec-cli/clihub/hub.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clihub/hub.go#L197

Added line #L197 was not covered by tests
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/cliitem/cmdinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (cli cliItem) install(ctx context.Context, args []string, yes bool, dryRun
log.Error(err)
}

if plan.ReloadNeeded {
fmt.Println("\n" + reload.Message)
if plan.ReloadNeeded && reload.UserMessage() != "" {
fmt.Println("\n" + reload.UserMessage())
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/cliitem/cmdremove.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun b
return err
}

if plan.ReloadNeeded {
fmt.Println("\n" + reload.Message)
if plan.ReloadNeeded && reload.UserMessage() != "" {
fmt.Println("\n" + reload.UserMessage())
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/cliitem/cmdupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (cli cliItem) upgrade(ctx context.Context, args []string, yes bool, dryRun
return err
}

if plan.ReloadNeeded {
fmt.Println("\n" + reload.Message)
if plan.ReloadNeeded && reload.UserMessage() != "" {
fmt.Println("\n" + reload.UserMessage())
}

return nil
Expand Down
4 changes: 3 additions & 1 deletion cmd/crowdsec-cli/clilapi/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (cli *cliLapi) register(ctx context.Context, apiURL string, outputFile stri
fmt.Printf("%s\n", string(apiConfigDump))
}

log.Warning(reload.Message)
if reload.UserMessage() != "" {
log.Warning(reload.UserMessage())
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/clisimulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ cscli simulation disable crowdsecurity/ssh-bf`,
return nil
},
PersistentPostRun: func(cmd *cobra.Command, _ []string) {
if cmd.Name() != "status" {
log.Info(reload.Message)
if cmd.Name() != "status" && reload.UserMessage() != "" {
log.Info(reload.UserMessage())
}
},
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/crowdsec-cli/reload/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build !windows && !freebsd && !linux

package reload

// generic message since we don't know the platform
const message = "Please reload the crowdsec process for the new configuration to be effective."
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reload

// actually sudo is not that popular on freebsd, but this will do
const Message = "Run 'sudo service crowdsec reload' for the new configuration to be effective."
const message = "Run 'sudo service crowdsec reload' for the new configuration to be effective."
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reload

// assume systemd, although gentoo and others may differ
const Message = "Run 'sudo systemctl reload crowdsec' for the new configuration to be effective."
const message = "Run 'sudo systemctl reload crowdsec' for the new configuration to be effective."
3 changes: 3 additions & 0 deletions cmd/crowdsec-cli/reload/message_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package reload

const message = "Please restart the crowdsec service for the new configuration to be effective."
15 changes: 11 additions & 4 deletions cmd/crowdsec-cli/reload/reload.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
//go:build !windows && !freebsd && !linux

package reload

// generic message since we don't know the platform
const Message = "Please reload the crowdsec process for the new configuration to be effective."
import (
"github.com/crowdsecurity/go-cs-lib/version"
)

func UserMessage() string {
if version.System == "docker" {
return ""
}

Check warning on line 10 in cmd/crowdsec-cli/reload/reload.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/reload/reload.go#L9-L10

Added lines #L9 - L10 were not covered by tests

return message
}
3 changes: 0 additions & 3 deletions cmd/crowdsec-cli/reload/reload_windows.go

This file was deleted.

0 comments on commit 9189d19

Please sign in to comment.