File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,10 @@ function scale_instances() {
186
186
187
187
# Get currently running instances
188
188
local running_containers=$( docker ps -q -f name=" ${PROJECT_NAME} -client-" )
189
- local current_count=$( echo " $running_containers " | grep -c . || echo 0)
189
+ local current_count=0
190
+ if [ -n " $running_containers " ]; then
191
+ current_count=$( echo " $running_containers " | wc -l)
192
+ fi
190
193
191
194
echo " Current instances: $current_count , Target: $target_instances "
192
195
@@ -243,12 +246,15 @@ function scale_instances() {
243
246
# Need to stop some instances
244
247
echo " Stopping excess instances (keeping first $target_instances )..."
245
248
246
- for i in $( seq $(( target_instances + 1 )) $current_count ) ; do
247
- local container_name=" ${PROJECT_NAME} -client-$i "
248
- echo " Stopping Instance $i "
249
- docker stop " $container_name " 2> /dev/null || true
250
- docker rm " $container_name " 2> /dev/null || true
251
- done
249
+ # Only run seq if we have valid numbers and current_count > target_instances
250
+ if [ " $current_count " -gt " $target_instances " ]; then
251
+ for i in $( seq $(( target_instances + 1 )) $current_count ) ; do
252
+ local container_name=" ${PROJECT_NAME} -client-$i "
253
+ echo " Stopping Instance $i "
254
+ docker stop " $container_name " 2> /dev/null || true
255
+ docker rm " $container_name " 2> /dev/null || true
256
+ done
257
+ fi
252
258
fi
253
259
254
260
echo " Scaling complete!"
You can’t perform that action at this time.
0 commit comments