#!/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 DATABASE_READY=1 APPLICATION_READY=1 report_not_ready() { local ready_flag="$1"; shift local config_file="$1"; shift if [ "1" != "$ready_flag" ]; then cat >&2 < for more details. When $(basename "$config_file") has been modified, reconfigure or reinstall this package. EOF fi } 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 if ! run_and_report "Running db:setup" \ bin/rake db:setup 2>/dev/null; then echo "Warning: unable to set up database." >&2 DATABASE_READY=0 fi else echo "Warning: Database is not ready to set up. Skipping database setup." >&2 DATABASE_READY=0 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 if [ -e /etc/redhat-release ]; then case "$WEB_SERVICE" in "") ;; nginx*) WWW_OWNER=nginx ;; *) WWW_OWNER=apache ;; esac else # Assume we're on a Debian-based system for now. # Both Apache and Nginx run as www-data by default. WWW_OWNER=www-data fi # 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 [ -n "$WWW_OWNER" ]; then cat <