geoip2influx/root/etc/cont-init.d/50-config

43 lines
1.5 KiB
Text
Raw Normal View History

2020-06-25 22:43:33 +02:00
#!/usr/bin/with-contenv bash
echo -e "Variables set:\\n\
NGINX_LOG_PATH=${NGINX_LOG_PATH}\\n\
INFLUX_HOST=${INFLUX_HOST}\\n\
INFLUX_HOST_PORT=${INFLUX_HOST_PORT}\\n\
INFLUX_DATABASE=${INFLUX_DATABASE}\\n\
INFLUX_USER=${INFLUX_USER}\\n\
INFLUX_PASS=${INFLUX_PASS}\\n\
INFLUX_RETENTION=${INFLUX_RETENTION}\\n\
INFLUX_SHARD=${INFLUX_SHARD}\\n\
GEO_MEASUREMENT=${GEO_MEASUREMENT}\\n\
LOG_MEASUREMENT=${LOG_MEASUREMENT}\\n\
SEND_NGINX_LOGS=${SEND_NGINX_LOGS}\\n\
GEOIP2INFLUX_LOG_LEVEL=${GEOIP2INFLUX_LOG_LEVEL}\\n\
2020-10-04 23:16:00 +02:00
GEOIP2INFLUX_LOG_PATH=${GEOIP2INFLUX_LOG_PATH}\\n\
2020-06-25 22:43:33 +02:00
MAXMINDDB_LICENSE_KEY=${MAXMINDDB_LICENSE_KEY}\\n"
2020-10-04 23:16:00 +02:00
mkdir -p \
/config/geoip2db \
/config/log/geoip2influx
2020-08-17 17:53:45 +02:00
cp -f /geoip2influx/geoip2influx.py /config/geoip2db
2020-10-04 23:16:00 +02:00
# move old log if needed
if [ -f /config/geoip2db/geoip2influx.log ]; then
mv /config/geoip2db/geoip2influx.log /config/log/geoip2influx
2020-06-25 22:43:33 +02:00
# create GeoIP2 folder symlink
[[ -d /var/lib/libmaxminddb ]] && [[ ! -L /var/lib/libmaxminddb ]] && \
rm -rf /var/lib/libmaxminddb
[[ ! -d /var/lib/libmaxminddb ]] && \
ln -s /config/geoip2db /var/lib/libmaxminddb
# check GeoIP2 database
if [ -n "$MAXMINDDB_LICENSE_KEY" ]; then
sed -i "s|.*MAXMINDDB_LICENSE_KEY.*|MAXMINDDB_LICENSE_KEY=\"${MAXMINDDB_LICENSE_KEY}\"|g" /etc/conf.d/libmaxminddb
if [ ! -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]; then
echo "Downloading GeoIP2 City database."
/etc/periodic/weekly/libmaxminddb
fi
2020-06-28 14:43:10 +02:00
fi
2020-08-17 17:53:45 +02:00
# permissions
chown -R abc:abc /config/geoip2db
chmod +x /config/geoip2db/geoip2influx.py
chmod -R 0644 /etc/logrotate.d