diff --git a/README.md b/README.md index 5132e35..61b5a29 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,6 @@ We provide Docker container for local use. Please note, the docker container was ``` # with docker container docker run --rm -p 3838:3838 jd21/methylr:latest - -# with singularity container -singularity run docker://jd21/methylr:latest ``` ##### Step:2 - web-browser @@ -90,6 +87,57 @@ Open the web-browser (check above for your OS), and type: http://localhost:3838 ``` +**For Singularity container** +Thanks to WiilieYu (https://github.com/JD2112/methylr/issues/3), we found a problem on running Singularity/Apptainer container on methylR and using a script from [sigularity-shiny](https://github.com/vsoch/singularity-shiny), we solved the issue. Please run the commands below for Singularity container (tested with Singularity v3.8.6) - + +1. To run the [Singularity](https://docs.sylabs.io/guides/latest/user-guide/) or [Apptainer](https://apptainer.org/docs/user/main/index.html), please use the following commandlines - + +``` +# Copy prepare_template.sh to and run +/bin/bash prepare_template.sh start +``` +The above command run will generate an script on the terminal and command to run on the server, + +``` +$ /bin/bash prepare_template.sh start +Generating shiny configuration... +port: 15910 # PLEASE NOTE THIS WILL BE CHANGED IN YOUR COMPUTER +logs: /tmp/shiny-server.ie3djR +base: /srv/shiny-server +run_as: jyotirmoy # +Server logging will be in /tmp/shiny-server.ie3djR + +To run your server: + + singularity run --bind /tmp/shiny-server.ie3djR/logs:/var/log/shiny \ + --bind /tmp/shiny-server.ie3djR/lib:/var/lib/shiny-server \ + --bind shiny-server.conf:/etc/shiny-server/shiny-server.conf + + --------------------------------------------------------------------------- + For custom applications, also add --bind /srv/shiny-server:/srv/shiny-server + To see your applications, open your browser to http://127.0.0.1:15910 or + open a ssh connection from your computer to your cluster. +``` + +2. Run the following command on your server + +``` +singularity run --bind /tmp/shiny-server.ie3djR/logs:/var/log/shiny \ + --bind /tmp/shiny-server.ie3djR/lib:/var/lib/shiny-server \ + --bind shiny-server.conf:/etc/shiny-server/shiny-server.conf docker://jd21/methylr:latest +``` + +3. The terminal will prompt likes +``` +INFO: Using cached SIF image +INFO: Converting SIF file to temporary sandbox... +[2023-07-31T06:44:52.258] [INFO] shiny-server - Shiny Server v1.5.18.979 (Node.js v12.22.6) +[2023-07-31T06:44:52.259] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf" +[2023-07-31T06:44:52.285] [INFO] shiny-server - Starting listener on http://[::]:15910 +``` + ++click or run `localhost:15910` on the browser. + #### MacOS (Intel) and Windows AMD64 OS architecture **Please follow the [manual](https://methylr.netlify.app/dockercontainer.html)**. diff --git a/prepare_template.sh b/prepare_template.sh new file mode 100644 index 0000000..bec533f --- /dev/null +++ b/prepare_template.sh @@ -0,0 +1,173 @@ +#!/bin/bash + +# Thanks to https://github.com/vsoch/singularity-shiny + +usage () { + + echo "Steps: + ---------------------------------------------------------------------- + 1. Use this script to prepare your shiny-server.conf (configuration) + + /bin/bash prepare_template.sh + + ---------------------------------------------------------------------- + 2. If needed, you can provide the following arguments + + Commands: + help: show help and exit + start: the generation of your config + + Options: + --port: the port for the application (e.g., shiny default is 3737) + --user: the user for the run_as directive in the shiny configuration + --base: base folder with applications + --logs: temporary folder with write for logs (not required) + --disable-index: disable directory indexing + + ---------------------------------------------------------------------- + 3. Make sure Singularity is loaded, and run the container using + the commands shown by the template. + + " +} + +# Start the application +SHINY_START="no"; + +# Port for Flask +CHECK_PORT="notnull" +while [[ ! -z $CHECK_PORT ]]; do + SHINY_PORT=$(( ( RANDOM % 60000 ) + 1025 )) + CHECK_PORT=$(netstat -atn | grep $SHINY_PORT) +done + +# Base for apps +SHINY_BASE=/srv/shiny-server; + +# Log folder assumed to be bound to +SHINY_LOGS=$(mktemp -d /tmp/shiny-server.XXXXXX) && rmdir ${SHINY_LOGS}; + +# Disable indexing (on, default, is not disabled) +DISABLE_DIRINDEX="on"; + +# User to run_as, defaults to docker +SHINY_USER="${USER}" + +if [ $# -eq 0 ]; then + usage + exit +fi + +while true; do + case ${1:-} in + -h|--help|help) + usage + exit + ;; + -s|--start|start) + SHINY_START="yes" + shift + ;; + -p|--port|port) + shift + SHINY_PORT="${1:-}" + shift + ;; + -b|--base|base) + shift + SHINY_BASE="${1:-}" + shift + ;; + -u|--user) + shift + SHINY_USER="${1:-}" + shift + ;; + -di|--disable-index|disable-index) + DISABLE_DIRINDEX="off" + shift + ;; + -l|logs|--logs) + shift + SHINY_LOGS="${1:-}" + shift + ;; + -*) + echo "Unknown option: ${1:-}" + exit 1 + ;; + *) + break + ;; + esac +done + +# Functions + +function prepare_conf() { + SHINY_PORT=$1 + SHINY_BASE=$2 + SHINY_LOGS=$3 + DISABLE_DIRINDEX=$4 + SHINY_USER=$5 + CONFIG="run_as ${SHINY_USER}; +server { + listen ${SHINY_PORT}; + + # Define a location at the base URL + location / { + + # Host the directory of Shiny Apps stored in this directory + site_dir ${SHINY_BASE}; + + # Log all Shiny output to files in this directory + log_dir ${SHINY_LOGS}; + + # When a user visits the base URL rather than a particular application, + # an index of the applications available in this directory will be shown. + directory_index ${DISABLE_DIRINDEX}; + } +}" + echo "${CONFIG}"; +} + + +# Are we starting the server? + +if [ "${SHINY_START}" == "yes" ]; then + + echo "Generating shiny configuration..."; + echo "port: ${SHINY_PORT}"; + echo "logs:" ${SHINY_LOGS}; + echo "base: ${SHINY_BASE}"; + echo "run_as: ${SHINY_USER}"; + + # Prepare the template + + CONFIG=$(prepare_conf $SHINY_PORT $SHINY_BASE $SHINY_LOGS $DISABLE_DIRINDEX $SHINY_USER); + + # Temporary directories, if don't exist + mkdir -p "${SHINY_LOGS}"; + mkdir -p ${SHINY_LOGS}/logs; + mkdir -p ${SHINY_LOGS}/lib; + + # Configuration file + echo "${CONFIG}" > "shiny-server.conf"; + echo "Server logging will be in ${SHINY_LOGS}"; + echo + echo "To run your server: + + module load singularity + singularity run --bind $SHINY_LOGS/logs:/var/log/shiny \\ + --bind $SHINY_LOGS/lib:/var/lib/shiny-server \\ + --bind shiny-server.conf:/etc/shiny-server/shiny-server.conf shiny.simg + + --------------------------------------------------------------------------- + For custom applications, also add --bind $SHINY_BASE:/srv/shiny-server + To see your applications, open your browser to http://127.0.0.1:$SHINY_PORT or + open a ssh connection from your computer to your cluster. +" + exit +else + usage +fi \ No newline at end of file