Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database problems with startup and startup_lite #562

Open
bedroesb opened this issue Jul 30, 2020 · 17 comments
Open

Database problems with startup and startup_lite #562

bedroesb opened this issue Jul 30, 2020 · 17 comments

Comments

@bedroesb
Copy link

When I want to build a galaxy container with version 20.05 using especially startup_lite (both with quay.io/bgruening/galaxy and bgruening/galaxy):

#!/bin/bash

# install everything for workflow to work inside container

set -e
galaxy_instance="http://localhost:8080"

# launch the instance
echo "Starting Galaxy..."

export GALAXY_CONFIG_TOOL_PATH=/galaxy-central/tools/
startup_lite

I encounter this problem:

 * Starting PostgreSQL 11 database server
   ...done.
Checking if database is up and running
Traceback (most recent call last):
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context      
    cursor, statement, parameters, context
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedTable: relation "galaxy_user" does not exist
LINE 3: FROM galaxy_user
             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/check_database.py", line 25, in <module>
    query.count()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3669, in count
    return self.from_self(col).scalar()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3393, in scalar
    ret = self.one()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3360, in one
    ret = self.one_or_none()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3329, in one_or_none
    ret = list(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3405, in __iter__
    return self._execute_and_instances(context)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3430, in _execute_and_instances  
    result = conn.execute(querycontext.statement, self._params)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 984, in execute
    return meth(self, multiparams, params)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 293, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1103, in _execute_clauseelement
    distilled_params,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1288, in _execute_context
    e, statement, parameters, cursor, context
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1482, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "galaxy_user" does not exist
LINE 3: FROM galaxy_user
             ^

[SQL: SELECT count(*) AS count_1
FROM (SELECT galaxy_user.id AS galaxy_user_id, galaxy_user.create_time AS galaxy_user_create_time, galaxy_user.update_time AS galaxy_user_update_time, galaxy_user.email AS galaxy_user_email, galaxy_user.username AS galaxy_user_username, galaxy_user.password AS galaxy_user_password, galaxy_user.last_password_change AS galaxy_user_last_password_change, galaxy_user.external AS galaxy_user_external, galaxy_user.form_values_id AS galaxy_user_form_values_id, galaxy_user.deleted AS galaxy_user_deleted, galaxy_user.purged AS galaxy_user_purged, galaxy_user.disk_usage AS galaxy_user_disk_usage, galaxy_user.active AS galaxy_user_active, galaxy_user.activation_token AS galaxy_user_activation_token
FROM galaxy_user
WHERE galaxy_user.email = %(email_1)s) AS anon_1]
[parameters: {'email_1': '[email protected]'}]

This error message keeps repeating himself with Waiting for database.
I am not mounting anything in the export folder. Does somebody else encounter this problem or know what I do wrong?

@bedroesb
Copy link
Author

@bgruening I don't know if you have any idea about what might go wrong here?

@AndreasSko
Copy link
Collaborator

It looks like the Galaxy DB is not yet created, which the check_database.py is expecting. I think the DB will be created while Galaxy is starting for the first time (at least since 20.05). As a quick „fix“ I think you could try to change https://github.com/galaxyproject/ansible-galaxy-extras/blob/3c6fe3585aa3b82d22f74a1c3eb59afc1a2a49c0/templates/startup_lite.sh.j2#L42 with something like this

until nc -z -w 2 postgres 5432 && echo Postgres started; do
or just completely replace it with a long enough sleep 😄

@bedroesb
Copy link
Author

bedroesb commented Aug 3, 2020

Thank you for trying to help me! Sadly this did not work :/ Could my problem be related to the changes in this commit? @abretaud

@mvdbeek
Copy link
Contributor

mvdbeek commented Aug 3, 2020

@bedroesb I think Andreas' suggestion was to replace https://github.com/galaxyproject/ansible-galaxy-extras/blob/3c6fe3585aa3b82d22f74a1c3eb59afc1a2a49c0/templates/startup_lite.sh.j2#L42 with his suggestion. Did you do this, and if yes, what is the output you're seeing ?

@bedroesb
Copy link
Author

bedroesb commented Aug 3, 2020

@mvdbeek I misinterpreted the suggestion I think, so now I changed the line, changed .gitmodules to refer to my changed one, and tried to build it. I am unfamiliar with the build process of galaxy stable, and was wondering if I could use the github actions to generate a final galaxy stable image like it does here that I could use to test on? Or am I not looking at the right generated image on docker.io?

@mvdbeek
Copy link
Contributor

mvdbeek commented Aug 3, 2020

That looks correct, at first glance it looks like some of the tests failed because they couldn't mount the cvmfs shares, and maybe that's why the tests failed ? That shouldn't be related to the startup_lite changes.

@bedroesb
Copy link
Author

bedroesb commented Aug 3, 2020

The suggestion gives:

Waiting for database
/usr/bin/startup_lite: line 44: nc: command not found

@AndreasSko
Copy link
Collaborator

AndreasSko commented Aug 3, 2020

You might need to add a apt-get install netcat -y to your Dockerfile for it to work :)

@bedroesb
Copy link
Author

bedroesb commented Aug 3, 2020

ok step by step I will get there, now it is complaining about

Waiting for database
postgres: forward host lookup failed: Unknown host

off course still using in ansible-galaxy-extras:

until nc -z -w 2 postgres 5432 && echo Postgres started; do sleep 1; echo "Waiting for database"; done

and adapted docker file

My try out containers are being pushed at: https://hub.docker.com/repository/docker/bedroesb/galaxy-stable

Thank you for the help btw!

@AndreasSko
Copy link
Collaborator

AndreasSko commented Aug 4, 2020

So what the command does is to check if the host is available for requests at a given port. In the Docker Compose setup Postgres sits in another container (hostname postgres). As in galaxy-stable Postgres runs in the same container, you probably need to replace the hostname with something like 127.0.0.1 or localhost (so nc -z -w 2 127.0.0.1 5432...), though I personally didn‘t test it.

@bedroesb
Copy link
Author

bedroesb commented Aug 4, 2020

Ok this worked! This is great, I will open some PR with the changes. But for some reason I now stumble across the same problem as with 19.09 I described here #551, and that is that ephemeris is not available when I am building on top of this base image.

shed-tools: command not found
galaxy-wait: command not found

Funny things is, If I go into the container interactively, I do have ephemeris on my path available?

@bedroesb
Copy link
Author

bedroesb commented Aug 4, 2020

The script I run in the image built looks like this:

#!/bin/bash

# install everything for workflow to work inside container

set -e
galaxy_instance="http://localhost:8080"

# launch the instance
echo "Starting Galaxy..."

export GALAXY_CONFIG_TOOL_PATH=/galaxy-central/tools/
startup_lite

# wait until galaxy has started
galaxy-wait -g $galaxy_instance

# run install as user galaxy
su - $GALAXY_USER

# install workflow
echo " - Extracting tools from workflows"
for w in `ls /workflowDir/*.ga | sort -r`
do
    echo $w
    workflow-to-tools -w $w -o /workflowDir/wftools.yaml -l "Tools from workflows"
    echo " - Installing tools from workflow" 
    n=0
    until [ $n -ge 3 ]
    do
        shed-tools install -t /workflowDir/wftools.yaml -g $galaxy_instance -u $GALAXY_DEFAULT_ADMIN_USER -p $GALAXY_DEFAULT_ADMIN_PASSWORD && break
        n=$[$n+1]
        sleep 5
        echo " - Retrying shed-tools install "
    done    
    echo " - Installing workflow"
    workflow-install --publish_workflows --workflow_path $w -g $galaxy_instance -u $GALAXY_DEFAULT_ADMIN_USER -p $GALAXY_DEFAULT_ADMIN_PASSWORD
    
done

@bedroesb
Copy link
Author

bedroesb commented Aug 4, 2020

ok I solved it by adding GALAXY_CONDA_PREFIX=/tool_deps/_conda export PATH=$GALAXY_CONDA_PREFIX/bin/:$PATH to my build script, thanks to @ieguinoa
It is all working now. Thank you all very much

@bedroesb
Copy link
Author

bedroesb commented Aug 4, 2020

I have now sadly new problems:

When I run my image with galaxy-stable as base image, I have following error:

Starting postgres
postgresql: ERROR (spawn error)
Checking if database is up and running
Traceback (most recent call last):
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
    return fn()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 773, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
    rec = pool._do_get()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
    self._dec_overflow()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
    return self._create_connection()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 657, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 652, in __connect
    connection = pool._invoke_creator(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 490, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/galaxy_venv/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/bin/check_database.py", line 25, in <module>
    query.count()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3669, in count
    return self.from_self(col).scalar()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3393, in scalar
    ret = self.one()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3360, in one
    ret = self.one_or_none()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3329, in one_or_none
    ret = list(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3405, in __iter__
    return self._execute_and_instances(context)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3427, in _execute_and_instances
    querycontext, self._connection_from_session, close_with_result=True
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3442, in _get_bind_args
    mapper=self._bind_mapper(), clause=querycontext.statement, **kw
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3420, in _connection_from_session
    conn = self.session.connection(**kw)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 1133, in connection
    execution_options=execution_options,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 1142, in _connection_for_bind
    conn = engine._contextual_connect(**kw)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2251, in _contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2289, in _wrap_pool_connect
    e, dialect, self
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1555, in _handle_dbapi_exception_noconnection
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
    return fn()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 773, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
    rec = pool._do_get()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
    self._dec_overflow()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
    return self._create_connection()
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 657, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 652, in __connect
    connection = pool._invoke_creator(self)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/galaxy_venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 490, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/galaxy_venv/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
(Background on this error at: http://sqlalche.me/e/e3q8)

and when I use workflow-install --publish_workflows --workflow_path $w -g $galaxy_instance -a $GALAXY_CONFIG_MASTER_API_KEY i get:

Traceback (most recent call last):
  File "/export/tool_deps/_conda/bin/workflow-install", line 10, in <module>
    sys.exit(main())
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 48, in main
    import_workflow(gi, args.workflow_path, args.publish_workflows)
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 20, in import_workflow
    gi.workflows.import_workflow_from_local_path(path, publish=publish_wf)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 165, in import_workflow_from_local_path   
    return self.import_workflow_dict(workflow_json, publish)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 122, in import_workflow_dict
    return self._post(url=url, payload=payload)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/client.py", line 152, in _post
    files_attached=files_attached)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxyclient.py", line 159, in make_post_request
    body=r.text, status_code=r.status_code)
bioblend.ConnectionError: Unexpected HTTP status code: 500: {"err_msg": "Uncaught exception in exposed API method:", "err_code": 0}
Traceback (most recent call last):
  File "/export/tool_deps/_conda/bin/workflow-install", line 10, in <module>
    sys.exit(main())
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 48, in main
    import_workflow(gi, args.workflow_path, args.publish_workflows)
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 20, in import_workflow
    gi.workflows.import_workflow_from_local_path(path, publish=publish_wf)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 165, in import_workflow_from_local_path   
    return self.import_workflow_dict(workflow_json, publish)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 122, in import_workflow_dict
    return self._post(url=url, payload=payload)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/client.py", line 152, in _post
    files_attached=files_attached)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxyclient.py", line 159, in make_post_request
    body=r.text, status_code=r.status_code)
bioblend.ConnectionError: Unexpected HTTP status code: 500: {"err_msg": "Uncaught exception in exposed API method:", "err_code": 0}
Traceback (most recent call last):
  File "/export/tool_deps/_conda/bin/workflow-install", line 10, in <module>
    sys.exit(main())
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 48, in main
    import_workflow(gi, args.workflow_path, args.publish_workflows)
  File "/tool_deps/_conda/lib/python2.7/site-packages/ephemeris/workflow_install.py", line 20, in import_workflow
    gi.workflows.import_workflow_from_local_path(path, publish=publish_wf)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 165, in import_workflow_from_local_path   
    return self.import_workflow_dict(workflow_json, publish)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/workflows/__init__.py", line 122, in import_workflow_dict
    return self._post(url=url, payload=payload)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxy/client.py", line 152, in _post
    files_attached=files_attached)
  File "/tool_deps/_conda/lib/python2.7/site-packages/bioblend/galaxyclient.py", line 159, in make_post_request
    body=r.text, status_code=r.status_code)
bioblend.ConnectionError: Unexpected HTTP status code: 500: {"err_msg": "Uncaught exception in exposed API method:", "err_code": 0}

@bedroesb
Copy link
Author

bedroesb commented Aug 4, 2020

after also changing startup.sh.j2 in PR galaxyproject/ansible-galaxy-extras#244 :

Starting postgres
postgresql: ERROR (already started)
Checking if database is up and running
Waiting for database
Waiting for database
Waiting for database

@AndreasSko
Copy link
Collaborator

AndreasSko commented Aug 5, 2020

postgresql: ERROR (spawn error)

and

postgresql: ERROR (already started)

Seem a bit odd to me, I‘m not sure it has something to do with the change in the PR 🤔 Is Postgres already started from a different script or do you run it twice somehow? Maybe you could check if Postgres complains about something. Do you export the Postgres data? If so you could try to remove all data to have a clean start.

@bedroesb
Copy link
Author

bedroesb commented Aug 7, 2020

Ok I finally got a way of installing the workflows in a reliable way, and it even works on the current version of quay.io/bgruening/galaxy:20.05 ! I discovered that if you make use of the install_tools_wrapper.sh to install tools, there are not really problems. So I basically used the code in that wrapper to set up the database/galaxy :

#!/bin/bash

# Enable Test Tool Shed
echo "Enable installation from the Test Tool Shed."
export GALAXY_CONFIG_TOOL_SHEDS_CONFIG_FILE=$GALAXY_HOME/tool_sheds_conf.xml

. /tool_deps/_conda/etc/profile.d/conda.sh
conda activate base

if pgrep "supervisord" > /dev/null
then
    echo "System is up and running. Starting with the installation."
    export PORT=80
else
    # start Galaxy
    export PORT=8080
    service postgresql start
    install_log='galaxy_install.log'

    # wait for database to finish starting up
    STATUS=$(psql 2>&1)
    while [[ ${STATUS} =~ "starting up" ]]
    do
      echo "waiting for database: $STATUS"
      STATUS=$(psql 2>&1)
      sleep 1
    done

    echo "starting Galaxy"
    # Unset SUDO_* vars otherwise conda run chown based on that
    sudo -E -u galaxy -- bash -c "unset SUDO_UID; \
        unset SUDO_GID; \
        unset SUDO_COMMAND; \
        unset SUDO_USER; \
        ./run.sh -d $install_log --pidfile galaxy_install.pid --http-timeout 3000"

    galaxy_install_pid=`cat galaxy_install.pid`
    galaxy-wait -g http://localhost:$PORT -v --timeout 120
fi

# Create the admin user if not already done
# Starting with 20.05 this user is only created at first startup of galaxy
# We need to create it here for Galaxy Flavors = installing from Dockerfile
if [[ ! -z $GALAXY_DEFAULT_ADMIN_USER ]]
    then
        (
        cd $GALAXY_ROOT
        . $GALAXY_VIRTUAL_ENV/bin/activate
        echo "Creating admin user $GALAXY_DEFAULT_ADMIN_USER with key $GALAXY_DEFAULT_ADMIN_KEY and password $GALAXY_DEFAULT_ADMIN_PASSWORD if not existing"
        python /usr/local/bin/create_galaxy_user.py --user "$GALAXY_DEFAULT_ADMIN_EMAIL" --password "$GALAXY_DEFAULT_ADMIN_PASSWORD" \
        -c "$GALAXY_CONFIG_FILE" --username "$GALAXY_DEFAULT_ADMIN_USER" --key "$GALAXY_DEFAULT_ADMIN_KEY"
        )
fi

and this to close off the database/galaxy after installation of the tools/workflows/datalibraries using ephemeris:

if [ $exit_code != 0 ] ; then
    if [ "$2" == "-v" ] ; then
        echo "Installation failed, Galaxy server log:"
        cat $install_log
    fi
    exit $exit_code
fi

if ! pgrep "supervisord" > /dev/null
then
    # stop everything
    sudo -E -u galaxy ./run.sh --stop --pidfile galaxy_install.pid
    rm $install_log
    service postgresql stop
fi

And this gives almost no problems (besides sometimes an API HTTP connection error which appears randomly) and I managed to update the covid-19 workflow container to 20.05 with success.

I am now wondering, do I keep the subtle edits to startup_lite in my other PRs or do I close them and we forget about this way of installing things :) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants