Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 3258c14

Browse files
committed
add better clustering commands
1 parent cc1fdce commit 3258c14

File tree

1 file changed

+79
-10
lines changed

1 file changed

+79
-10
lines changed

workers.sh

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,90 @@
22
ACTION=$1
33
SIGNAL=""
44

5+
pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ')
6+
if [ "$pid" == "" ]; then
7+
echo "No cluster master process found."
8+
exit
9+
fi
10+
11+
function workers_ps {
12+
ps_out=$(ps ax | grep -- "actionhero start$" | grep -v grep)
13+
IFS='
14+
'
15+
IFS=${IFS:0:1}
16+
workers=( $ps_out )
17+
}
18+
19+
workers_ps
20+
21+
wpids=()
22+
for worker in "${workers[@]}"
23+
do
24+
wpids+=("$(echo -e "${worker}" | xargs | cut -f1 -d' ')")
25+
done
26+
27+
528
if [ "$ACTION" == "reload" ]; then
629
SIGNAL="HUP"
730
elif [ "$ACTION" == "add" ]; then
831
SIGNAL="TTIN"
932
elif [ "$ACTION" == "rm" ]; then
1033
SIGNAL="TTOU"
11-
fi
34+
elif [ "$ACTION" == "kill" ]; then
35+
for wpid in "${wpids[@]}"
36+
do
37+
kill -9 $wpid # kill the workers and let master restart
38+
done
39+
exit
40+
elif [ "$ACTION" == "recycle" ]; then
41+
numWorkers=${#wpids[@]}
42+
echo "Start Recycle, Workers Running: ${#workers[@]}"
43+
44+
for wpid in "${wpids[@]}"
45+
do
46+
kill -TTIN $pid # add one
47+
sleep 1
48+
done
1249

13-
if [ "$SIGNAL" == "" ]; then
14-
echo "Usage: workers.sh [reload|add|rm]"
50+
declare -i sleepTime
51+
sleepTime=$numWorkers
52+
sleep $sleepTime
53+
54+
workers_ps
55+
echo "Max Workers Running: ${#workers[@]}"
56+
57+
# signal recycle of all
58+
kill -HUP $pid
59+
60+
sleepTime=$numWorkers*2
61+
sleep $sleepTime
62+
63+
for wpid in "${wpids[@]}"
64+
do
65+
kill -TTOU $pid # remove one
66+
sleep 1
67+
done
68+
69+
sleepTime=$numWorkers/2
70+
sleep $sleepTime
71+
72+
workers_ps
73+
echo "End Recycle, Workers Running: ${#workers[@]}"
74+
exit
75+
elif [ "$ACTION" == "ls" ]; then
76+
for worker in "${workers[@]}"
77+
do
78+
echo -e "${worker}" | xargs | cut -f1,4 -d' '
79+
done
80+
echo "Count: ${#wpids[@]}"
81+
exit
82+
elif [ "$ACTION" == "count" ]; then
83+
echo "${#wpids[@]}"
84+
exit
1585
else
16-
pid=$(ps ax | grep startCluster | grep -v grep | xargs | cut -f1 -d' ')
17-
if [ "$pid" == "" ]; then echo "No cluster master process found."
18-
else
19-
kill -$SIGNAL $pid
20-
echo "Signal $SIGNAL sent to process: $pid"
21-
fi
22-
fi
86+
echo "Usage: workers.sh [reload|recycle|add|rm|ls|count]"
87+
exit
88+
fi
89+
90+
kill -$SIGNAL $pid
91+
echo "Signal $SIGNAL sent to process: $pid"

0 commit comments

Comments
 (0)