Skip to content

Commit

Permalink
Merge pull request #1 from influxdata/master
Browse files Browse the repository at this point in the history
resync from origin
  • Loading branch information
cbonte authored Oct 16, 2022
2 parents e377407 + 2ad8995 commit 489bca2
Show file tree
Hide file tree
Showing 4,061 changed files with 97,943 additions and 435,613 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1,303 changes: 719 additions & 584 deletions .circleci/config.yml

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions .circleci/package/control/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/bash

BIN_DIR=/usr/bin
DATA_DIR=/var/lib/influxdb
LOG_DIR=/var/log/influxdb
SCRIPT_DIR=/usr/lib/influxdb/scripts
LOGROTATE_DIR=/etc/logrotate.d
INFLUXD_CONFIG_PATH=/etc/influxdb/config.toml

function install_init {
cp -f $SCRIPT_DIR/init.sh /etc/init.d/influxdb
chmod +x /etc/init.d/influxdb
}

function install_systemd {
cp -f $SCRIPT_DIR/influxdb.service /lib/systemd/system/influxdb.service
systemctl enable influxdb
}

function install_update_rcd {
update-rc.d influxdb defaults
}

function install_chkconfig {
chkconfig --add influxdb
}

function should_upgrade {
if [[ ! -s /etc/influxdb/influxdb.conf ]]; then
# No V1 config present, no upgrade needed.
return 1
fi

bolt_dir="/root/.influxdbv2 /var/lib/influxdb/.influxdbv2 /var/lib/influxdb"
for bolt in $bolt_dir; do
if [[ -s ${bolt}/influxd.bolt ]]; then
# Found a bolt file, assume previous v2 upgrade.
return 1
fi
done

return 0
}

function upgrade_notice {
cat << EOF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Important 1.x to 2.x Upgrade Notice !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you for installing InfluxDB v2. Due to significant changes between
the v1 and v2 versions, upgrading to v2 requires additional steps. If
upgrading to v2 was not intended, simply re-install the v1 package now.
An upgrade helper script is available that should be reviewed and executed
prior to starting the influxdb systemd service. In order to start the v2
upgrade, execute the following:
sudo /usr/share/influxdb/influxdb2-upgrade.sh
Visit our website for complete details on the v1 to v2 upgrade process:
https://docs.influxdata.com/influxdb/latest/upgrade/v1-to-v2/
For new or upgrade installations, please review the getting started guide:
https://docs.influxdata.com/influxdb/latest/get-started/
EOF
}

function init_config {
mkdir -p $(dirname ${INFLUXD_CONFIG_PATH})

local config_path=${INFLUXD_CONFIG_PATH}
if [[ -s ${config_path} ]]; then
config_path=${INFLUXD_CONFIG_PATH}.defaults
echo "Config file ${INFLUXD_CONFIG_PATH} already exists, writing defaults to ${config_path}"
fi

cat << EOF > ${config_path}
bolt-path = "/var/lib/influxdb/influxd.bolt"
engine-path = "/var/lib/influxdb/engine"
EOF
}

# Add defaults file, if it doesn't exist
if [[ ! -s /etc/default/influxdb2 ]]; then
cat << EOF > /etc/default/influxdb2
INFLUXD_CONFIG_PATH=${INFLUXD_CONFIG_PATH}
EOF
fi

# Remove legacy symlink, if it exists
if [[ -L /etc/init.d/influxdb ]]; then
rm -f /etc/init.d/influxdb
fi

# Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
if command -v systemctl &>/dev/null; then
install_systemd
else
# Assuming sysv
install_init
install_chkconfig
fi
elif [[ -f /etc/debian_version ]]; then
# Ownership for RH-based platforms is set in build.py via the `rmp-attr` option.
# We perform ownership change only for Debian-based systems.
# Moving these lines out of this if statement would make `rmp -V` fail after installation.
chown -R -L influxdb:influxdb $LOG_DIR
chown -R -L influxdb:influxdb $DATA_DIR
chmod 750 $LOG_DIR
chmod 750 $DATA_DIR

# Debian/Ubuntu logic
if command -v systemctl &>/dev/null; then
install_systemd
else
# Assuming sysv
install_init
install_update_rcd
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ "$NAME" = "Amazon Linux" ]]; then
# Amazon Linux 2+ logic
install_systemd
elif [[ "$NAME" = "Amazon Linux AMI" ]]; then
# Amazon Linux logic
install_init
install_chkconfig
fi
fi

# Check upgrade status
if should_upgrade; then
upgrade_notice
else
init_config
fi
File renamed without changes.
22 changes: 22 additions & 0 deletions .circleci/package/control/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

DATA_DIR=/var/lib/influxdb
USER=influxdb
GROUP=influxdb
LOG_DIR=/var/log/influxdb

if ! id influxdb &>/dev/null; then
useradd --system -U -M influxdb -s /bin/false -d $DATA_DIR
fi

# check if DATA_DIR exists
if [ ! -d "$DATA_DIR" ]; then
mkdir -p $DATA_DIR
chown $USER:$GROUP $DATA_DIR
fi

# check if LOG_DIR exists
if [ ! -d "$LOG_DIR" ]; then
mkdir -p $LOG_DIR
chown $USER:$GROUP $DATA_DIR
fi
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -e

/usr/bin/influxd &
PID=$!
echo $PID > /var/lib/influxdb/influxd.pid

PROTOCOL="http"
BIND_ADDRESS=$(influxd print-config --key-name http-bind-address)
TLS_CERT=$(influxd print-config --key-name tls-cert | tr -d '"')
TLS_KEY=$(influxd print-config --key-name tls-key | tr -d '"')
if [ -n "${TLS_CERT}" ] && [ -n "${TLS_KEY}" ]; then
echo "TLS cert and key found -- using https"
PROTOCOL="https"
fi
HOST=${BIND_ADDRESS%:*}
HOST=${HOST:-"localhost"}
PORT=${BIND_ADDRESS##*:}

set +e
attempts=0
url="$PROTOCOL://$HOST:$PORT/ready"
result=$(curl -k -s -o /dev/null $url -w %{http_code})
while [ "${result:0:2}" != "20" ] && [ "${result:0:2}" != "40" ]; do
attempts=$(($attempts+1))
echo "InfluxDB API at $url unavailable after $attempts attempts..."
sleep 1
result=$(curl -k -s -o /dev/null $url -w %{http_code})
done
echo "InfluxDB started"
set -e
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ User=influxdb
Group=influxdb
LimitNOFILE=65536
EnvironmentFile=-/etc/default/influxdb2
ExecStart=/usr/bin/influxd
ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh
KillMode=control-group
Restart=on-failure
Type=forking
PIDFile=/var/lib/influxdb/influxd.pid
UMask=0027

[Install]
WantedBy=multi-user.target
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
170 changes: 170 additions & 0 deletions .circleci/scripts/build-package
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/bin/bash
set -o errexit \
-o nounset \
-o pipefail

REGEX_RELEASE_VERSION='[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+'

if [[ ${RELEASE:-} ]]
then
# This ensures that release packages are built with valid versions.
# Unfortunately, `fpm` is fairly permissive with what version tags
# it accepts. This becomes a problem when `apt` or `dpkg` is used
# to install the package (both have strict version requirements).
if ! [[ ${VERSION} =~ ^${REGEX_RELEASE_VERSION}$ ]]
then
printf 'Release version is invalid!\n' >&2 && exit 1
fi
fi

function run_fpm()
{
if [[ ${1} == rpm ]]
then
case ${ARCH} in
arm64)
ARCH=aarch64
;;
amd64)
ARCH=x86_64
;;
esac
fi

pushd "${workspace}"

fpm \
--log error \
`# package description` \
--name influxdb2 \
--vendor InfluxData \
--description 'Distributed time-series database.' \
--url https://influxdata.com \
--maintainer [email protected] \
--license MIT \
`# package configuration` \
--input-type dir \
--output-type "${1}" \
--architecture "${ARCH}" \
--version "${VERSION}" \
--iteration 1 \
`# package relationships` \
--deb-recommends influxdb2-cli \
--conflicts influxdb \
--depends curl \
`# package scripts` \
--before-install control/preinst \
--after-install control/postinst \
--after-remove control/postrm \
`# package files` \
--chdir fs/ \
--package /artifacts \
--directories /var/lib/influxdb \
--rpm-defattrdir 750 \
--rpm-defattrfile 750

popd

# `goreleaser` stripped off the package revision and replaced '_' with
# '-'. Since the dockerfiles expect the previous naming convention,
# this rewrites the package names to match. Version information is
# also stored as metadata within the package.
case ${1} in
deb)
mv "/artifacts/influxdb2_${VERSION}-1_${ARCH}.deb" \
"/artifacts/influxdb2-${VERSION}-${ARCH}.deb"
;;
rpm)
mv "/artifacts/influxdb2-${VERSION//-/_}-1.${ARCH}.rpm" \
"/artifacts/influxdb2-${VERSION//-/_}.${ARCH}.rpm"
;;
esac
}

sudo bash <<'EOF'
mkdir /artifacts && chown -R circleci: /artifacts
EOF

build_archive()
{
workspace="$(mktemp -d)"

mkdir "${workspace}/influxdb2_${PLAT}_${ARCH}"

# `failglob` is required because `bin/influxd_${PLAT}_${ARCH}/*` may
# not expand. This will prevent the package from being built without
# the included binary files. This will also display as an error
# from CircleCI interface.
shopt -s failglob
cp -p LICENSE README.md "bin/influxd_${PLAT}_${ARCH}/"* \
"${workspace}/influxdb2_${PLAT}_${ARCH}/"

pushd "${workspace}"

if [[ ${PLAT} != windows ]]
then
# Using `find .. -type f` to supply a list of files to `tar` serves two
# purposes. The first being that `tar` wont construct a '.' directory
# in the root of the tarfile. The second being that this excludes
# empty directories from the tarfile.
find "influxdb2_${PLAT}_${ARCH}/" -type f \
| tar -czf "/artifacts/influxdb2-${VERSION}-${PLAT}-${ARCH}.tar.gz" -T -
else
# windows uses zip
find "influxdb2_${PLAT}_${ARCH}/" -type f \
| zip -r "/artifacts/influxdb2-${VERSION}-${PLAT}-${ARCH}.zip" -@
fi

popd
}

build_package_linux()
{
if [[ ${PLAT} != linux ]]
then
return 0
fi

workspace="$(mktemp -d)"

mkdir -p "${workspace}/fs/usr/bin"

# (see reasoning above)
shopt -s failglob
cp -rp .circleci/package/. "${workspace}/"
cp -p "bin/influxd_${PLAT}_${ARCH}/"* "${workspace}/fs/usr/bin"

run_fpm deb
run_fpm rpm
}

sign_artifacts()
{
# If this is not a release version, don't sign the artifacts. This
# prevents unathorized PRs and branches from being signed with our
# signing key.
if [[ ! ${RELEASE:-} ]]
then
return 0
fi

# CircleCI mangles environment variables with newlines. This key contians
# escaped newlines. For `gpg` to import the key, it requires `echo -e` to
# expand the escape sequences.
gpg --batch --import <<<"$(echo -e "${GPG_PRIVATE_KEY}")"

# TODO(bnpfeife): replace with code signing server
for target in /artifacts/*
do
gpg \
--batch \
--pinentry-mode=loopback \
--passphrase "${PASSPHRASE}" \
--detach-sign \
--armor "${target}"
done
}

build_archive
build_package_linux
sign_artifacts
Loading

0 comments on commit 489bca2

Please sign in to comment.