Skip to content

Instantly share code, notes, and snippets.

@dgutman
Last active December 14, 2015 08:48
Show Gist options
  • Save dgutman/5059929 to your computer and use it in GitHub Desktop.
Save dgutman/5059929 to your computer and use it in GitHub Desktop.
XNAT Ubuntu Install Script for 12.04 LTS
## David A Gutman dgutman _at_ emory.edu
## This script walks through install an XNAT Ubuntu Virtual Machine for a VMware Host
## Note: this script can not be run as a single bash script.
# This is a fork/update of johnpaulett's guest setup script
# https://gist.github.com/johnpaulett/206346
## VMWARE Setup: I allocated 80GB for the main XNAT partition (using Thin Provisioning)
## Also I set up an additional disk as a standalone partition to actually store all my data
## Presumably you do not want to have your VM image with your database/XNAT/etc in the same VM as
## storage
## This assumes a basic Ubuntu 12.04 LTS image has been already set up, and an IP Address and hostname have been generated
## When I first created me VM I used my user ID; after logging on for the first time I created an 'xnat' user
sudo adduser xnat ## enter default password you want for xnat...
sudo usermod -G sudo xnat ## add xnat user to sudo...
## If you installed 12.04 LTS Server andwant a desktop
#sudo apt-get install ubuntu-desktop
## then logout and log back in as xnat user
############# Make sure latest packages are installed and install vm tools ####
sudo apt-get update && sudo apt-get -y dist-upgrade
## rebooted to update to the latest kernel
#sudo reboot
sudo apt-get install open-vm-tools
## I created a separate partition where I will place all my main xnat images and archives
## I do not want to include the data in the same VM/snapshot as the XNAT database so I can keep them separated
## I am using nfs and mounting the partition from another machine
# I created an ext4 partition on /dev/sdb1
## I edited the /etc/fstab file and added the following line
### /dev/sdb1 /Library ext4 defaults,nobootwait 0 1
## the /dev/sdb1 would vary depending on how the extra storage is located and if it's NFS or local disk, etc...
sudo nano /etc/fstab # add line from above
sudo mkdir /Library
sudo mount -a
sudo chown xnat:xnat /Library ##otherwise xnat user can't read/write files to this location
df #run "df" to see if /dev/sdb1 actually mounted..
##### INSTALL DEPENDENCIES FOR XNAT ##################
#### Current list of prerequisites are listed here https://wiki.xnat.org/display/XNAT16/Prerequisites
## Install dependencies
## first add the PPA that adds the Oracle Java SDK
sudo apt-get purge openjdk* ##good not to have multiple java versinos
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
############# Setup database user (xnat) and also a database #####
sudo -u postgres createuser -S -D -R -P xnat
## will prompt you for password-- WRITE IT DOWN!!!
sudo -u postgres createdb -O xnat xnat
## Modify configuration files --- I set these up before tomcat and other package installs
# to make sure everything uses the same version fo java
echo "localhost:*:xnat:xnat:xnat" >> ~/.pgpass
chmod 600 ~/.pgpass
echo "export JAVA_HOME=/usr/lib/jvm/java-7-oracle/" >> ~/.bashrc
echo "export XNAT_HOME=/home/xnat/xnat/" >> ~/.bashrc
echo "export XDAT_HOME=/home/xnat/xnat/" >> ~/.bashrc
echo "export TOMCAT_HOME=/home/xnat/tomcat/" >> ~/.bashrc
echo "PATH=$PATH:$XNAT_HOME/bin" >> ~/.bashrc
#### NEED TO CLARIFY IF XDAT_HOME OR XNAT_HOME is the environment variable
source ~/.bashrc
sudo apt-get -y install openssh-server mercurial postgresql tomcat7 tomcat7-user postfix mailutils ntp nfs-common
##I set up postfix using a smarthost and provided the smtp server my university uses
## Clean the apt cache to save diskspace
sudo apt-get -y autoremove && sudo apt-get clean
##################### SET UP TOMCAT ################
## Remove primary Tomcat init script
## http://www.debuntu.org/how-to-manage-services-with-update-rc.d
sudo update-rc.d -f tomcat7 remove
## Install Tomcat local instance
cd ~
tomcat7-instance-create tomcat
## Get Tomcat to start on boot ##### NOT WORKING NEED TO FIX #######
CRONFILE=/tmp/xnat-cron
echo "export JAVA_HOME=/usr/lib/jvm/java-7-oracle/" > $CRONFILE
echo "@reboot /home/xnat/tomcat/bin/startup.sh" >> $CRONFILE
crontab $CRONFILE
^^^^ NOT WORKING!!! ^^^
#### Now that the DB is setup and I added environment variables, I can try and install xnat proper #####
### Download the lateset XNAT version ...http://www.xnat.org/download-xnat.html ###
# can get the latest version i.e. ftp://ftp.nrg.wustl.edu/pub/xnat/xnat_1_6_1.tar.gz after reading license
#wget ftp://ftp.nrg.wustl.edu/pub/xnat/xnat_1_6_1.tar.gz
#OR you can install from source and follow the instructions from here...
#https://wiki.xnat.org/display/XNAT16/Build+XNAT+from+Source+Repository
# Checkout code (mercurial must be installed as per above)
hg clone http://hg.xnat.org/xnat_builder_1_6dev xnat
# also get pipeline manager
cd xnat
hg clone http://hg.xnat.org/pipeline_1_6dev pipeline
############## CONFIGURE XNAT for your system setup #############
#Property information is located at:
#https://wiki.xnat.org/display/XNAT16/XNAT+1.6+Installation+Guide
#Build.properties is located in ~/xnat/build.properties.sample
cd ~/xnat
cp build.properties.sample build.properties
#Edit build.properties with your favorite editor, vim, nano, gedit, etc
#Don't forget to edit the maven.appserver.home--- I missed this one the first time and the URL
## Run the build
./bin/setup.sh
psql -h localhost -U xnat -d xnat_db -f deployments/xnat/sql/xnat.sql
cd deployments/xnat/
StoreXML -location security/security.xml -allowDataDeletion true
cd ../..
#The setup script (step 4) created a WAR file in XNAT_HOME/deployments/PROJECT_NAME/target/.
#This WAR file can be copied to the #webapps directory of your Tomcat server, and will be deployed when the server starts up.
# also can
#cd to ~/xnat
bin/update.sh -Ddeploy=true
### BELOW IS OPTIONAL BUT IS HOW You would customize your site
## Customize the deployment
SITEVM=projects/xnat/src/templates/screens/site_description.vm
echo "<b>XNAT Virtual Machine Demo</b><br />" > $SITEVM
bin/quick-deploy-templates.sh
## Start tomcat (only need to do it once, cron will start on boot)
~/tomcat/bin/startup.sh
## default user id is admin/admin and you can configure things the first time you conenct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment