blob: 7d32b87bbfceb2980f27f4bcf1e3316d458329bb [file] [log] [blame]
#!/bin/bash
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### start `pave` and `serve-updates` in a single command
## usage: fx serve [-v] [-l host[:port]]
## -l host:port for "pm serve" to listen on
## -v enable more verbose output (must be first argument)
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
kill_child_processes() {
child_pids=$(jobs -p)
if [[ -n "${child_pids}" ]]; then
# Note: child_pids must be expanded to args here.
kill ${child_pids} 2> /dev/null
wait 2> /dev/null
fi
}
trap kill_child_processes EXIT
serve_args=()
fx-standard-switches "$@"
set -- "${FX_ARGV[@]}"
while (($#)); do
case "$1" in
-v|-vv|--verbose)
serve_args+=("$1")
;;
-l)
serve_args+=("$1" "$2")
shift
;;
*)
echo 2>&1 "Unknown argument: \"${1}\" ignored"
;;
esac
shift
done
fx-command-exec pave &
pave_pid=$!
fx-command-exec serve-updates "${serve_args[@]}" &
serve_pid=$!
while true; do
sleep 1
# If any child exits, then exit the whole process, causing other children to
# be cleaned up by the exit trap.
for pid in "${pave_pid}" "${serve_pid}"; do
if ! kill -0 $pid 2> /dev/null; then
exit
fi
done
done
# See EXIT trap above for cleanup that occurs