Fix container management bugs: start/stop/restart logic
- Fix [s] Start in container menu to resume stopped containers with docker start instead of docker run (name already in use error) - Add safety check in run_conduit_container() to remove existing containers before docker run to prevent conflicts - Fix [t] Stop and [x] Restart to check exit codes and show accurate status - Add warning in main menu Start (option 5) when recreating stopped containers
This commit is contained in:
74
conduit.sh
74
conduit.sh
@@ -932,6 +932,10 @@ run_conduit_container() {
|
|||||||
local vol=$(get_volume_name $idx)
|
local vol=$(get_volume_name $idx)
|
||||||
local mc=$(get_container_max_clients $idx)
|
local mc=$(get_container_max_clients $idx)
|
||||||
local bw=$(get_container_bandwidth $idx)
|
local bw=$(get_container_bandwidth $idx)
|
||||||
|
# Remove any existing container with the same name to avoid conflicts
|
||||||
|
if docker ps -a 2>/dev/null | grep -q "[[:space:]]${name}$"; then
|
||||||
|
docker rm -f "$name" 2>/dev/null || true
|
||||||
|
fi
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name "$name" \
|
--name "$name" \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
@@ -2459,6 +2463,28 @@ start_conduit() {
|
|||||||
|
|
||||||
echo "Starting Conduit ($CONTAINER_COUNT container(s))..."
|
echo "Starting Conduit ($CONTAINER_COUNT container(s))..."
|
||||||
|
|
||||||
|
# Check if any stopped containers exist that will be recreated
|
||||||
|
local has_stopped=false
|
||||||
|
for i in $(seq 1 $CONTAINER_COUNT); do
|
||||||
|
local name=$(get_container_name $i)
|
||||||
|
if docker ps -a 2>/dev/null | grep -q "[[:space:]]${name}$"; then
|
||||||
|
if ! docker ps 2>/dev/null | grep -q "[[:space:]]${name}$"; then
|
||||||
|
has_stopped=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$has_stopped" = true ]; then
|
||||||
|
echo -e "${YELLOW}⚠ Note: This will remove and recreate stopped containers with fresh instances.${NC}"
|
||||||
|
echo -e "${YELLOW} Your data volumes are preserved, but container logs will be reset.${NC}"
|
||||||
|
echo -e "${YELLOW} To resume stopped containers without recreating, use the 'c' menu → [s].${NC}"
|
||||||
|
read -p " Continue? (y/n): " confirm < /dev/tty || true
|
||||||
|
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||||
|
echo -e " ${CYAN}Cancelled.${NC}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
for i in $(seq 1 $CONTAINER_COUNT); do
|
for i in $(seq 1 $CONTAINER_COUNT); do
|
||||||
local name=$(get_container_name $i)
|
local name=$(get_container_name $i)
|
||||||
local vol=$(get_volume_name $i)
|
local vol=$(get_volume_name $i)
|
||||||
@@ -3032,9 +3058,13 @@ manage_containers() {
|
|||||||
for i in $(seq 1 $CONTAINER_COUNT); do
|
for i in $(seq 1 $CONTAINER_COUNT); do
|
||||||
local name=$(get_container_name $i)
|
local name=$(get_container_name $i)
|
||||||
local vol=$(get_volume_name $i)
|
local vol=$(get_volume_name $i)
|
||||||
docker volume create "$vol" 2>/dev/null || true
|
if docker ps -a 2>/dev/null | grep -q "[[:space:]]${name}$"; then
|
||||||
fix_volume_permissions $i
|
docker start "$name" 2>/dev/null
|
||||||
run_conduit_container $i
|
else
|
||||||
|
docker volume create "$vol" 2>/dev/null || true
|
||||||
|
fix_volume_permissions $i
|
||||||
|
run_conduit_container $i
|
||||||
|
fi
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo -e " ${GREEN}✓ ${name} started${NC}"
|
echo -e " ${GREEN}✓ ${name} started${NC}"
|
||||||
else
|
else
|
||||||
@@ -3044,9 +3074,13 @@ manage_containers() {
|
|||||||
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
||||||
local name=$(get_container_name $sc_idx)
|
local name=$(get_container_name $sc_idx)
|
||||||
local vol=$(get_volume_name $sc_idx)
|
local vol=$(get_volume_name $sc_idx)
|
||||||
docker volume create "$vol" 2>/dev/null || true
|
if docker ps -a 2>/dev/null | grep -q "[[:space:]]${name}$"; then
|
||||||
fix_volume_permissions $sc_idx
|
docker start "$name" 2>/dev/null
|
||||||
run_conduit_container $sc_idx
|
else
|
||||||
|
docker volume create "$vol" 2>/dev/null || true
|
||||||
|
fix_volume_permissions $sc_idx
|
||||||
|
run_conduit_container $sc_idx
|
||||||
|
fi
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo -e " ${GREEN}✓ ${name} started${NC}"
|
echo -e " ${GREEN}✓ ${name} started${NC}"
|
||||||
else
|
else
|
||||||
@@ -3062,13 +3096,19 @@ manage_containers() {
|
|||||||
if [ "$sc_idx" = "all" ]; then
|
if [ "$sc_idx" = "all" ]; then
|
||||||
for i in $(seq 1 $CONTAINER_COUNT); do
|
for i in $(seq 1 $CONTAINER_COUNT); do
|
||||||
local name=$(get_container_name $i)
|
local name=$(get_container_name $i)
|
||||||
docker stop "$name" 2>/dev/null || true
|
if docker stop "$name" 2>/dev/null; then
|
||||||
echo -e " ${YELLOW}✓ ${name} stopped${NC}"
|
echo -e " ${YELLOW}✓ ${name} stopped${NC}"
|
||||||
|
else
|
||||||
|
echo -e " ${YELLOW} ${name} was not running${NC}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
||||||
local name=$(get_container_name $sc_idx)
|
local name=$(get_container_name $sc_idx)
|
||||||
docker stop "$name" 2>/dev/null || true
|
if docker stop "$name" 2>/dev/null; then
|
||||||
echo -e " ${YELLOW}✓ ${name} stopped${NC}"
|
echo -e " ${YELLOW}✓ ${name} stopped${NC}"
|
||||||
|
else
|
||||||
|
echo -e " ${YELLOW} ${name} was not running${NC}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo -e " ${RED}Invalid.${NC}"
|
echo -e " ${RED}Invalid.${NC}"
|
||||||
fi
|
fi
|
||||||
@@ -3087,8 +3127,11 @@ manage_containers() {
|
|||||||
fi
|
fi
|
||||||
for i in $(seq 1 $CONTAINER_COUNT); do
|
for i in $(seq 1 $CONTAINER_COUNT); do
|
||||||
local name=$(get_container_name $i)
|
local name=$(get_container_name $i)
|
||||||
docker restart "$name" 2>/dev/null || true
|
if docker restart "$name" 2>/dev/null; then
|
||||||
echo -e " ${GREEN}✓ ${name} restarted${NC}"
|
echo -e " ${GREEN}✓ ${name} restarted${NC}"
|
||||||
|
else
|
||||||
|
echo -e " ${RED}✗ Failed to restart ${name}${NC}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
# Restart tracker to pick up new container state
|
# Restart tracker to pick up new container state
|
||||||
if command -v systemctl &>/dev/null && systemctl is-active --quiet conduit-tracker.service 2>/dev/null; then
|
if command -v systemctl &>/dev/null && systemctl is-active --quiet conduit-tracker.service 2>/dev/null; then
|
||||||
@@ -3096,8 +3139,11 @@ manage_containers() {
|
|||||||
fi
|
fi
|
||||||
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
elif [[ "$sc_idx" =~ ^[1-5]$ ]] && [ "$sc_idx" -le "$CONTAINER_COUNT" ]; then
|
||||||
local name=$(get_container_name $sc_idx)
|
local name=$(get_container_name $sc_idx)
|
||||||
docker restart "$name" 2>/dev/null || true
|
if docker restart "$name" 2>/dev/null; then
|
||||||
echo -e " ${GREEN}✓ ${name} restarted${NC}"
|
echo -e " ${GREEN}✓ ${name} restarted${NC}"
|
||||||
|
else
|
||||||
|
echo -e " ${RED}✗ Failed to restart ${name}${NC}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo -e " ${RED}Invalid.${NC}"
|
echo -e " ${RED}Invalid.${NC}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user