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

don't ask user to reload systemd service when running in docker #3434

Merged
merged 3 commits into from
Jan 31, 2025
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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# vim: set ft=dockerfile:
FROM docker.io/golang:1.23-alpine3.20 AS build

ARG BUILD_VERSION
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# vim: set ft=dockerfile:
FROM docker.io/golang:1.23-bookworm AS build

ARG BUILD_VERSION
Expand Down
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 msg := reload.UserMessage(); msg != "" {
log.Warning(msg)
}

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 msg := reload.UserMessage(); msg != "" {
log.Info(msg)
}

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 @@
return err
}

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

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 msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded {
fmt.Println("\n" + msg)
}

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 msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded {
fmt.Println("\n" + msg)
}

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 msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded {
fmt.Println("\n" + msg)
}

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 msg := reload.UserMessage(); msg != "" {
log.Warning(msg)
}

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 msg := reload.UserMessage(); msg != "" && cmd.Name() != "status" {
log.Info(msg)
}
},
}
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."
22 changes: 18 additions & 4 deletions cmd/crowdsec-cli/reload/reload.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
//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 (
"os"

"github.com/crowdsecurity/go-cs-lib/version"
isatty "github.com/mattn/go-isatty"
)

func UserMessage() string {
if version.System == "docker" {
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
return "You may need to restart the container to apply the changes."
}

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

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/reload/reload.go#L12-L14

Added lines #L12 - L14 were not covered by tests

return ""

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

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/reload/reload.go#L16

Added line #L16 was not covered by tests
}

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

This file was deleted.

Loading