#!/bin/sh # Copyright (C) The Arvados Authors. All rights reserved. # # SPDX-License-Identifier: AGPL-3.0 # This code runs after package variable definitions and step2.sh. set -e for DISTRO_FAMILY in $(. /etc/os-release && echo "${ID:-} ${ID_LIKE:-}"); do case "$DISTRO_FAMILY" in debian) RESETUP_CMD="dpkg-reconfigure $PACKAGE_NAME" break ;; rhel) RESETUP_CMD="dnf reinstall $PACKAGE_NAME" break ;; esac done if [ -z "$RESETUP_CMD" ]; then echo "$PACKAGE_NAME postinst skipped: don't recognize the distribution from /etc/os-release" >&2 exit 0 fi # Default documentation URL. This can be set to a more specific URL. NOT_READY_DOC_URL="https://doc.arvados.org/install/install-api-server.html" report_web_service_warning() { local warning="$1"; shift cat >&2 <&1 || true` if echo "$DB_MIGRATE_STATUS" | grep -qF 'Schema migrations table does not exist yet.'; then # The database exists, but the migrations table doesn't. run_and_report "Setting up database" bin/rake \ "$RAILSPKG_DATABASE_LOAD_TASK" db:seed elif echo "$DB_MIGRATE_STATUS" | grep -q '^database: '; then run_and_report "Running db:migrate" \ bin/rake db:migrate elif echo "$DB_MIGRATE_STATUS" | grep -q 'database .* does not exist'; then run_and_report "Running db:setup" bin/rake db:setup else # We don't have enough configuration to even check the database. return 1 fi } configure_version() { if [ -n "$WEB_SERVICE" ]; then SERVICE_MANAGER=$(guess_service_manager) elif WEB_SERVICE=$(list_services_systemd | grep -E '^(nginx|httpd)'); then SERVICE_MANAGER=systemd elif WEB_SERVICE=$(list_services_service \ | grep -Eo '\b(nginx|httpd)[^[:space:]]*'); then SERVICE_MANAGER=service fi if [ -z "$WEB_SERVICE" ]; then report_web_service_warning "Web service (Nginx or Apache) not found" elif [ "$WEB_SERVICE" != "$(echo "$WEB_SERVICE" | head -n 1)" ]; then WEB_SERVICE=$(echo "$WEB_SERVICE" | head -n 1) report_web_service_warning \ "Multiple web services found. Choosing the first one ($WEB_SERVICE)" fi case "$DISTRO_FAMILY" in debian) WWW_OWNER=www-data ;; rhel) case "$WEB_SERVICE" in httpd*) WWW_OWNER=apache ;; nginx*) WWW_OWNER=nginx ;; esac ;; esac # Before we do anything else, make sure some directories and files are in place if [ ! -e $SHARED_PATH/log ]; then mkdir -p $SHARED_PATH/log; fi if [ ! -e $RELEASE_PATH/tmp ]; then mkdir -p $RELEASE_PATH/tmp; fi if [ ! -e $RELEASE_PATH/log ]; then ln -s $SHARED_PATH/log $RELEASE_PATH/log; fi if [ ! -e $SHARED_PATH/log/production.log ]; then touch $SHARED_PATH/log/production.log; fi cd "$RELEASE_PATH" export RAILS_ENV=production run_and_report "Installing bundler" gem install --conservative --version '~> 2.4.0' bundler local ruby_minor_ver="$(ruby -e 'puts RUBY_VERSION.split(".")[..1].join(".")')" local bundle="$(gem contents --version '~> 2.4.0' bundler | grep -E '/(bin|exe)/bundle$' | tail -n1)" if ! [ -x "$bundle" ]; then # Some distros (at least Ubuntu 24.04) append the Ruby version to the # executable name, but that isn't reflected in the output of # `gem contents`. Check for that version. bundle="$bundle$ruby_minor_ver" if ! [ -x "$bundle" ]; then echo "Error: failed to find \`bundle\` command after installing bundler gem" >&2 return 1 fi fi local bundle_path="$SHARED_PATH/vendor_bundle" run_and_report "Running bundle config set --local path $SHARED_PATH/vendor_bundle" \ "$bundle" config set --local path "$bundle_path" # As of April 2024/Bundler 2.4, `bundle install` tends not to install gems # which are already installed system-wide, which causes bundle activation to # fail later. Work around this by installing all gems manually. find vendor/cache -maxdepth 1 -name '*.gem' -print0 \ | run_and_report "Installing bundle gems" xargs -0r \ gem install --conservative --ignore-dependencies --local --quiet \ --install-dir="$bundle_path/ruby/$ruby_minor_ver.0" run_and_report "Running bundle install" "$bundle" install --prefer-local --quiet run_and_report "Verifying bundle is complete" "$bundle" exec true if [ -z "$WWW_OWNER" ]; then NOT_READY_REASON="there is no web service account to own Arvados configuration" NOT_READY_DOC_URL="https://doc.arvados.org/install/nginx.html" else cat <&2 < After you do that, resume $PACKAGE_NAME setup by running: $RESETUP_CMD EOF fi