Galaxy Server Install and Setup

Installing Galaxy on Scientific Linux 6

Galaxy is a platform for managing, running, and sharing computational biology data and pipelines. Its a big idea, and a good idea, but a bit of a task to get working exactly how you might want it.

What follows is a brain dump of the initial setup and configuration of this tool. Sorry about the length.

Goals for sever configuration

  • Follow all recommended settings for production level Galaxy server
  • Use Nginx proxy front-end
    • Enable as much of proxy components as possible
  • Use local postgreSQL server
  • Try to make these instructions as complete as possible

Future goals for follow up configuration include

  • Enable and configure as many of the tools as possible
  • Provide easy access to local directories of sequencing data inside Galaxy
  • Experiment with with Galaxy Toolshed
  • Experiment with cluster configurations

About the System

Scientific Linux release 6.1 (Carbon)

Will use separate galaxy user to run galaxy

Galaxy user’s home directory will be located:
/usr/local/galaxy

Resources

Most information comes from apapow.net

And the galaxy wikis Production Server page

Check base install

Ensure python is installed and at 2.6

which python
# /usr/bin/python
python --version
# Python 2.6.6

Ensure PostgreSQL is installed

sudo yum install postgresql postgresql-server

Modify PostgreSQL config file

Tricky part to getting postgreSQL working is the pg_hba.conf file. Edit it to allow local connections.

sudo vim /var/lib/pgsql/data/pg_hba.conf

A blog post explaining the syntax of this file . It should look something like:

local   all         all                               trust
host    all         all         127.0.0.1/32          trust
host    all         all         ::1/128               trust
host    all         all         0.0.0.0/0             md5

Startup PostgreSQL

sudo service postgresql initdb
sudo chkconfig postgresql on
sudo service postgresql start

Add galaxy user

Note

The galaxy user created here is not capable of using sudo. Every time sudo is used in this document, it is done from a sudo capable user.

Galaxy user’s home directory is at:
/usr/local/galaxy

This was done because /home is a remotely mounted disk.

sudo /usr/sbin/useradd galaxy --home /usr/local/galaxy
passwd galaxy

Install dependency packages

# install git just to have
sudo yum install git 
# install mercurial to download galaxy
sudo yum install mercurial

Install Galaxy

Switch to galaxy user

su galaxy
cd ~

Download galaxy

hg clone https://bitbucket.org/galaxy/galaxy-dist

Download virtualenv

wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py

Create sand-boxed Python using virtualenv

python ./virtualenv.py --no-site-packages galaxy_env
. ./galaxy_env/bin/activate
which python
# ~/galaxy_env/bin/python

Configure galaxy user

Edit ~/.bashrc to define TEMP and to add virtualenv source

source ~/galaxy_env/bin/activate

TEMP=$HOME/galaxy-dist/database/tmp 
export TEMP 

Ensure that ~/.bash_profile sources ~/.bashrc

# this should be in ~/.bash_profile
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

Setup PostgreSQL database for Galaxy

Login as postgres user

sudo su - postgres

Use createdb to create new database for galaxy

createdb galaxy_prod

Connect to database using psql

psql galaxy_prod

Create galaxy user for PostgreSQL database

CREATE USER galaxy WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE galaxy_prod to galaxy;
\q

Test galaxy PostgreSQL user.

Exit out of postgres user. Return to galaxy user and then attempt to connect to database.

exit
su galaxy
psql -d galaxy_prod -U galaxy

# Should get:
# psql (8.4.9)
# Type "help" for help.

\q

Edit Galaxy Config file

Copy sample config file to config file location

cd ~/galaxy-dist
cp universe_wsgi.ini.sample universe_wsgi.ini

Edit config file. For now we will allow connections from all network interfaces and connect to the postgres database.

Open universe_wsgi.ini in editor and modify these sections:

#host = 127.0.0.1
host = 0.0.0.0

#database_connection = sqlite:///./database/universe.sqlite?isolation_level=IMMEDIATE
database_connection = postgres://galaxy:password@localhost:5432/galaxy_prod

Test start Galaxy

Lets see if everything is up and running.

cd ~
# ensure local python env is activated
. ./galaxy_env/bin/activate
cd galaxy-dist
sh run.sh

Should update / fetch a bunch of python eggs (if this is your first time running run.sh). And then migrate a bunch of database tables. Then, you should be able to connect to your galaxy server on port 8080.

Create init script

Create this file at /etc/init.d/galaxy

Modified from This BioStar Post

#!/bin/bash

#--- config

SERVICE_NAME=galaxy
RUN_AS=galaxy
RUN_IN=/usr/local/galaxy/galaxy-dist

#--- main actions

start() {
        echo "Starting $SERVICE_NAME... "
        cmd="cd $RUN_IN && sh run.sh --daemon"
        case "$(id -un)" in
                $RUN_AS)
                        eval "$cmd"
                        ;;
                root)
                        su - $RUN_AS -c "$cmd"
                        ;;
                *)
                        echo "*** ERROR *** must be $RUN_AS or root in order to control this service" >&2
                        exit 1
        esac
        echo "...done."
}

stop() {
        echo -n "Stopping $SERVICE_NAME... "

        cmd="cd $RUN_IN && sh run.sh --stop-daemon"

        case "$(id -un)" in
                $RUN_AS)
                        eval "$cmd"
                        ;;
                root)
                        su - $RUN_AS -c "$cmd"
                        ;;
                *)
                        echo "*** ERROR *** must be $RUN_AS or root in order to control this service" >&2
                        exit 1
        esac

        echo "done."
}

status() {
        echo -n "$SERVICE_NAME status: "

        while read pid; do
                if [ "$(readlink -m /proc/$pid/cwd)" = "$(readlink -m $RUN_IN)" ]; then
                        echo "started"
                        return 0
                fi
        done < <(ps ax -o 'pid cmd' | grep -P '^\s*\d+ python ./scripts/paster.py serve' | awk '{print $1}')
        echo "stopped"
        return 3
}

notsupported() {
        echo "*** ERROR*** $SERVICE_NAME: operation [$1] not supported"
}

usage() {
        echo "Usage: $SERVICE_NAME start|stop|restart|status"
}


#---

case "$1" in
        start)
                start "$@"
                ;;
        stop)
                stop
                ;;
        restart|reload)
                stop
                start
                ;;
        status)
                set +e
                status
                exit $?
                ;;
        '')
                usage >&2
                exit 1
                ;;
        *)
                notsupported "$1" >&2
                usage >&2
                exit 1
                ;;
esac

Make it an executable and add it to system services

sudo chmod 755 /etc/init.d/galaxy
sudo /sbin/chkconfig --add galaxy

Install Nginx

Installing from source based on these articles:

But we also want to include the upload module, based on Galaxy documentation.

sudo yum install pcre-devel zlib-devel openssl-devel
wget http://nginx.org/download/nginx-1.0.10.tar.gz
tar xvf nginx-1.0.10.tar.gz
wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz
tar xvf nginx_upload_module-2.2.0.tar.gz
cd nginx-1.0.10
./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --add-module=../nginx_upload_module-2.2.0
make
sudo make install

Now to create init script

sudo vim /etc/init.d/nginx

Should look like:

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
sudo chmod 755 /etc/init.d/nginx
sudo /sbin/chkconfig nginx on
sudo /sbin/chkconfig --list nginx

Configure Nginx

Modify /usr/local/nginx/conf/nginx.conf to match content from Galaxys nginx page

user galaxy
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_proxied any;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml text/javascript application/json;
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6].(?!.*SV1)";

    upstream galaxy_app {
        server localhost:8080;
    }

    server {
        client_max_body_size 10G;
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://galaxy_app;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /static {
            alias /usr/local/galaxy/galaxy-dist/static;
        }
        location /static/style {
            alias /usr/local/galaxy/galaxy-dist/static/june_2007_style/blue;
        }
        location /static/scripts {
            alias /usr/local/galaxy/galaxy-dist/static/scripts/packed;
        }
        location /favicon.ico {
            alias /usr/local/galaxy/galaxy-dist/static/favicon.ico;
        }
        location /robots.txt {
            alias /usr/local/galaxy/galaxy-dist/static/robots.txt;
        }
        location /_x_accel_redirect/ {
            internal;
            alias /;
        }
        location /_upload {
            upload_store /usr/local/galaxy/galaxy-dist/database/tmp/upload_store;
            upload_pass_form_field "";
            upload_set_form_field "__${upload_field_name}__is_composite" "true";
            upload_set_form_field "__${upload_field_name}__keys" "name path";
            upload_set_form_field "${upload_field_name}_name" "$upload_file_name";
            upload_set_form_field "${upload_field_name}_path" "$upload_tmp_path";
            upload_pass_args on;
            upload_pass /_upload_done;
        }
        location /_upload_done {
            set $dst /tool_runner/index;
            if ($args ~ nginx_redir=([^&]+)) {
                set $dst $1;
            }
            rewrite "" $dst;
        }

      #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

More Galaxy Configuration

Due to Ngnix and reccomendations from the Galaxy wiki page, we one more go into the universe_wsgi.ini file.

debug = True
#debug = False

#use_interactive = True
use_interactive = False

#set_metadata_externally = False
set_metadata_externally = True

#database_engine_option_strategy = threadlocal
database_engine_option_strategy = threadlocal

#database_engine_option_server_side_cursors = False
database_engine_option_server_side_cursors = True

#nginx_x_accel_redirect_base = False
nginx_x_accel_redirect_base = /_x_accel_redirect

#upstream_gzip = False
upstream_gzip = True

#nginx_upload_store = False
nginx_upload_store = database/tmp/upload_store

#nginx_upload_path = False
nginx_upload_path = /_upload

NOTE

Galaxy documentation recommends debug = False. Setting that parameter currently causes an error the History panel of Galaxy. Hopefully a work around for this can be found and I will update this document.

Start up Galaxy and Nginx

Lets see if all this can work together

sudo /etc/init.d/galaxy start
sudo /etc/init.d/nginx start

Both should return back that they started ok.

Now navigating to your site on the default port 80 and you should see Galaxy.

Enabling Trackster

Follow the Instructions on the Galaxy Visualization Wiki page

It involves enabling enable_tracks in the universe_wsgi.ini file and then generating chromosome length files using a provided script.

Installing Galaxy tools

See my work in progress post on installing galaxy tools for more info.

blog comments powered by Disqus