@@ -106,7 +106,11 @@ function pids_list {
106106 fi
107107
108108 echo " $pid "
109- mapfile -t pids < <( ps --ppid " $pid " -o pid | awk ' NR>1' )
109+
110+ pids=()
111+ while IFS= read -r line; do
112+ pids+=(" $line " )
113+ done < <( ps -ax -o pid,ppid | awk -v ppid=" $pid " ' $2 == ppid {print $1}' )
110114
111115 if [[ ! 0 -eq " ${# pids[@]} " ]]; then
112116 for child_pid in " ${pids[@]} " ; do
@@ -135,7 +139,10 @@ function stop_services {
135139 continue
136140 fi
137141
138- mapfile -t pids < <( pids_list " $pid " )
142+ pids=()
143+ while IFS= read -r line; do
144+ pids+=(" $line " )
145+ done < <( pids_list " $pid " )
139146
140147 echo " Stopping ${svc_name} by pids ${pids[*]} "
141148 kill -s TERM " ${pids[@]} " & > /dev/null
@@ -205,22 +212,49 @@ while [[ $# -gt 0 ]]; do
205212done
206213
207214# load services from path if they were not provided by command-line option
215+
208216if [[ 0 -eq " ${# services[@]} " ]]; then
209- mapfile -t service_entries < <( find \
210- " $path " /* /src \
211- -type f \
212- -name " *.ts" \
213- -exec grep -lP ' extends\s+IMQ(Service|Client)\s*\{' {} +)
214-
215- for file in " ${service_entries[@]} " ; do
216- IFS=' /' read -ra file_path <<< " ${file#${path}/}"
217- service_name=" ${file_path[0]} "
218- present=$( in_services " $service_name " )
219-
220- if [[ 0 -eq ${present} ]]; then
221- services+=( " $service_name " )
222- fi
223- done
217+ # MacOSX patch, as long as it does not compatible with linux's grep -P
218+ if [[ -x perl ]]; then
219+ service_entries=()
220+
221+ while IFS= read -r -d ' ' file; do
222+ service_entries+=(" $file " )
223+ done < <( find \
224+ " $path " /* /src \
225+ -type f \
226+ -name " *.ts" \
227+ -exec perl -lne \
228+ ' print $ARGV if /extends\s+IMQ(Service|Client)\s*\{/' \
229+ {} + 2> /dev/null | tr ' \n' ' \0'
230+ )
231+
232+ for file in " ${service_entries[@]} " ; do
233+ IFS=' /' read -ra file_path <<< " ${file#${path}/}"
234+ service_name=" ${file_path[0]} "
235+ present=$( in_services " $service_name " )
236+
237+ if [[ 0 -eq ${present} ]]; then
238+ services+=( " $service_name " )
239+ fi
240+ done
241+ else
242+ mapfile -t service_entries < <( find \
243+ " $path " /* /src \
244+ -type f \
245+ -name " *.ts" \
246+ -exec grep -lP ' extends\s+IMQ(Service|Client)\s*\{' {} +)
247+
248+ for file in " ${service_entries[@]} " ; do
249+ IFS=' /' read -ra file_path <<< " ${file#${path}/}"
250+ service_name=" ${file_path[0]} "
251+ present=$( in_services " $service_name " )
252+
253+ if [[ 0 -eq ${present} ]]; then
254+ services+=( " $service_name " )
255+ fi
256+ done
257+ fi
224258fi
225259
226260# make sure workdir exists to store pids
0 commit comments