v1.2
This commit is contained in:
Regular → Executable
+2
-3
@@ -3,6 +3,5 @@ set -euo pipefail
|
|||||||
|
|
||||||
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
"$ROOT_DIR/labctl" up
|
bash "$ROOT_DIR/labctl" up
|
||||||
"$ROOT_DIR/labctl" urls
|
bash "$ROOT_DIR/labctl" urls
|
||||||
|
|
||||||
|
|||||||
Regular → Executable
+1
-2
@@ -3,5 +3,4 @@ set -euo pipefail
|
|||||||
|
|
||||||
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
"$ROOT_DIR/labctl" down
|
bash "$ROOT_DIR/labctl" down
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ ANSIBLE_PYTHON="$ANSIBLE_VENV/bin/python"
|
|||||||
ANSIBLE_PLAYBOOK="$ANSIBLE_VENV/bin/ansible-playbook"
|
ANSIBLE_PLAYBOOK="$ANSIBLE_VENV/bin/ansible-playbook"
|
||||||
export ANSIBLE_CONFIG="$ROOT_DIR/ansible/ansible.cfg"
|
export ANSIBLE_CONFIG="$ROOT_DIR/ansible/ansible.cfg"
|
||||||
|
|
||||||
|
run_project_script() {
|
||||||
|
local script_path=$1
|
||||||
|
shift || true
|
||||||
|
bash "$script_path" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
Usage:
|
Usage:
|
||||||
@@ -501,10 +507,10 @@ main() {
|
|||||||
up)
|
up)
|
||||||
confirm_installation
|
confirm_installation
|
||||||
run_playbook up.yml
|
run_playbook up.yml
|
||||||
"$ROOT_DIR/scripts/service_manager.sh" start all
|
run_project_script "$ROOT_DIR/scripts/service_manager.sh" start all
|
||||||
;;
|
;;
|
||||||
down)
|
down)
|
||||||
"$ROOT_DIR/scripts/service_manager.sh" stop all || true
|
run_project_script "$ROOT_DIR/scripts/service_manager.sh" stop all || true
|
||||||
run_playbook down.yml
|
run_playbook down.yml
|
||||||
;;
|
;;
|
||||||
preflight)
|
preflight)
|
||||||
@@ -519,7 +525,7 @@ main() {
|
|||||||
handle_assets_command "$@"
|
handle_assets_command "$@"
|
||||||
;;
|
;;
|
||||||
start|stop|status|urls|open|logs)
|
start|stop|status|urls|open|logs)
|
||||||
exec "$ROOT_DIR/scripts/service_manager.sh" "$cmd" "$@"
|
exec bash "$ROOT_DIR/scripts/service_manager.sh" "$cmd" "$@"
|
||||||
;;
|
;;
|
||||||
""|-h|--help|help)
|
""|-h|--help|help)
|
||||||
usage
|
usage
|
||||||
|
|||||||
Regular → Executable
+70
-10
@@ -91,6 +91,45 @@ service_ready() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
service_listener_pids() {
|
||||||
|
local service=$1
|
||||||
|
local port
|
||||||
|
|
||||||
|
port=$(service_port "$service") || return 0
|
||||||
|
ss -ltnp "( sport = :$port )" 2>/dev/null \
|
||||||
|
| grep -o 'pid=[0-9]\+' \
|
||||||
|
| cut -d= -f2 \
|
||||||
|
| sort -u
|
||||||
|
}
|
||||||
|
|
||||||
|
kill_pid_tree() {
|
||||||
|
local signal=$1
|
||||||
|
local pid=$2
|
||||||
|
|
||||||
|
if [[ ! "$pid" =~ ^[0-9]+$ ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
kill "-$signal" -- "-$pid" >/dev/null 2>&1 || true
|
||||||
|
pkill "-$signal" -P "$pid" >/dev/null 2>&1 || true
|
||||||
|
kill "-$signal" "$pid" >/dev/null 2>&1 || true
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate_service_processes() {
|
||||||
|
local service=$1
|
||||||
|
local signal=$2
|
||||||
|
local pid=${3:-}
|
||||||
|
local listener_pid
|
||||||
|
|
||||||
|
if [ -n "$pid" ]; then
|
||||||
|
kill_pid_tree "$signal" "$pid"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r listener_pid; do
|
||||||
|
kill_pid_tree "$signal" "$listener_pid"
|
||||||
|
done < <(service_listener_pids "$service")
|
||||||
|
}
|
||||||
|
|
||||||
start_one() {
|
start_one() {
|
||||||
local service=$1
|
local service=$1
|
||||||
local cmd
|
local cmd
|
||||||
@@ -184,26 +223,47 @@ start_one() {
|
|||||||
stop_one() {
|
stop_one() {
|
||||||
local service=$1
|
local service=$1
|
||||||
local pid_file
|
local pid_file
|
||||||
|
local pid=""
|
||||||
|
local attempt
|
||||||
|
|
||||||
pid_file=$(service_pid_file "$service")
|
pid_file=$(service_pid_file "$service")
|
||||||
|
|
||||||
if [ ! -f "$pid_file" ]; then
|
if [ -f "$pid_file" ]; then
|
||||||
|
pid=$(cat "$pid_file")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$pid" ] && ! service_ready "$service"; then
|
||||||
echo "$service not running"
|
echo "$service not running"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local pid
|
terminate_service_processes "$service" TERM "$pid"
|
||||||
pid=$(cat "$pid_file")
|
|
||||||
if kill -0 "$pid" >/dev/null 2>&1; then
|
for attempt in $(seq 1 20); do
|
||||||
kill "$pid" >/dev/null 2>&1 || true
|
if ! has_live_pid "$service" && ! service_ready "$service"; then
|
||||||
sleep 2
|
rm -f "$pid_file"
|
||||||
if kill -0 "$pid" >/dev/null 2>&1; then
|
echo "stopped $service"
|
||||||
kill -9 "$pid" >/dev/null 2>&1 || true
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
terminate_service_processes "$service" KILL "$pid"
|
||||||
|
|
||||||
|
for attempt in $(seq 1 5); do
|
||||||
|
if ! has_live_pid "$service" && ! service_ready "$service"; then
|
||||||
|
rm -f "$pid_file"
|
||||||
|
echo "stopped $service"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
rm -f "$pid_file"
|
rm -f "$pid_file"
|
||||||
echo "stopped $service"
|
echo "failed to stop $service cleanly" >&2
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
status_one() {
|
status_one() {
|
||||||
|
|||||||
Reference in New Issue
Block a user