mirror of
https://github.com/shadoll/just-commons.git
synced 2025-12-20 01:25:43 +00:00
Refactor: Improve service restart logic to check status and start if not running
This commit is contained in:
@@ -143,14 +143,24 @@ restart service="" compose-file="":
|
|||||||
|
|
||||||
if [ -n "$service" ]; then
|
if [ -n "$service" ]; then
|
||||||
echo -e "{{BLUE}}Restarting service: $service{{NORMAL}}"
|
echo -e "{{BLUE}}Restarting service: $service{{NORMAL}}"
|
||||||
if ! $compose_cmd $file_arg restart "$service" 2>&1; then
|
|
||||||
echo -e "{{RED}}✗ Service '$service' not found{{NORMAL}}"
|
# Try to restart first
|
||||||
echo ""
|
$compose_cmd $file_arg restart "$service" 2>/dev/null || true
|
||||||
echo -e "{{YELLOW}}Available services:{{NORMAL}}"
|
|
||||||
$compose_cmd $file_arg config --services 2>/dev/null || echo "Could not list services"
|
# Check if service is actually running after restart attempt
|
||||||
exit 1
|
if $compose_cmd $file_arg ps "$service" 2>/dev/null | grep -q "Up"; then
|
||||||
|
echo -e "{{GREEN}}✓ Service $service restarted{{NORMAL}}"
|
||||||
|
else
|
||||||
|
echo -e "{{YELLOW}}Service $service not running, starting instead...{{NORMAL}}"
|
||||||
|
if ! $compose_cmd $file_arg up -d "$service" 2>&1; then
|
||||||
|
echo -e "{{RED}}✗ Service '$service' not found{{NORMAL}}"
|
||||||
|
echo ""
|
||||||
|
echo -e "{{YELLOW}}Available services:{{NORMAL}}"
|
||||||
|
$compose_cmd $file_arg config --services 2>/dev/null || echo "Could not list services"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "{{GREEN}}✓ Service $service started{{NORMAL}}"
|
||||||
fi
|
fi
|
||||||
echo -e "{{GREEN}}✓ Service $service restarted{{NORMAL}}"
|
|
||||||
else
|
else
|
||||||
just container stop "$service" "$compose_file"
|
just container stop "$service" "$compose_file"
|
||||||
just container start "$service" "$compose_file"
|
just container start "$service" "$compose_file"
|
||||||
|
|||||||
Reference in New Issue
Block a user