docker-entrypoint.sh 2.31 KB
Newer Older
1 2 3
#!/bin/bash
# FOSSology docker-entrypoint script
# Copyright Siemens AG 2016, fabio.huser@siemens.com
4
# Copyright TNG Technology Consulting GmbH 2016, maximilian.huber@tngtech.com
5 6 7 8 9 10 11 12
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.
#
# Description: startup helper script for the FOSSology Docker container

13
set -o errexit -o nounset -o pipefail
14

15 16 17 18
db_host="${FOSSOLOGY_DB_HOST:-localhost}"
db_name="${FOSSOLOGY_DB_NAME:-fossology}"
db_user="${FOSSOLOGY_DB_USER:-fossy}"
db_password="${FOSSOLOGY_DB_PASSWORD:-fossy}"
19 20 21 22 23 24 25 26 27

# Write configuration
cat <<EOM > /usr/local/etc/fossology/Db.conf
dbname=$db_name;
host=$db_host;
user=$db_user;
password=$db_password;
EOM

28 29 30
sed -i 's/address = .*/address = '"${FOSSOLOGY_SCHEDULER_HOST:-localhost}"'/' \
    /usr/local/etc/fossology/fossology.conf

31
# Startup DB if needed or wait for external DB
32
if [[ $db_host == 'localhost' ]]; then
33 34 35 36 37
  echo '*****************************************************'
  echo 'WARNING: No database host was set and therefore the'
  echo 'internal database without persistency will be used.'
  echo 'THIS IS NOT RECOMENDED FOR PRODUCTIVE USE!'
  echo '*****************************************************'
38
  sleep 5
39
  /etc/init.d/postgresql start
40
else
41
  test_for_postgres() {
42 43 44
    PGPASSWORD=$db_password psql -h "$db_host" "$db_name" "$db_user" -c '\l' >/dev/null
    return $?
  }
45
  until test_for_postgres; do
46 47 48
    >&2 echo "Postgres is unavailable - sleeping"
    sleep 1
  done
49 50 51
fi

# Setup environment
52
if [[ $# -eq 0 || ($# -eq 1 && "$1" == "scheduler") ]]; then
53
  /usr/local/lib/fossology/fo-postinstall --common --database --licenseref
54
fi
55 56 57 58 59

# Start Fossology
echo
echo 'Fossology initialisation complete; Starting up...'
echo
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
if [[ $# -eq 0 ]]; then
  /etc/init.d/fossology start
  /usr/local/share/fossology/scheduler/agent/fo_scheduler \
    --log /dev/stdout \
    --verbose=3 \
    --reset &
  /usr/sbin/apache2ctl -D FOREGROUND
elif [[ $# -eq 1 && "$1" == "scheduler" ]]; then
  exec /usr/local/share/fossology/scheduler/agent/fo_scheduler \
    --log /dev/stdout \
    --verbose=3 \
    --reset
elif [[ $# -eq 1 && "$1" == "web" ]]; then
  exec /usr/sbin/apache2ctl -e info -D FOREGROUND
else
  exec "$@"
fi