-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev-shutdown.sh
More file actions
executable file
·169 lines (143 loc) · 5.33 KB
/
dev-shutdown.sh
File metadata and controls
executable file
·169 lines (143 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# CFMN Development Shutdown Script
# This script gracefully stops all development services
set -e # Exit on error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Project paths
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Print banner
print_banner() {
echo -e "${CYAN}${BOLD}"
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ CFMN Development Environment Shutdown ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
# Print section header
print_section() {
echo -e "\n${BLUE}${BOLD}▶ $1${NC}"
}
# Print success message
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
# Print error message
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Print warning message
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
# Print info message
print_info() {
echo -e "${CYAN}ℹ${NC} $1"
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Stop backend server
stop_backend() {
print_section "Stopping Backend Server"
# Check if tmux session exists
if tmux has-session -t cfmn-backend 2>/dev/null; then
tmux kill-session -t cfmn-backend
print_success "Backend server stopped (tmux session killed)"
else
print_info "Backend tmux session not found"
# Fallback: check for running processes
if pgrep -f "cargo.*run" > /dev/null || pgrep -f "cargo-watch" > /dev/null; then
print_warning "Found backend process running outside tmux, attempting to kill..."
pkill -f "cargo-watch" || pkill -f "cargo.*run"
sleep 1
if pgrep -f "cargo.*run" > /dev/null || pgrep -f "cargo-watch" > /dev/null; then
print_error "Failed to stop backend process. Kill manually with: pkill -9 -f cargo-watch"
else
print_success "Backend process stopped"
fi
else
print_success "No backend process found"
fi
fi
}
# Stop frontend server
stop_frontend() {
print_section "Stopping Frontend Dev Server"
# Check if tmux session exists
if tmux has-session -t cfmn-frontend 2>/dev/null; then
tmux kill-session -t cfmn-frontend
print_success "Frontend dev server stopped (tmux session killed)"
else
print_info "Frontend tmux session not found"
# Fallback: check for running processes
if pgrep -f "vite" > /dev/null; then
print_warning "Found frontend process running outside tmux, attempting to kill..."
pkill -f "vite"
sleep 1
if pgrep -f "vite" > /dev/null; then
print_error "Failed to stop frontend process. Kill manually with: pkill -9 -f vite"
else
print_success "Frontend process stopped"
fi
else
print_success "No frontend process found"
fi
fi
}
# Stop database container
stop_database() {
print_section "Stopping PostgreSQL Database"
cd "${PROJECT_ROOT}"
# Check if container is running
if docker ps --format '{{.Names}}' | grep -q '^cfmn-dev-db$'; then
# Stop and remove the container
if command_exists docker-compose; then
docker-compose -f docker-compose.dev.yml down
else
docker compose -f docker-compose.dev.yml down
fi
print_success "PostgreSQL container stopped and removed"
else
print_info "Database container is not running"
fi
}
# Print summary
print_summary() {
echo ""
echo -e "${GREEN}${BOLD}╔════════════════════════════════════════════════════════════════╗"
echo -e "║ ║"
echo -e "║ ✓ Shutdown Complete! ║"
echo -e "║ ║"
echo -e "╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""
print_section "Status Summary"
echo -e " ${GREEN}✓${NC} Backend server stopped"
echo -e " ${GREEN}✓${NC} Frontend dev server stopped"
echo -e " ${GREEN}✓${NC} PostgreSQL container stopped"
echo ""
print_section "To Restart Development Environment"
echo -e " ${CYAN}./dev-startup.sh${NC}"
echo ""
print_info "All services have been shut down cleanly."
echo ""
}
# Main execution
main() {
print_banner
stop_backend
stop_frontend
stop_database
print_summary
}
# Run main function
main