Pass installdir as a parameter

This commit is contained in:
Siddharth Bansal
2026-04-20 21:36:42 +05:30
parent 2c8b7b5ca5
commit 473bce856d
2 changed files with 4 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
func installCrowdsec(config Config) error { func installCrowdsec(config Config, installDir string) error {
if err := stopContainers(config.InstallationContainerType); err != nil { if err := stopContainers(config.InstallationContainerType); err != nil {
return fmt.Errorf("failed to stop containers: %v", err) return fmt.Errorf("failed to stop containers: %v", err)
@@ -41,7 +41,7 @@ func installCrowdsec(config Config) error {
os.Exit(1) os.Exit(1)
} }
setupTraefikLogRotate() setupTraefikLogRotate(installDir)
if err := copyDockerService("config/crowdsec/docker-compose.yml", "docker-compose.yml", "crowdsec"); err != nil { if err := copyDockerService("config/crowdsec/docker-compose.yml", "docker-compose.yml", "crowdsec"); err != nil {
fmt.Printf("Error copying docker service: %v\n", err) fmt.Printf("Error copying docker service: %v\n", err)
@@ -219,21 +219,10 @@ func CheckAndAddCrowdsecDependency(composePath string) error {
// copytruncate is used so Traefik does not need to be restarted or sent a // copytruncate is used so Traefik does not need to be restarted or sent a
// signal after rotation — it keeps writing to the same file descriptor while // signal after rotation — it keeps writing to the same file descriptor while
// the rotated copy is made and the original is truncated in place. // the rotated copy is made and the original is truncated in place.
func setupTraefikLogRotate() { func setupTraefikLogRotate(installDir string) {
const logrotateDir = "/etc/logrotate.d" const logrotateDir = "/etc/logrotate.d"
const logrotateFile = "/etc/logrotate.d/pangolin-traefik" const logrotateFile = "/etc/logrotate.d/pangolin-traefik"
// Resolve the absolute path to the install directory so the logrotate
// config references the correct log file regardless of where the user
// installed Pangolin.
installDir, err := filepath.Abs(".")
if err != nil {
fmt.Printf("[logrotate] Warning: could not resolve install directory: %v\n", err)
fmt.Println("[logrotate] Skipping logrotate setup. Set it up manually:")
printLogrotateConfig("<install_dir>/config/traefik/logs/access.log")
return
}
logPath := filepath.Join(installDir, "config/traefik/logs/access.log") logPath := filepath.Join(installDir, "config/traefik/logs/access.log")
if os.Geteuid() != 0 { if os.Geteuid() != 0 {

View File

@@ -259,7 +259,7 @@ func main() {
} }
config.DoCrowdsecInstall = true config.DoCrowdsecInstall = true
err := installCrowdsec(config) err := installCrowdsec(config, installDir)
if err != nil { if err != nil {
fmt.Printf("Error installing CrowdSec: %v\n", err) fmt.Printf("Error installing CrowdSec: %v\n", err)
return return