mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
don't ask user to reload systemd service when running in docker (#3434)
* don't ask user to reload systemd service when running in docker * refactor + give appropriate message if terminal is attached * remove explicit filetype
This commit is contained in:
parent
763959fb68
commit
bfed861ba7
16 changed files with 51 additions and 25 deletions
|
@ -1,4 +1,3 @@
|
|||
# vim: set ft=dockerfile:
|
||||
FROM docker.io/golang:1.23-alpine3.20 AS build
|
||||
|
||||
ARG BUILD_VERSION
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# vim: set ft=dockerfile:
|
||||
FROM docker.io/golang:1.23-bookworm AS build
|
||||
|
||||
ARG BUILD_VERSION
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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 msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded {
|
||||
fmt.Println("\n" + msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
6
cmd/crowdsec-cli/reload/message.go
Normal file
6
cmd/crowdsec-cli/reload/message.go
Normal file
|
@ -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."
|
|
@ -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."
|
|
@ -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
cmd/crowdsec-cli/reload/message_windows.go
Normal file
3
cmd/crowdsec-cli/reload/message_windows.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package reload
|
||||
|
||||
const message = "Please restart the crowdsec service for the new configuration to be effective."
|
|
@ -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."
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package reload
|
||||
|
||||
const Message = "Please restart the crowdsec service for the new configuration to be effective."
|
Loading…
Add table
Add a link
Reference in a new issue