Skip to content

Commit e35a2d7

Browse files
committed
Killall command not available in Circle
1 parent 7ac57b0 commit e35a2d7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

scripts/browserstack/start-tunnel.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ echo "Starting Browserstack Local in the background, logging into: ${tunnelLogFi
3838

3939
# Extension to the BrowserStackLocal binaries, because those can't create a readyfile.
4040
function create_ready_file {
41+
# Process ID for the BrowserStack local asynchronous instance.
42+
tunnelProcessPid=${1}
4143

4244
# To be able to exit the tail properly we need to have a sub shell spawned, which is
4345
# used to track the state of tail.
@@ -57,11 +59,12 @@ function create_ready_file {
5759
echo
5860
echo "BrowserStack Tunnel ready"
5961

60-
touch ${tunnelReadyFile}
62+
# Create the readyfile and write the PID for BrowserStack Local into it.
63+
echo ${tunnelProcessPid} > ${tunnelReadyFile}
6164
}
6265

6366
browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> \
6467
${tunnelLogFile} &
6568

6669
# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
67-
create_ready_file &
70+
create_ready_file ${!} &

scripts/browserstack/stop-tunnel.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
set -e -o pipefail
44

5-
echo "Shutting down Browserstack tunnel"
5+
tunnelTmpDir="/tmp/material-browserstack"
6+
tunnelReadyFile="${tunnelTmpDir}/readyfile"
67

7-
killall BrowserStackLocal
8+
if [[ ! -f ${tunnelReadyFile} ]]; then
9+
echo "BrowserStack tunnel has not been started. Cannot stop tunnel.."
10+
exit 1
11+
fi
812

9-
while [[ -n `ps -ef | grep "BrowserStackLocal" | grep -v "grep"` ]]; do
13+
echo "Shutting down Browserstack tunnel.."
14+
15+
# The process id for the BrowserStack local instance is stored inside of the readyfile.
16+
tunnelProcessId=$(cat ${tunnelReadyFile})
17+
18+
# Kill the process by reading the PID from the readyfile. Note that we cannot
19+
# use killall because CircleCI base container images don't have it installed.
20+
kill ${tunnelProcessId}
21+
22+
while (ps -p ${tunnelProcessId} &> /dev/null); do
1023
printf "."
1124
sleep .5
1225
done

0 commit comments

Comments
 (0)