Skip to content

Instantly share code, notes, and snippets.

@johnpaulett
Created October 9, 2009 20:23
Show Gist options
  • Save johnpaulett/206346 to your computer and use it in GitHub Desktop.
Save johnpaulett/206346 to your computer and use it in GitHub Desktop.
Scripts to create a XNAT virtual machine http://nrg.wikispaces.com/XNAT+Virtual+Machine
#WINDOWS USERS: The '\' character is not supported by Maven. Do not use the '\' character in your file paths. Replace any '\' characters with the '/'. The '/' works as a file path separator on UNIX and WINDOWS.
maven.appserver.home=/home/xnat/tomcat/
#maven.appserver.home=/var/lib/tomcat6/
xdat.project.name=xnat
xdat.project.template=xnat
xdat.project.db.name=xnat
xdat.project.db.driver=org.postgresql.Driver
xdat.project.db.connection.string=jdbc:postgresql://localhost/xnat
xdat.project.db.user=xnat
xdat.project.db.password=xnat
#IMAGE FILE LOCATION (FOR USE WITH THE xnat TEMPLATE)
#Location where image data will be stored.
xdat.archive.location=/home/xnat/xnat_data/archive
#Location where image data may be stored temporarily before it is stored into the archive.
xdat.prearchive.location=/home/xnat/xnat_data/prearchive
#Location where cached image data should be stored
xdat.cache.location=/home/xnat/xnat_data/cache
#Location where thumbnails should be cached
xdat.project.image.thumbnail.location=/home/xnat/xnat_data/archive/cache/Thumbnails
#Location where Lo-Res images should be cached
xdat.project.image.lo_res.location=/home/xnat/xnat_data/archive/LoRes
xdat.smtp.server=localhost
[email protected]
xdat.url=http://localhost:8080/xnat
# 'xdat.require_login' must be set to 'true' or 'false'. It governs whether or not users will be
# prompted to login when visiting the site. If true, users will be required to login. If false,
# users will be automatically logged in using an XNAT guest account.
xdat.require_login=true
# 'xdat.enable_new_registrations' must be set to 'true' or 'false'. Users are provided with a
# link on the Login.vm page to register for a new account. If this variable is true, that newly
# registered account will be automatically enabled and the user will be allowed to immediately login.
# If this is false, then an email will be sent to the admin (xdat.admin_email) requesting that the
# account be enabled, and the user will be unable to login until the account is enabled.
xdat.enable_new_registrations=false
## Create a VirtualBox virtual machine.
##
## Allows access to XNAT via port 8080 of the host machine
##
## Currently requires manually clicking through the guest OS installation
##
## Requires 32-bit Ubuntu Desktop 9.04 ISO
##
## Tested on Ubuntu 9.04 guest and Ubuntu 9.04 host, VirtualBox (2.1.4 OSE)
##
## This script is run on the host machine.
##
## John Paulett (jpaulett _at_ wustl.edu)
# http://blog.arextech.net/index.php/tag/virtualbox/
VMNAME=xnat-demo
BASE_DIR=$HOMEvbox
DISTRO=ubuntu-9.04-desktop-i386.iso
HD=$BASE_DIR/$VMNAME/$VMNAME.vdi
VBoxManage createvm -name $VMNAME -ostype Ubuntu -register -basefolder $BASE_DIR
VBoxManage createhd -filename $HD -size 50000 -register #| awk '/UUID/ { print $5 }'
VBoxManage modifyvm $VMNAME -memory 512 -bioslogoimagepath $BASE_DIR/logo-xnat.bmp -hda $HD
## Port forward through VirtualBox's NAT to Tomcat
## http://mydebian.blogdns.org/?p=148
# SSH 8080 -> 8080
VBoxManage setextradata $VMNAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/HostPort" 8080
VBoxManage setextradata $VMNAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/GuestPort" 8080
VBoxManage setextradata $VMNAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/Protocol" TCP
## Setup the Ubuntu install CD
VBoxManage openmedium dvd $BASE_DIR/$DISTRO
VBoxManage modifyvm $VMNAME -dvd $BASE_DIR/$DISTRO
VBoxManage startvm $VMNAME
################################################################################
########################### Manual Step: Install OS ############################
################################################################################
VBoxManage controlvm $VMNAME poweroff
# wait for it to shutdown
VBoxManage modifyvm $VMNAME -dvd none
VBoxManage unregisterimage dvd $BASE_DIR/$DISTRO
## First Step Install
VBoxManage startvm $VMNAME
#VBoxManage getextradata xnat enumerate
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
configuration file for DicomServer, by [email protected]
</comment>
<entry key="arcspec">/home/xnat/xnat_data/cache/archive_specification.xml</entry>
<entry key="xnat_url">http://localhost:8080/xnat</entry>
<entry key="user">admin</entry>
<entry key="password">admin</entry>
<entry key="xnat_public_url">http://localhost:8080/xnat</entry>
<entry key="http_port">8180</entry>
<entry key="scp_public_host">localhost</entry>
<entry key="scp_public_port">8104</entry>
<entry key="sessions_url">http://localhost:8180/session</entry>
<entry key="project_spec">(0008,1030):Project:\s*(\w+)</entry>
<entry key="log4j.rootLogger">WARN,R</entry>
<entry key="log4j.appender.R">org.apache.log4j.RollingFileAppender</entry>
<entry key="log4j.appender.R.File">/home/xnat/xnat_data/dicom_log/DicomServer.log</entry>
<entry key="log4j.appender.R.MaxFileSize">100KB</entry>
<entry key="log4j.appender.R.MaxBackupIndex">4</entry>
<entry key="log4j.appender.R.layout">org.apache.log4j.PatternLayout</entry>
<entry key="log4j.appender.R.layout.ConversionPattern">%d %5p [%t] %c - %m%n</entry>
<entry key="log4j.logger.org.dcm4che2">WARN</entry>
<entry key="log4j.logger.org.nrg">INFO</entry>
<entry key="log4j.additivity.org.nrg.xnat.received">false</entry>
<entry key="log4j.logger.org.nrg.xnat.received">INFO,RECEIVED</entry>
<entry key="log4j.appender.RECEIVED">org.apache.log4j.DailyRollingFileAppender</entry>
<entry key="log4j.appender.RECEIVED.File">/home/xnat/xnat_data/dicom_log/DicomServer-received.log</entry>
<entry key="log4j.appender.RECEIVED.DatePattern">'.'yyyy-MM-dd</entry>
<entry key="log4j.appender.RECEIVED.layout">org.apache.log4j.PatternLayout</entry>
<entry key="log4j.appender.RECEIVED.layout.ConversionPattern">%d %m%n</entry>
</properties>
## Setup the Ubuntu Virtual Machine
##
## Currently the commands require some manual intervention (e.g. entering sudo
## password, rebooting), so this script can not be run as a single bash script.
##
## Tested on Ubuntu 9.04 guest and Ubuntu 9.04 host, VirtualBox (2.1.4 OSE)
## Tested on Ubuntu 9.10 guest and Ubuntu 9.10 host, VMWare Server (2.0.2)
## Tested on Ubuntu 9.10 guest and Ubuntu 9.10 host, VirtualBox (3.0.8 OSE)
## Tested on Ubuntu 9.10 guest and Ubuntu 9.10 host, VMWare Player (3.0.0)
##
## VMWare Specifics
## To ssh in
## ssh [email protected]
##
## Virtualbox Specifics
## To Open Ports:
## VBoxManage setextradata xnat-demo "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
## VBoxManage setextradata xnat-demo "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
## VBoxManage setextradata xnat-demo "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
## Which can then be used like
## ssh -p 2222 xnat@localhost
## The host has an IP of 10.0.2.2
##
## This script and the required supporting files are available at
## http://gist.github.com/gists/206346
## The script assumes that build.properties and DicomServer.xml have
## been downloaded to /home/xnat/
##
##
## John Paulett (jpaulett _at_ wustl.edu)
## VirtualBox Guest Additions for mouse integration, requires reboot
## Mount via menu with "Devices > Install guest additions".
#sudo /media/cdrom/VBoxLinuxAdditions-x86.run
#sudo reboot
## Upgrade
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade
## Install dependencies
sudo apt-get -y install openssh-server mercurial openjdk-6-jdk postgresql tomcat6 tomcat6-user postfix mailx ntp
## If installed from server install and you want a desktop
#sudo apt-get install ubuntu-desktop
## A few additional dependencies to make using XNAT with Ubuntu easier
sudo apt-get -y install icedtea6-plugin
## Clean the apt cache to save diskspace
sudo apt-get -y autoremove && sudo apt-get clean
## Modify configuration files
echo "localhost:*:xnat:xnat:xnat" >> ~/.pgpass
chmod 600 ~/.pgpass
echo "export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/" >> ~/.bashrc
source ~/.bashrc
## Setup database
sudo -u postgres createuser -D -A -R xnat
sudo -u postgres psql -c "ALTER USER xnat WITH PASSWORD 'xnat'"
## Remove primary Tomcat init script
## http://www.debuntu.org/how-to-manage-services-with-update-rc.d
sudo update-rc.d -f tomcat6 remove
## Reboot (to apply changes from upgrade)
sudo reboot
################################################################################
############################# Part 2: After Reboot #############################
################################################################################
## Install Tomcat local instance
cd ~
tomcat6-instance-create tomcat
## Get Tomcat to start on boot
CRONFILE=/tmp/xnat-cron
echo "JAVA_HOME=/usr/lib/jvm/java-6-openjdk/" > $CRONFILE
echo "@reboot /home/xnat/tomcat/bin/startup.sh" >> $CRONFILE
echo "@reboot cd /home/xnat/DicomServer && bin/arc-dcmstore start" >> $CRONFILE
crontab $CRONFILE
## Setup database
sudo -u postgres createdb -O xnat xnat
sudo -u postgres createlang plpgsql xnat
## Checkout code
hg clone http://bitbucket.org/nrg/xdat_release xnat
cd xnat/
REV=`hg log --rev tip --template "{latesttag} ({rev}:{node|short})"`
hg clone http://bitbucket.org/nrg/pipeline_1_4 pipeline
## Need build.properties (available at http://gist.github.com/gists/206346)
cp ~/build.properties ~/xnat
## Run the build
./bin/setup.sh -Ddeploy=true
psql -h localhost -U xnat -f deployments/xnat/sql/xnat.sql
cd deployments/xnat/
../../bin/StoreXML -location security/security.xml -allowDataDeletion true
cd ../..
## Customize the deployment
SITEVM=projects/xnat/src/templates/screens/site_description.vm
echo "<b>XNAT Virtual Machine Demo</b><br />" > $SITEVM
echo "Login: admin/admin<br />" >> $SITEVM
echo "HG Revision: $REV <br />" >> $SITEVM
bin/quick-deploy-templates.sh
## Install DicomServer
## http://nrg.wustl.edu/projects/DICOM/DicomServer-1.4RC3.html
cd ~
DICOMSERVER=DicomServer-xnat-1.4-r702
wget http://nrg.wustl.edu/projects/DICOM/$DICOMSERVER.tgz
tar xzvf $DICOMSERVER.tgz
mv DicomServer-xnat-1.4 DicomServer
rm $DICOMSERVER.tgz
## Need DicomServer.xml (available at http://gist.github.com/gists/206346)
mv DicomServer.xml DicomServer/etc/
## Optional: Install XNAT Desktop
cd ~
XNATDESKTOP=xnd_v0.92_linux_gtk_x86.zip
wget http://nrg.wustl.edu/xnd/download/$XNATDESKTOP
unzip $XNATDESKTOP
mv linux.gtk.x86/ xnd
chmod u+x xnd/xnd
rm $XNATDESKTOP
## Start tomcat (only need to do it once, cron will start on boot)
~/tomcat/bin/startup.sh
## Go to http://localhost:8080/xnat and configure
## wget http://nrg.wustl.edu/1.4/sample1.zip
## wget http://nrg.wustl.edu/1.4/sample2.zip
## When configuring the Dicom Server section of XNAT:
## DICOM host: localhost
## DICOM port: 8104
## DICOM AE Title: XNAT
## DICOM Server HTTP URL: http://localhost:8180/session
## Applet Link: true
## Start DicomServer
cd DicomServer
bin/arc-dcmstore start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment