Skip to content

Commit

Permalink
Support $GEOIPUPDATE_CONF_FILE in geoipupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
ugexe committed Jun 23, 2023
1 parent 928b738 commit 34a4203
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
The following new environment variables are supported:

* `GEOIPUPDATE_ACCOUNT_ID`
* `GEOIPUPDATE_CONF_FILE`
* `GEOIPUPDATE_DB_DIR`
* `GEOIPUPDATE_EDITION_IDS`
* `GEOIPUPDATE_HOST`
Expand Down
7 changes: 6 additions & 1 deletion cmd/geoipupdate/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ type Args struct {
}

func getArgs() *Args {
confFileDefault := vars.DefaultConfigFile
if value, ok := os.LookupEnv("GEOIPUPDATE_CONF_FILE"); ok {
confFileDefault = value
}

configFile := flag.StringP(
"config-file",
"f",
vars.DefaultConfigFile,
confFileDefault,
"Configuration file",
)
databaseDirectory := flag.StringP(
Expand Down
5 changes: 3 additions & 2 deletions doc/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ The following are optional:
default is `0`.
* `GEOIPUPDATE_VERBOSE` - Enable verbose mode. Prints out the steps that
`geoipupdate` takes. Set to `1` to enable.
* `GEOIPUPDATE_CONF_FILE` - The path where the configuration file will be
written. The default is `/etc/GeoIP.conf`.
* `GEOIPUPDATE_CONF_FILE` - The path of a configuration file to be used by
`geoipupdate`. If this file does not exist, an empty file will be created.
The default is `/etc/GeoIP.conf`.
* `GEOIPUPDATE_DB_DIR` - The directory where geoipupdate will download the
databases. The default is `/usr/share/GeoIP`.

Expand Down
3 changes: 2 additions & 1 deletion doc/geoipupdate.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ open.
`-f`, `--config-file`

: The configuration file to use. See `GeoIP.conf` and its documentation for
more information. This is optional. It defaults to CONFFILE.
more information. This is optional. It defaults to the environment variable
`GEOIPUPDATE_CONF_FILE` if it is set, or CONFFILE otherwise.

`--parallelism`

Expand Down
8 changes: 4 additions & 4 deletions docker/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ log_file="$log_dir/.healthcheck"
flags="--output"
frequency=$((GEOIPUPDATE_FREQUENCY * 60 * 60))

if ! [ -z "$GEOIPUPDATE_CONF_FILE" ]; then
conf_file=$GEOIPUPDATE_CONF_FILE
if [ -z "$GEOIPUPDATE_CONF_FILE" ]; then
GEOIPUPDATE_CONF_FILE="$conf_file"
fi

if ! [ -z "$GEOIPUPDATE_DB_DIR" ]; then
Expand All @@ -45,13 +45,13 @@ fi
# Create an empty configuration file. All configuration is provided via
# environment variables or command line options, but geoipupdate still
# expects a configuration file to exist.
touch "$conf_file"
touch "$GEOIPUPDATE_CONF_FILE"

mkdir -p $log_dir

while true; do
echo "# STATE: Running geoipupdate"
/usr/bin/geoipupdate -d "$database_dir" -f "$conf_file" $flags 1>$log_file
/usr/bin/geoipupdate -d "$database_dir" $flags 1>$log_file
if [ "$frequency" -eq 0 ]; then
break
fi
Expand Down

0 comments on commit 34a4203

Please sign in to comment.