@@ -10,20 +10,21 @@ LOGDIR=$IRIS_HOME/logs
10
10
PIDFILE=$LOGDIR /iris.pid
11
11
SVCPIDFILE=$LOGDIR /service.%%.pid
12
12
INSTALL_LOG=$LOGDIR /install.log
13
- HOSTNAME=http:// 0.0.0.0
13
+ DEFAULT_HOSTNAME= 0.0.0.0
14
14
15
15
IRIS_USAGE=' iris [options] <command> [<arguments>]
16
16
17
17
Available commands:
18
+ check Ensure that Iris is ready to go
19
+ examples Install example data
18
20
help This command
19
21
install Install dependencies required by Iris
20
22
open Open up an Iris session (Mac only, for now)
21
- start Start Iris
22
- stop Stop Iris
23
23
restart Restart Iris
24
24
services Lists available services
25
+ start Start Iris
25
26
status Check whether or not Iris is running
26
- check Ensure that Iris is ready to go
27
+ stop Stop Iris
27
28
28
29
"iris help <command>" shows help on specific commands.'
29
30
@@ -55,6 +56,16 @@ function _json_flatten {
55
56
" < $jsonfile
56
57
}
57
58
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
+
58
69
function _running_pid {
59
70
pidfile=$1
60
71
if [ -e " $pidfile " ]; then
@@ -80,7 +91,7 @@ function _start_services {
80
91
fi
81
92
echo " Starting services..."
82
93
if [ -n " $svc " ]; then
83
- list_services=" iris_cmd_services | awk ' \$ 2== \" $ svc\" {print}' "
94
+ list_services=" iris_cmd_services $ svc"
84
95
else
85
96
list_services=' iris_cmd_services'
86
97
fi
@@ -128,10 +139,15 @@ function _status_line {
128
139
129
140
function _find_service {
130
141
local svc=$1
131
- local service=(` iris_cmd_services | awk " \\\$ 2== \"\$ svc\" {print} " ` )
142
+ local service=(` iris_cmd_services $ svc` )
132
143
echo " ${service[*]} "
133
144
}
134
145
146
+ function _service_url {
147
+ local svc=($@ )
148
+ echo " http://${svc[4]} :${svc[0]} "
149
+ }
150
+
135
151
function _service_status {
136
152
local service=($@ )
137
153
local name=${service[1]}
@@ -140,8 +156,7 @@ function _service_status {
140
156
echo " Service '$name ' is not running."
141
157
return
142
158
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[@]} `
145
160
}
146
161
147
162
# ===========================================================================
@@ -157,7 +172,7 @@ Starts Iris services. With no arguments, starts all services.
157
172
function iris_cmd_start {
158
173
svc=$1
159
174
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
161
176
echo " Service $svc is not a valid service!"
162
177
exit 1
163
178
fi
@@ -184,7 +199,7 @@ Stops Iris services. With no arguments, stops all of Iris.
184
199
function iris_cmd_stop {
185
200
svc=$1
186
201
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
188
203
echo " Service $svc is not a valid service!"
189
204
exit 1
190
205
else
@@ -346,8 +361,8 @@ Opens a browser window with the Iris website. This option is currently only
346
361
supported by Mac (Srsly, why would you use anything else?)."
347
362
function iris_cmd_open {
348
363
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 `
351
366
}
352
367
353
368
# ---------------------------------------------------------------------------
@@ -363,23 +378,24 @@ See also: 'iris services'"
363
378
function iris_cmd_status {
364
379
svc=$1
365
380
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
368
383
echo " Service '$svc ' is not a valid service!"
369
384
iris_cmd_help status
370
385
fi
371
386
_status_line " SERVICE" " PID" " URL"
372
- _service_status ${ service[@]}
387
+ _service_status $service
373
388
else
374
389
pid=` _iris_pid`
375
390
if [ -z " $pid " ]; then
376
391
echo " Iris is not running."
377
392
else
378
393
echo " Iris is running as process $pid with the following services:"
379
394
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]} ) )
383
399
if [ -n " $pid " ]; then
384
400
if [ -z " $service_running " ]; then
385
401
_status_line " SERVICE" " PID" " URL"
@@ -394,13 +410,34 @@ function iris_cmd_status {
394
410
# ---------------------------------------------------------------------------
395
411
# IRIS SERVICES
396
412
# ---------------------------------------------------------------------------
397
- _help_services=" iris services
413
+ _help_services=" iris services [<service>]
398
414
399
415
Lists available service currently configured with Iris (not *running* services).
400
416
417
+ <service> Only show configuration for specified service
418
+
401
419
See also: 'iris status'"
402
420
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
404
441
}
405
442
406
443
# ---------------------------------------------------------------------------
@@ -420,7 +457,7 @@ function iris_cmd_restart {
420
457
# ---------------------------------------------------------------------------
421
458
# IRIS EXAMPLES
422
459
# ---------------------------------------------------------------------------
423
- _help_check =" iris examples
460
+ _help_examples =" iris examples
424
461
425
462
Install example data."
426
463
function iris_cmd_examples {
0 commit comments