Skip to content

Commit

Permalink
Singularity run command updated
Browse files Browse the repository at this point in the history
#3 to fix Singularity container run, we added a bash script and 'how to run' details on README.
  • Loading branch information
JD2112 committed Jul 31, 2023
1 parent 6981511 commit 87bd767
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 3 deletions.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <YOUR_LOCAL_PATH> 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 #<YOUR_USER_NAME>
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 <CONTAINER>
---------------------------------------------------------------------------
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
```

<Control>+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)**.
Expand Down
173 changes: 173 additions & 0 deletions prepare_template.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 87bd767

Please sign in to comment.