Merge pull request #4786 from influxdb/package-updates

Backporting changes from build.py to package.sh
pull/4755/merge
Ross McDonald 2015-11-16 13:32:43 -06:00
commit 736e0ace84
5 changed files with 33 additions and 82 deletions

View File

@ -36,17 +36,16 @@ INIT_SCRIPT = "scripts/init.sh"
SYSTEMD_SCRIPT = "scripts/influxdb.service" SYSTEMD_SCRIPT = "scripts/influxdb.service"
PREINST_SCRIPT = "scripts/pre-install.sh" PREINST_SCRIPT = "scripts/pre-install.sh"
POSTINST_SCRIPT = "scripts/post-install.sh" POSTINST_SCRIPT = "scripts/post-install.sh"
PREUNINST_SCRIPT = "scripts/pre-uninstall.sh"
POSTUNINST_SCRIPT = "scripts/post-uninstall.sh" POSTUNINST_SCRIPT = "scripts/post-uninstall.sh"
LOGROTATE_SCRIPT = "scripts/logrotate" LOGROTATE_SCRIPT = "scripts/logrotate"
DEFAULT_CONFIG = "etc/config.sample.toml" DEFAULT_CONFIG = "etc/config.sample.toml"
# META-PACKAGE VARIABLES # META-PACKAGE VARIABLES
PACKAGE_LICENSE = "MIT" PACKAGE_LICENSE = "MIT"
PACKAGE_URL = "github.com/influxdb/influxdb" PACKAGE_URL = "https://github.com/influxdb/influxdb"
MAINTAINER = "support@influxdb.com" MAINTAINER = "InfluxData"
VENDOR = "InfluxData" VENDOR = "InfluxData"
DESCRIPTION = "A distributed time-series database" DESCRIPTION = "A distributed time-series database."
# SCRIPT START # SCRIPT START
prereqs = [ 'git', 'go' ] prereqs = [ 'git', 'go' ]
@ -58,7 +57,6 @@ fpm_common_args = "-f -s dir --log error \
--after-install {} \ --after-install {} \
--before-install {} \ --before-install {} \
--after-remove {} \ --after-remove {} \
--before-remove {} \
--license {} \ --license {} \
--maintainer {} \ --maintainer {} \
--config-files {} \ --config-files {} \
@ -69,7 +67,6 @@ fpm_common_args = "-f -s dir --log error \
POSTINST_SCRIPT, POSTINST_SCRIPT,
PREINST_SCRIPT, PREINST_SCRIPT,
POSTUNINST_SCRIPT, POSTUNINST_SCRIPT,
PREUNINST_SCRIPT,
PACKAGE_LICENSE, PACKAGE_LICENSE,
MAINTAINER, MAINTAINER,
CONFIG_DIR, CONFIG_DIR,
@ -88,9 +85,9 @@ supported_builds = {
'darwin': [ "amd64", "386" ], 'darwin': [ "amd64", "386" ],
# Windows is not currently supported in InfluxDB 0.9.5 due to use of mmap # Windows is not currently supported in InfluxDB 0.9.5 due to use of mmap
# 'windows': [ "amd64", "386", "arm" ], # 'windows': [ "amd64", "386", "arm" ],
'linux': [ "amd64", "386" ] 'linux': [ "amd64", "386", "arm" ]
} }
supported_go = [ '1.5.1' ] supported_go = [ '1.5.1', '1.4.2' ]
supported_packages = { supported_packages = {
"darwin": [ "tar", "zip" ], "darwin": [ "tar", "zip" ],
"linux": [ "deb", "rpm", "tar", "zip" ], "linux": [ "deb", "rpm", "tar", "zip" ],
@ -331,19 +328,21 @@ def create_package_fs(build_root):
print "\t- Creating a filesystem hierarchy from directory: {}".format(build_root) print "\t- Creating a filesystem hierarchy from directory: {}".format(build_root)
# Using [1:] for the path names due to them being absolute # Using [1:] for the path names due to them being absolute
# (will overwrite previous paths, per 'os.path.join' documentation) # (will overwrite previous paths, per 'os.path.join' documentation)
create_dir(os.path.join(build_root, INSTALL_ROOT_DIR[1:])) dirs = [ INSTALL_ROOT_DIR[1:], LOG_DIR[1:], DATA_DIR[1:], SCRIPT_DIR[1:], CONFIG_DIR[1:], LOGROTATE_DIR[1:] ]
create_dir(os.path.join(build_root, LOG_DIR[1:])) for d in dirs:
create_dir(os.path.join(build_root, DATA_DIR[1:])) create_dir(os.path.join(build_root, d))
create_dir(os.path.join(build_root, SCRIPT_DIR[1:])) os.chmod(os.path.join(build_root, d), 0755)
create_dir(os.path.join(build_root, CONFIG_DIR[1:]))
create_dir(os.path.join(build_root, LOGROTATE_DIR[1:]))
def package_scripts(build_root): def package_scripts(build_root):
print "\t- Copying scripts and sample configuration to build directory" print "\t- Copying scripts and sample configuration to build directory"
shutil.copyfile(INIT_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], INIT_SCRIPT.split('/')[1])) shutil.copyfile(INIT_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], INIT_SCRIPT.split('/')[1]))
os.chmod(os.path.join(build_root, SCRIPT_DIR[1:], INIT_SCRIPT.split('/')[1]), 0644)
shutil.copyfile(SYSTEMD_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], SYSTEMD_SCRIPT.split('/')[1])) shutil.copyfile(SYSTEMD_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], SYSTEMD_SCRIPT.split('/')[1]))
os.chmod(os.path.join(build_root, SCRIPT_DIR[1:], SYSTEMD_SCRIPT.split('/')[1]), 0644)
shutil.copyfile(LOGROTATE_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], LOGROTATE_SCRIPT.split('/')[1])) shutil.copyfile(LOGROTATE_SCRIPT, os.path.join(build_root, SCRIPT_DIR[1:], LOGROTATE_SCRIPT.split('/')[1]))
os.chmod(os.path.join(build_root, SCRIPT_DIR[1:], LOGROTATE_SCRIPT.split('/')[1]), 0644)
shutil.copyfile(DEFAULT_CONFIG, os.path.join(build_root, CONFIG_DIR[1:], "influxdb.conf")) shutil.copyfile(DEFAULT_CONFIG, os.path.join(build_root, CONFIG_DIR[1:], "influxdb.conf"))
os.chmod(os.path.join(build_root, CONFIG_DIR[1:], "influxdb.conf"), 0644)
def go_get(update=False): def go_get(update=False):
get_command = None get_command = None
@ -362,7 +361,7 @@ def generate_md5_from_file(path):
m.update(chunk) m.update(chunk)
return m.hexdigest() return m.hexdigest()
def build_packages(build_output, version, nightly=False, rc=None): def build_packages(build_output, version, nightly=False, rc=None, iteration=1):
outfiles = [] outfiles = []
tmp_build_dir = create_temp_dir() tmp_build_dir = create_temp_dir()
try: try:
@ -401,6 +400,9 @@ def build_packages(build_output, version, nightly=False, rc=None):
if package_type == 'tar': if package_type == 'tar':
# Add `tar.gz` to path to ensure a small package size # Add `tar.gz` to path to ensure a small package size
current_location = os.path.join(current_location, name + '.tar.gz') current_location = os.path.join(current_location, name + '.tar.gz')
if package_type == 'deb' and rc:
# For debs with an RC, just append to version number
version += "-rc{}".format(rc)
fpm_command = "fpm {} --name {} -a {} -t {} --version {} -C {} -p {} ".format( fpm_command = "fpm {} --name {} -a {} -t {} --version {} -C {} -p {} ".format(
fpm_common_args, fpm_common_args,
name, name,
@ -411,10 +413,12 @@ def build_packages(build_output, version, nightly=False, rc=None):
current_location) current_location)
if package_type == "rpm": if package_type == "rpm":
fpm_command += "--depends coreutils " fpm_command += "--depends coreutils "
# For rpms with RC, add to iteration for adherence to Fedora packaging standard:
# http://fedoraproject.org/wiki/Packaging%3aNamingGuidelines#NonNumericRelease
if rc: if rc:
fpm_command += "--iteration {} ".format(rc) fpm_command += "--iteration 0.{}.rc{} ".format(iteration, rc)
else: else:
fpm_command += "--iteration 1 " fpm_command += "--iteration 1 ".format(iteration)
out = run(fpm_command, shell=True) out = run(fpm_command, shell=True)
matches = re.search(':path=>"(.*)"', out) matches = re.search(':path=>"(.*)"', out)
outfile = None outfile = None
@ -476,6 +480,7 @@ def main():
clean = False clean = False
upload = False upload = False
test = False test = False
iteration = 1
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if '--outdir' in arg: if '--outdir' in arg:
@ -520,6 +525,8 @@ def main():
elif '--clean' in arg: elif '--clean' in arg:
# Signifies that the outdir should be deleted before building # Signifies that the outdir should be deleted before building
clean = True clean = True
elif '--iteration' in arg:
iteration = arg.split("=")[1]
elif '--help' in arg: elif '--help' in arg:
print_usage() print_usage()
return 0 return 0
@ -533,7 +540,7 @@ def main():
print "!! Cannot be both nightly and a release candidate! Stopping." print "!! Cannot be both nightly and a release candidate! Stopping."
return 1 return 1
# In order to support nightly builds on the repository, we are adding the epoch timestamp # In order to support nightly builds on the repository, we are adding the epoch timestamp
# to the version so that seamless upgrades are possible. # to the version so that version numbers are always greater than the previous nightly.
version = "{}.n{}".format(version, int(time.time())) version = "{}.n{}".format(version, int(time.time()))
# Pre-build checks # Pre-build checks
@ -599,7 +606,7 @@ def main():
if not check_path_for("fpm"): if not check_path_for("fpm"):
print "!! Cannot package without command 'fpm'. Stopping." print "!! Cannot package without command 'fpm'. Stopping."
return 1 return 1
packages = build_packages(build_output, version, nightly=nightly, rc=rc) packages = build_packages(build_output, version, nightly=nightly, rc=rc, iteration=iteration)
# TODO(rossmcdonald): Add nice output for print_package_summary() # TODO(rossmcdonald): Add nice output for print_package_summary()
# print_package_summary(packages) # print_package_summary(packages)
# Optionally upload to S3 # Optionally upload to S3

View File

@ -46,6 +46,9 @@ LOGROTATE_DIR=/etc/logrotate.d
SAMPLE_CONFIGURATION=etc/config.sample.toml SAMPLE_CONFIGURATION=etc/config.sample.toml
INITD_SCRIPT=scripts/init.sh INITD_SCRIPT=scripts/init.sh
SYSTEMD_SCRIPT=scripts/influxdb.service SYSTEMD_SCRIPT=scripts/influxdb.service
POSTINSTALL_SCRIPT=scripts/post-install.sh
PREINSTALL_SCRIPT=scripts/pre-install.sh
POSTUNINSTALL_SCRIPT=scripts/post-uninstall.sh
LOGROTATE=scripts/logrotate LOGROTATE=scripts/logrotate
TMP_WORK_DIR=`mktemp -d` TMP_WORK_DIR=`mktemp -d`
@ -278,52 +281,6 @@ do_build() {
echo "Build completed successfully." echo "Build completed successfully."
} }
# generate_postinstall_script creates the post-install script for the
# package. It must be passed the version.
generate_postinstall_script() {
version=$1
cat <<EOF >$POST_INSTALL_PATH
#!/bin/sh
if ! id influxdb >/dev/null 2>&1; then
useradd --system -U -M influxdb -s /bin/false -d $INFLUXDB_DATA_DIR
fi
chown influxdb:influxdb $INSTALL_ROOT_DIR/influx*
chmod a+rX $INSTALL_ROOT_DIR/influx*
mkdir -p $INFLUXDB_LOG_DIR
chown -R -L influxdb:influxdb $INFLUXDB_LOG_DIR
mkdir -p $INFLUXDB_DATA_DIR
chown -R -L influxdb:influxdb $INFLUXDB_DATA_DIR
test -f /etc/default/influxdb || touch /etc/default/influxdb
# Remove legacy logrotate file
test -f $LOGROTATE_DIR/influxd && rm -f $LOGROTATE_DIR/influxd
# Remove legacy symlink
test -h /etc/init.d/influxdb && rm -f /etc/init.d/influxdb
# Systemd
if which systemctl > /dev/null 2>&1 ; then
cp $INFLUXDB_SCRIPT_DIR/$SYSTEMD_SCRIPT /lib/systemd/system/influxdb.service
systemctl enable influxdb
# Sysv
else
cp -f $INFLUXDB_SCRIPT_DIR/$INITD_SCRIPT /etc/init.d/influxdb
chmod +x /etc/init.d/influxdb
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f influxdb remove
update-rc.d influxdb defaults
else
chkconfig --add influxdb
fi
fi
EOF
echo "Post-install script created successfully at $POST_INSTALL_PATH"
}
########################################################################### ###########################################################################
# Process options # Process options
while : while :
@ -478,8 +435,6 @@ if [ $? -ne 0 ]; then
cleanup_exit 1 cleanup_exit 1
fi fi
generate_postinstall_script `full_version $VERSION $RC`
########################################################################### ###########################################################################
# Create the actual packages. # Create the actual packages.
@ -500,8 +455,9 @@ COMMON_FPM_ARGS="\
--url $URL \ --url $URL \
--license $LICENSE \ --license $LICENSE \
--maintainer $MAINTAINER \ --maintainer $MAINTAINER \
--after-install $POST_INSTALL_PATH \ --after-install $POSTINSTALL_SCRIPT \
--after-remove $POST_UNINSTALL_PATH \ --before-install $PREINSTALL_SCRIPT \
--after-remove $POSTUNINSTALL_SCRIPT \
--name influxdb${RACE} \ --name influxdb${RACE} \
--config-files $CONFIG_ROOT_DIR \ --config-files $CONFIG_ROOT_DIR \
--config-files $LOGROTATE_DIR" --config-files $LOGROTATE_DIR"

View File

@ -8,7 +8,6 @@ LOGROTATE_DIR=/etc/logrotate.d
if ! id influxdb >/dev/null 2>&1; then if ! id influxdb >/dev/null 2>&1; then
useradd --system -U -M influxdb -s /bin/false -d $DATA_DIR useradd --system -U -M influxdb -s /bin/false -d $DATA_DIR
fi fi
chown influxdb:influxdb $BIN_DIR/influx*
chmod a+rX $BIN_DIR/influx* chmod a+rX $BIN_DIR/influx*
mkdir -p $LOG_DIR mkdir -p $LOG_DIR

View File

@ -3,7 +3,7 @@
# Copy existing configuration if pre-existing installation is found # Copy existing configuration if pre-existing installation is found
test -f /etc/opt/influxdb/influxdb.conf test -f /etc/opt/influxdb/influxdb.conf
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
cp -a /etc/opt/influxdb /etc/influxdb cp -a /etc/opt/influxdb/* /etc/influxdb/
fi fi
exit exit

View File

@ -1,11 +0,0 @@
#!/bin/sh
echo "Stopping the InfluxDB process..."
if which systemctl > /dev/null 2>&1; then
systemctl stop influxdb
elif which service >/dev/null 2>&1; then
service influxdb stop
else
/etc/init.d/influxdb stop
fi