33# SPDX-FileCopyrightText: 2021 Omar AbdelSamea <omarmohamed168@gmail.com>
44# SPDX-License-Identifier: GPL-2.0
55#
6- # Description: startup helper script for the FOSSology Docker container in kuberentes
6+ # Description: startup helper script for the FOSSology Docker container in Kubernetes
7+ # Set database environment variables (override Db.conf if needed)
8+ export FOSSOLOGY_DB_HOST=db
9+ export FOSSOLOGY_DB_NAME=fossology
10+ export FOSSOLOGY_DB_USER=fossy
11+ export FOSSOLOGY_DB_PASSWORD=fossy
712
813set -o errexit -o nounset -o pipefail
914
10- sed -i ' s/address = .*/address = ' " ${FOSSOLOGY_SCHEDULER_HOST:- scheduler} " ' /' \
11- /etc/fossology/fossology.conf
12-
13- # Startup DB if needed or wait for external DB
14- if [[ " $1 " == " scheduler" ]]; then
15- echo ' *****************************************************'
16- echo ' WARNING: No database host was set and therefore the'
17- echo ' internal database without persistency will be used.'
18- echo ' THIS IS NOT RECOMENDED FOR PRODUCTIVE USE!'
19- echo ' *****************************************************'
20- bash ./fo_conf.sh db
21- sleep 10
22- /etc/init.d/postgresql start
23- else
15+ # update fossology.conf with scheduler and database host
16+ sed -i ' s/address = .*/address = ' " ${FOSSOLOGY_SCHEDULER_HOST:- scheduler} " ' /' /etc/fossology/fossology.conf
17+ sed -i ' /\[FOSSOLOGY\]/a DB_HOST=db' /etc/fossology/fossology.conf
18+ # wait for external database (skip for web container)
19+ if [[ " $1 " != " web" ]]; then
2420 test_for_postgres () {
25- PGPASSWORD=$db_password psql -h " $db_host " " $db_name " " $db_user " -c ' \l' > /dev/null
21+ PGPASSWORD=$FOSSOLOGY_DB_PASSWORD psql -h " $FOSSOLOGY_DB_HOST " " $FOSSOLOGY_DB_NAME " " $FOSSOLOGY_DB_USER " -c ' \l' > /dev/null 2>&1
2622 return $?
2723 }
2824 until test_for_postgres; do
@@ -37,31 +33,31 @@ if [[ $# -eq 0 || ($# -eq 1 && "$1" == "scheduler") ]]; then
3733 bash ./fo_conf.sh scheduler
3834fi
3935
40- # Start Fossology
36+ # start Fossology
4137echo
4238echo ' Fossology initialisation complete; Starting up...'
4339echo
4440if [[ $# -eq 0 ]]; then
4541 /etc/init.d/cron start
46- /etc/fossology/mods-enabled/scheduler/agent/fo_scheduler \
47- --log /dev/stdout \
48- --verbose=4095 \
49- --reset &
42+ /etc/fossology/mods-enabled/scheduler/agent/fo_scheduler --log /dev/stdout --verbose=4095 --reset &
5043 /usr/sbin/apache2ctl -D FOREGROUND
5144elif [[ $# -eq 1 && " $1 " == " scheduler" ]]; then
52- exec /etc/fossology/mods-enabled/scheduler/agent/fo_scheduler \
53- --log /dev/stdout \
54- --verbose=4095 \
55- --reset
45+ exec /etc/fossology/mods-enabled/scheduler/agent/fo_scheduler --log /dev/stdout --verbose=4095 --reset
5646elif [[ $# -eq 1 && " $1 " == " web" ]]; then
47+ # configure Apache for FOSSology
48+ sed -i ' s/DocumentRoot \/var\/www\/html/DocumentRoot \/usr\/share\/fossology\/www\/ui/' /etc/apache2/sites-available/000-default.conf
49+ a2dissite 000-default.conf
50+ a2ensite 000-default.conf
51+ sed -i ' /<Directory \/var\/www\/html>/,/<\/Directory>/ s/DirectoryIndex.*/DirectoryIndex index.php index.html/' /etc/apache2/mods-available/dir.conf
52+ a2enmod dir
53+ a2enmod php7.3
5754 service cron start
5855 exec /usr/sbin/apache2ctl -e info -D FOREGROUND
5956elif [[ $# -ge 1 && " $1 " == " agent" ]]; then
6057 bash ./fo_conf.sh agent $2
6158 chmod +x /usr/share/fossology/scheduler/agent/fo_cli
62- /usr/share/fossology/scheduler/agent/fo_cli --host=${FOSSOLOGY_SCHEDULER_HOST:- scheduler} \
63- --port=24693 --reload || echo " Scheduler is initlaizing or not running"
59+ /usr/share/fossology/scheduler/agent/fo_cli --host=${FOSSOLOGY_SCHEDULER_HOST:- scheduler} --port=24693 --reload || echo " Scheduler is initializing or not running"
6460 exec tail -f /dev/null
6561else
6662 exec " $@ "
67- fi
63+ fi
0 commit comments