Skip to content

Commit

Permalink
fix: adding redirect of stdout on failing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Sep 17, 2024
1 parent dc5f6fa commit c13fa39
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions api/utils/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net"
"os"
"os/exec"
"strings"
"time"
)

Expand Down Expand Up @@ -60,27 +61,32 @@ func DownloadGeoIpDatabase() {
logs.Logs.Println("[INFO][GEOIP] geoip db file is up to date")
return
}
err = exec.Command(
cmd := exec.Command(
"curl",
"-L",
"--fail",
"--retry", "5",
"--retry-max-time", "120",
"https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key="+configuration.Config.MaxmindLicense+"&suffix=tar.gz",
"-o", configuration.Config.GeoIPDbDir+"/GeoLite2-Country.tar.gz",
).Run()
)
var out strings.Builder
cmd.Stderr = &out
err = cmd.Run()
if err != nil {
logs.Logs.Println("[ERR][GEOIP] error downloading geoip db file :" + err.Error())
logs.Logs.Println("[ERR][GEOIP] error downloading geoip db file: " + out.String())
return
}
err = exec.Command(
cmd = exec.Command(
"tar",
"xvzf",
configuration.Config.GeoIPDbDir+"/GeoLite2-Country.tar.gz",
"--strip-components=1",
).Run()
)
cmd.Stderr = &out
err = cmd.Run()
if err != nil {
logs.Logs.Println("[ERR][GEOIP] error extracting geoip db file :" + err.Error())
logs.Logs.Println("[ERR][GEOIP] error extracting geoip db file: " + out.String())
return
}
}

0 comments on commit c13fa39

Please sign in to comment.