Skip to content

Commit 0b08400

Browse files
committed
fix: macosx cli start/stop problem
1 parent 3799403 commit 0b08400

File tree

3 files changed

+96
-36
lines changed

3 files changed

+96
-36
lines changed

bin/ctl.sh

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
205212
done
206213

207214
# load services from path if they were not provided by command-line option
215+
208216
if [[ 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
224258
fi
225259

226260
# make sure workdir exists to store pids

bin/log.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ function multitail {
2121
args=( "$@" )
2222

2323
if [[ -z "${args[*]}" ]]; then
24-
mapfile -t logs < <(find \
25-
"$workdir" \
26-
-type f \
27-
-name "*.log")
24+
logs=()
25+
26+
while IFS= read -r logfile; do
27+
logs+=("$logfile")
28+
done < <(find "$workdir" -type f -name "*.log")
2829

2930
for logfile in "${logs[@]}"; do
3031
tail -f -n +1 "$logfile" &

bin/updep.sh

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,46 @@ done
6868

6969
# load services from path if they were not provided by command-line option
7070
if [[ 0 -eq "${#services[@]}" ]]; then
71-
mapfile -t service_entries < <(find \
72-
"$path"/*/src \
73-
-type f \
74-
-name "*.ts" \
75-
-exec grep -lP 'extends\s+IMQ(Service|Client)\s*\{' {} +)
76-
77-
for file in "${service_entries[@]}"; do
78-
IFS='/' read -ra file_path <<< "${file#${path}/}"
79-
service_name="${file_path[0]}"
80-
present=$(in_services "$service_name")
81-
82-
if [[ 0 -eq ${present} ]]; then
83-
services+=( "$service_name" )
84-
fi
85-
done
71+
if [[ -x perl ]]; then
72+
service_entries=()
73+
74+
while IFS= read -r -d '' file; do
75+
service_entries+=("$file")
76+
done < <(find \
77+
"$path"/*/src \
78+
-type f \
79+
-name "*.ts" \
80+
-exec perl -lne \
81+
'print $ARGV if /extends\s+IMQ(Service|Client)\s*\{/' \
82+
{} + 2>/dev/null | tr '\n' '\0'
83+
)
84+
85+
for file in "${service_entries[@]}"; do
86+
IFS='/' read -ra file_path <<< "${file#${path}/}"
87+
service_name="${file_path[0]}"
88+
present=$(in_services "$service_name")
89+
90+
if [[ 0 -eq ${present} ]]; then
91+
services+=( "$service_name" )
92+
fi
93+
done
94+
else
95+
mapfile -t service_entries < <(find \
96+
"$path"/*/src \
97+
-type f \
98+
-name "*.ts" \
99+
-exec grep -lP 'extends\s+IMQ(Service|Client)\s*\{' {} +)
100+
101+
for file in "${service_entries[@]}"; do
102+
IFS='/' read -ra file_path <<< "${file#${path}/}"
103+
service_name="${file_path[0]}"
104+
present=$(in_services "$service_name")
105+
106+
if [[ 0 -eq ${present} ]]; then
107+
services+=( "$service_name" )
108+
fi
109+
done
110+
fi
86111
fi
87112

88113
if ! [[ -x "$(command -v npm-check-updates)" ]]; then

0 commit comments

Comments
 (0)