Skip to content

Commit 6316b34

Browse files
committed
hostname now configurable. Cleanup of iris script.
1 parent ff1587d commit 6316b34

File tree

3 files changed

+76
-26
lines changed

3 files changed

+76
-26
lines changed

conf/services-sample.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"settings" : {
3+
"hostname" : "0.0.0.0"
4+
},
25
"endpoints": {
36
"iris" : {
47
"examples" : { "paths" : [ "/gwas", "/phenotypes", "/species", "/pcoords" ] }
@@ -12,7 +15,7 @@
1215
{
1316
"config": "app-config.js",
1417
"name": "iris",
15-
"nodefile": "proxy.js",
18+
"nodefile": "proxy.js",
1619
"port": 4747
1720
},
1821
{

nodejs/services/service-base.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,21 @@ exports.loadConfiguration = function (confFile) {
128128
}
129129
if (confFile == null) {
130130
console.log("Configuration file required!");
131-
console.log("Usage: node " + process.argv[1] + " <config_file.js> [<service-name>]");
131+
console.log("Usage: node " +
132+
process.argv[1] + " <config_file.js> [<service-name>]");
132133
return;
133134
}
134135
IRIS.config = require(confFile).Config;
135136
if (global.process.env.NODE_PORT != null) {
136137
IRIS.config.appPort = global.process.env.NODE_PORT;
137138
}
139+
if (!IRIS.config.settings) {
140+
IRIS.config.settings = {};
141+
}
142+
if (!IRIS.config.settings.hostname) {
143+
IRIS.config.settings.hostname = '0.0.0.0';
144+
}
145+
138146
return IRIS.config;
139147
};
140148

@@ -170,7 +178,7 @@ exports.findService = function (args) {
170178

171179
exports.startService = function () {
172180
IRIS.app.listen(IRIS.config.appPort);
173-
console.log("service-address http://localhost:%d", IRIS.app.address().port)
181+
console.log("service-address %s", IRIS.uri());
174182
console.log("service-mode %s", IRIS.app.settings.env);
175183
}
176184

@@ -184,7 +192,8 @@ exports.httpGET = function (response, service, path) {
184192
}
185193

186194
IRIS.uri = function () {
187-
return 'http://' + IRIS.app.address().address + ':' + IRIS.app.address().port;
195+
return 'http://' +
196+
IRIS.app.address().address + ':' + IRIS.app.address().port;
188197
}
189198

190199
/* SERVICE API
@@ -211,7 +220,8 @@ IRIS.app.get('/service/list', function (req, res) {
211220
var service = {
212221
name: serviceName,
213222
path: paths[i],
214-
uri: 'http://0.0.0.0:' + endpoint.port
223+
uri: 'http://' + IRIS.config.settings.hostname +
224+
':' + endpoint.port
215225
};
216226
services.push(service);
217227
}

scripts/iris

+58-21
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ LOGDIR=$IRIS_HOME/logs
1010
PIDFILE=$LOGDIR/iris.pid
1111
SVCPIDFILE=$LOGDIR/service.%%.pid
1212
INSTALL_LOG=$LOGDIR/install.log
13-
HOSTNAME=http://0.0.0.0
13+
DEFAULT_HOSTNAME=0.0.0.0
1414

1515
IRIS_USAGE='iris [options] <command> [<arguments>]
1616
1717
Available commands:
18+
check Ensure that Iris is ready to go
19+
examples Install example data
1820
help This command
1921
install Install dependencies required by Iris
2022
open Open up an Iris session (Mac only, for now)
21-
start Start Iris
22-
stop Stop Iris
2323
restart Restart Iris
2424
services Lists available services
25+
start Start Iris
2526
status Check whether or not Iris is running
26-
check Ensure that Iris is ready to go
27+
stop Stop Iris
2728
2829
"iris help <command>" shows help on specific commands.'
2930

@@ -55,6 +56,16 @@ function _json_flatten {
5556
" < $jsonfile
5657
}
5758

59+
function _json_lookup {
60+
jsonfile=$1
61+
fields=$2
62+
perl -MJSON -e "
63+
my \$d = decode_json(join '',<STDIN>);
64+
for (qw/$fields/) { \$d = \$d->{\$_} };
65+
print \"\$d\n\";
66+
" < $jsonfile
67+
}
68+
5869
function _running_pid {
5970
pidfile=$1
6071
if [ -e "$pidfile" ]; then
@@ -80,7 +91,7 @@ function _start_services {
8091
fi
8192
echo "Starting services..."
8293
if [ -n "$svc" ]; then
83-
list_services="iris_cmd_services | awk '\$2==\"$svc\"{print}'"
94+
list_services="iris_cmd_services $svc"
8495
else
8596
list_services='iris_cmd_services'
8697
fi
@@ -128,10 +139,15 @@ function _status_line {
128139

129140
function _find_service {
130141
local svc=$1
131-
local service=(`iris_cmd_services | awk "\\\$2==\"\$svc\"{print}"`)
142+
local service=(`iris_cmd_services $svc`)
132143
echo "${service[*]}"
133144
}
134145

146+
function _service_url {
147+
local svc=($@)
148+
echo "http://${svc[4]}:${svc[0]}"
149+
}
150+
135151
function _service_status {
136152
local service=($@)
137153
local name=${service[1]}
@@ -140,8 +156,7 @@ function _service_status {
140156
echo "Service '$name' is not running."
141157
return
142158
fi
143-
local port=${service[0]}
144-
_status_line $name `_running_pid $pidfile` "$HOSTNAME:$port"
159+
_status_line $name `_running_pid $pidfile` `_service_url ${service[@]}`
145160
}
146161

147162
# ===========================================================================
@@ -157,7 +172,7 @@ Starts Iris services. With no arguments, starts all services.
157172
function iris_cmd_start {
158173
svc=$1
159174
if [ -n "$svc" ]; then
160-
if [ `iris_cmd_services | cut -f2 | grep -c "\b$svc\b"` -eq 0 ]; then
175+
if [ -z `iris_cmd_services $svc` ]; then
161176
echo "Service $svc is not a valid service!"
162177
exit 1
163178
fi
@@ -184,7 +199,7 @@ Stops Iris services. With no arguments, stops all of Iris.
184199
function iris_cmd_stop {
185200
svc=$1
186201
if [ -n "$svc" ]; then
187-
if [ `iris_cmd_services | cut -f2 | grep -c "\b$svc\b"` -eq 0 ]; then
202+
if [ -z `iris_cmd_services $svc` ]; then
188203
echo "Service $svc is not a valid service!"
189204
exit 1
190205
else
@@ -346,8 +361,8 @@ Opens a browser window with the Iris website. This option is currently only
346361
supported by Mac (Srsly, why would you use anything else?)."
347362
function iris_cmd_open {
348363
proxy_service='iris' # TODO: Name it something else?
349-
port=`_find_service $proxy_service | awk '{print $1}'`
350-
open $HOSTNAME:$port
364+
local service=`iris_cmd_services $proxy_service`
365+
open `_service_url $service`
351366
}
352367

353368
# ---------------------------------------------------------------------------
@@ -363,23 +378,24 @@ See also: 'iris services'"
363378
function iris_cmd_status {
364379
svc=$1
365380
if [ -n "$svc" ]; then
366-
local service=(`_find_service $svc`)
367-
if [ "${#service[@]}" -eq 0 ]; then
381+
local service=`iris_cmd_services $svc`
382+
if [ -z "$service" ]; then
368383
echo "Service '$svc' is not a valid service!"
369384
iris_cmd_help status
370385
fi
371386
_status_line "SERVICE" "PID" "URL"
372-
_service_status ${service[@]}
387+
_service_status $service
373388
else
374389
pid=`_iris_pid`
375390
if [ -z "$pid" ]; then
376391
echo "Iris is not running."
377392
else
378393
echo "Iris is running as process $pid with the following services:"
379394
fi
380-
iris_cmd_services | cut -f2 | while read name; do
381-
local service=(`_find_service $name`)
382-
local pid=$(_running_pid $(_svc_pidfile $name))
395+
iris_cmd_services | while read line
396+
do
397+
local service=($line)
398+
local pid=$(_running_pid $(_svc_pidfile ${service[1]}))
383399
if [ -n "$pid" ]; then
384400
if [ -z "$service_running" ]; then
385401
_status_line "SERVICE" "PID" "URL"
@@ -394,13 +410,34 @@ function iris_cmd_status {
394410
# ---------------------------------------------------------------------------
395411
# IRIS SERVICES
396412
# ---------------------------------------------------------------------------
397-
_help_services="iris services
413+
_help_services="iris services [<service>]
398414
399415
Lists available service currently configured with Iris (not *running* services).
400416
417+
<service> Only show configuration for specified service
418+
401419
See also: 'iris status'"
402420
function iris_cmd_services {
403-
_json_flatten $SVC_CONF "services" "port name nodefile config"
421+
local name=$1
422+
local hostname=$(_json_lookup $SVC_CONF "settings hostname")
423+
[ -z "$hostname" ] && hostname=DEFAULT_HOSTNAME
424+
local services
425+
if [ -n "$name" ]; then
426+
services=$(_json_flatten $SVC_CONF services \
427+
'port name nodefile config hostname' | awk "\$2 == \"$name\"")
428+
else
429+
services=$(_json_flatten $SVC_CONF services \
430+
'port name nodefile config hostname')
431+
fi
432+
433+
[ -z "$services" ] && return
434+
echo "$services" | while read line; do
435+
local svc=($line)
436+
if [ -z "${svc[4]}" ]; then
437+
svc[4]=$hostname
438+
fi
439+
printf "%-5d %-18s %-20s %-25s %s\n" ${svc[@]}
440+
done
404441
}
405442

406443
# ---------------------------------------------------------------------------
@@ -420,7 +457,7 @@ function iris_cmd_restart {
420457
# ---------------------------------------------------------------------------
421458
# IRIS EXAMPLES
422459
# ---------------------------------------------------------------------------
423-
_help_check="iris examples
460+
_help_examples="iris examples
424461
425462
Install example data."
426463
function iris_cmd_examples {

0 commit comments

Comments
 (0)