Raw File
npflow
#!/bin/bash
MYDIR=`dirname $0` && [ ! `echo "$0" | grep '^\/'` ] && MYDIR=`pwd`/$MYDIR

# INI/CONF file
INI_FILE=$MYDIR/etc/config.ini
CONF_FILE=$MYDIR/etc/npflow.conf

DEV=$(cat $INI_FILE | grep -E -E "^DEV *=" | cut -d'=' -f2 | tr -d "\n")

cp -f $INI_FILE $MYDIR/nmrviewer/www/etc/nmrview.conf
cp -f $INI_FILE $MYDIR/nmrspec/conf/global.ini

if [ $DEV -eq 1 ]; then
   DATADIR=$(cat $INI_FILE | grep DATASETS | cut -d'=' -f2 | tr -d "\n")
   HTTP_PORT=$(cat $INI_FILE | grep HTTP_PORT | cut -d'=' -f2 | tr -d "\n")
else
   DATADIR=$(cat $CONF_FILE | grep DATASETS | cut -d'=' -f2 | tr -d "\n")
   HTTP_PORT=$(cat $CONF_FILE | grep HTTP_PORT | cut -d'=' -f2 | tr -d "\n")
fi

mkdir -p $DATADIR/tmp/np && chmod 777 $DATADIR/tmp/np
mkdir -p $DATADIR/tmp/nv && chmod 777 $DATADIR/tmp/nv

# nmrspec Container
SPEC_PORT=$HTTP_PORT
SPEC_IMAGE=nmrprocflow/nmrprocflow:latest
SPEC_CONTAINER=npflow
SPEC_PAR="--env-file $MYDIR/etc/npflow.conf"
SPEC_SRC=''
SPEC_TMP="-v $DATADIR/tmp/np:/tmp -v $DATADIR/tmp/nv:/var/www/html/nv/tmp"

if [ $DEV -eq 1 ]; then
   SPEC_PAR=''
   SPEC_SRC="-v $MYDIR/nmrspec:/srv/shiny-server -v $MYDIR/nmrviewer/www:/var/www/html/nv"
fi

CMD=$1

# If you use a named volume, (assumes that your docker version >= 1.9)
# - First you have to create the /opt/data volume
# sudo docker create -v /opt/data --name npflow_data_volume ubuntu
# - Second, uncomment the line below, and
#   comment the line with 'VOLS' specified further with a local directory .
#VOLS="--volumes-from npflow_data_volume"

# If you use a local directory, first you have to create the /opt/data directory
VOLS="-v $DATADIR:/opt/data"

usage() { echo "usage: sh $0 start|stop|ps|restart|logs|update";  exit 1; }

case "$CMD" in
   start)
        # run NMRProcFlow
        sudo docker run -d $SPEC_PAR $VOLS $SPEC_SRC $SPEC_TMP -p $SPEC_PORT:80 --name $SPEC_CONTAINER $SPEC_IMAGE

        # show Logs
        sudo docker logs $SPEC_CONTAINER
        ;;
   stop)
        sudo docker rm -f $SPEC_CONTAINER
        ;;
   restart)
        ( sh $0 stop; sh $0 start)
        ;;
   logs)
        sudo docker logs $SPEC_CONTAINER
        ;;
   ps)
        sudo docker ps | head -1
        sudo docker ps | grep "nmrprocflow/"
        ;;
   build)
        ( rm -rf ./nmrviewer/www/tmp/_*; sudo docker build -t $SPEC_IMAGE . )
        ;;
   pull)
        sudo docker pull $SPEC_IMAGE
        ;;
   push)
        sudo docker push $SPEC_IMAGE
        ;;
   clean)
        ( rm -rf /opt/data/_*; rm -rf $DATADIR/tmp/np/Rtmp*; rm -rf /tmp/_*; rm -rf $DATADIR/tmp/nv/_* )
        ;;
   *) usage
      exit 2
esac
back to top