-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathis-local-function-working.sh
More file actions
executable file
·48 lines (41 loc) · 1.44 KB
/
is-local-function-working.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.44 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
#!/bin/bash
set -e # Fail on any error
set -o pipefail # Ensure piped commands propagate exit codes properly
set -u # Treat unset variables as an error when substituting
#######################################################################################
# Script used in the git pre-push hook to check if the local cloud function can start #
#######################################################################################
# Initialize PID variable
PID=""
# Function to kill the background process and all its children
cleanup() {
# trunk-ignore(shellcheck/SC2317)
if [[ -n ${PID} ]]; then
# Kill the process group to ensure all child processes are terminated
# trunk-ignore(shellcheck/SC2317)
pkill -P "${PID}" 2>/dev/null || true
# trunk-ignore(shellcheck/SC2317)
kill "${PID}" 2>/dev/null || true
# Give it a moment to terminate gracefully
# trunk-ignore(shellcheck/SC2317)
sleep 1
# Force kill if still running
# trunk-ignore(shellcheck/SC2317)
kill -9 "${PID}" 2>/dev/null || true
fi
}
# Set up trap to ensure cleanup on exit
trap cleanup EXIT
# Start the function in the background and store the PID
npm start &
PID=$!
# Wait for the function to start (adjust the sleep time if needed)
sleep 5
# Check if the process is still running
if kill -0 "${PID}" 2>/dev/null; then
printf "\n✅ Local Function started successfully.\n"
exit 0
else
printf "\n❌ Local Function failed to start or crashed.\n"
exit 1
fi