Skip to content

Commit 87bd767

Browse files
committed
Singularity run command updated
#3 to fix Singularity container run, we added a bash script and 'how to run' details on README.
1 parent 6981511 commit 87bd767

File tree

2 files changed

+224
-3
lines changed

2 files changed

+224
-3
lines changed

README.md

+51-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ We provide Docker container for local use. Please note, the docker container was
7979
```
8080
# with docker container
8181
docker run --rm -p 3838:3838 jd21/methylr:latest
82-
83-
# with singularity container
84-
singularity run docker://jd21/methylr:latest
8582
```
8683

8784
##### Step:2 - web-browser
@@ -90,6 +87,57 @@ Open the web-browser (check above for your OS), and type:
9087
http://localhost:3838
9188
```
9289

90+
**For Singularity container**
91+
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) -
92+
93+
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 -
94+
95+
```
96+
# Copy prepare_template.sh to <YOUR_LOCAL_PATH> and run
97+
/bin/bash prepare_template.sh start
98+
```
99+
The above command run will generate an script on the terminal and command to run on the server,
100+
101+
```
102+
$ /bin/bash prepare_template.sh start
103+
Generating shiny configuration...
104+
port: 15910 # PLEASE NOTE THIS WILL BE CHANGED IN YOUR COMPUTER
105+
logs: /tmp/shiny-server.ie3djR
106+
base: /srv/shiny-server
107+
run_as: jyotirmoy #<YOUR_USER_NAME>
108+
Server logging will be in /tmp/shiny-server.ie3djR
109+
110+
To run your server:
111+
112+
singularity run --bind /tmp/shiny-server.ie3djR/logs:/var/log/shiny \
113+
--bind /tmp/shiny-server.ie3djR/lib:/var/lib/shiny-server \
114+
--bind shiny-server.conf:/etc/shiny-server/shiny-server.conf <CONTAINER>
115+
116+
---------------------------------------------------------------------------
117+
For custom applications, also add --bind /srv/shiny-server:/srv/shiny-server
118+
To see your applications, open your browser to http://127.0.0.1:15910 or
119+
open a ssh connection from your computer to your cluster.
120+
```
121+
122+
2. Run the following command on your server
123+
124+
```
125+
singularity run --bind /tmp/shiny-server.ie3djR/logs:/var/log/shiny \
126+
--bind /tmp/shiny-server.ie3djR/lib:/var/lib/shiny-server \
127+
--bind shiny-server.conf:/etc/shiny-server/shiny-server.conf docker://jd21/methylr:latest
128+
```
129+
130+
3. The terminal will prompt likes
131+
```
132+
INFO: Using cached SIF image
133+
INFO: Converting SIF file to temporary sandbox...
134+
[2023-07-31T06:44:52.258] [INFO] shiny-server - Shiny Server v1.5.18.979 (Node.js v12.22.6)
135+
[2023-07-31T06:44:52.259] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
136+
[2023-07-31T06:44:52.285] [INFO] shiny-server - Starting listener on http://[::]:15910
137+
```
138+
139+
<Control>+click or run `localhost:15910` on the browser.
140+
93141

94142
#### MacOS (Intel) and Windows AMD64 OS architecture
95143
**Please follow the [manual](https://methylr.netlify.app/dockercontainer.html)**.

prepare_template.sh

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/bin/bash
2+
3+
# Thanks to https://github.com/vsoch/singularity-shiny
4+
5+
usage () {
6+
7+
echo "Steps:
8+
----------------------------------------------------------------------
9+
1. Use this script to prepare your shiny-server.conf (configuration)
10+
11+
/bin/bash prepare_template.sh
12+
13+
----------------------------------------------------------------------
14+
2. If needed, you can provide the following arguments
15+
16+
Commands:
17+
help: show help and exit
18+
start: the generation of your config
19+
20+
Options:
21+
--port: the port for the application (e.g., shiny default is 3737)
22+
--user: the user for the run_as directive in the shiny configuration
23+
--base: base folder with applications
24+
--logs: temporary folder with write for logs (not required)
25+
--disable-index: disable directory indexing
26+
27+
----------------------------------------------------------------------
28+
3. Make sure Singularity is loaded, and run the container using
29+
the commands shown by the template.
30+
31+
"
32+
}
33+
34+
# Start the application
35+
SHINY_START="no";
36+
37+
# Port for Flask
38+
CHECK_PORT="notnull"
39+
while [[ ! -z $CHECK_PORT ]]; do
40+
SHINY_PORT=$(( ( RANDOM % 60000 ) + 1025 ))
41+
CHECK_PORT=$(netstat -atn | grep $SHINY_PORT)
42+
done
43+
44+
# Base for apps
45+
SHINY_BASE=/srv/shiny-server;
46+
47+
# Log folder assumed to be bound to
48+
SHINY_LOGS=$(mktemp -d /tmp/shiny-server.XXXXXX) && rmdir ${SHINY_LOGS};
49+
50+
# Disable indexing (on, default, is not disabled)
51+
DISABLE_DIRINDEX="on";
52+
53+
# User to run_as, defaults to docker
54+
SHINY_USER="${USER}"
55+
56+
if [ $# -eq 0 ]; then
57+
usage
58+
exit
59+
fi
60+
61+
while true; do
62+
case ${1:-} in
63+
-h|--help|help)
64+
usage
65+
exit
66+
;;
67+
-s|--start|start)
68+
SHINY_START="yes"
69+
shift
70+
;;
71+
-p|--port|port)
72+
shift
73+
SHINY_PORT="${1:-}"
74+
shift
75+
;;
76+
-b|--base|base)
77+
shift
78+
SHINY_BASE="${1:-}"
79+
shift
80+
;;
81+
-u|--user)
82+
shift
83+
SHINY_USER="${1:-}"
84+
shift
85+
;;
86+
-di|--disable-index|disable-index)
87+
DISABLE_DIRINDEX="off"
88+
shift
89+
;;
90+
-l|logs|--logs)
91+
shift
92+
SHINY_LOGS="${1:-}"
93+
shift
94+
;;
95+
-*)
96+
echo "Unknown option: ${1:-}"
97+
exit 1
98+
;;
99+
*)
100+
break
101+
;;
102+
esac
103+
done
104+
105+
# Functions
106+
107+
function prepare_conf() {
108+
SHINY_PORT=$1
109+
SHINY_BASE=$2
110+
SHINY_LOGS=$3
111+
DISABLE_DIRINDEX=$4
112+
SHINY_USER=$5
113+
CONFIG="run_as ${SHINY_USER};
114+
server {
115+
listen ${SHINY_PORT};
116+
117+
# Define a location at the base URL
118+
location / {
119+
120+
# Host the directory of Shiny Apps stored in this directory
121+
site_dir ${SHINY_BASE};
122+
123+
# Log all Shiny output to files in this directory
124+
log_dir ${SHINY_LOGS};
125+
126+
# When a user visits the base URL rather than a particular application,
127+
# an index of the applications available in this directory will be shown.
128+
directory_index ${DISABLE_DIRINDEX};
129+
}
130+
}"
131+
echo "${CONFIG}";
132+
}
133+
134+
135+
# Are we starting the server?
136+
137+
if [ "${SHINY_START}" == "yes" ]; then
138+
139+
echo "Generating shiny configuration...";
140+
echo "port: ${SHINY_PORT}";
141+
echo "logs:" ${SHINY_LOGS};
142+
echo "base: ${SHINY_BASE}";
143+
echo "run_as: ${SHINY_USER}";
144+
145+
# Prepare the template
146+
147+
CONFIG=$(prepare_conf $SHINY_PORT $SHINY_BASE $SHINY_LOGS $DISABLE_DIRINDEX $SHINY_USER);
148+
149+
# Temporary directories, if don't exist
150+
mkdir -p "${SHINY_LOGS}";
151+
mkdir -p ${SHINY_LOGS}/logs;
152+
mkdir -p ${SHINY_LOGS}/lib;
153+
154+
# Configuration file
155+
echo "${CONFIG}" > "shiny-server.conf";
156+
echo "Server logging will be in ${SHINY_LOGS}";
157+
echo
158+
echo "To run your server:
159+
160+
module load singularity
161+
singularity run --bind $SHINY_LOGS/logs:/var/log/shiny \\
162+
--bind $SHINY_LOGS/lib:/var/lib/shiny-server \\
163+
--bind shiny-server.conf:/etc/shiny-server/shiny-server.conf shiny.simg
164+
165+
---------------------------------------------------------------------------
166+
For custom applications, also add --bind $SHINY_BASE:/srv/shiny-server
167+
To see your applications, open your browser to http://127.0.0.1:$SHINY_PORT or
168+
open a ssh connection from your computer to your cluster.
169+
"
170+
exit
171+
else
172+
usage
173+
fi

0 commit comments

Comments
 (0)