blob: a7cf78feb60025984504f22770b9bd23a6451fb0 [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.
#### CATEGORY=Software delivery
### start `pave` and `serve-updates` in a single command
## usage: fx serve [-v] [-l host[:port]] [-a target]
## -l host:port for "pm serve" to listen on
## --no-auto-config do not configure this host as a package server on the device
## -v enable more verbose output (must be first argument)
## -a target ipv6 address for "fx pave --no-bind"
##
## NOTE: This command supports incremental package publishing. If enabled,
## it will not run 'pave' at all, and only act as a proxy for 'fx serve-updates'
##
## To enable incremental package serving, run "fx --enable=incremental serve ..."
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/fx-optional-features.sh || exit $?
fx-config-read
# If incremental is enabled, this is only a proxy for 'fx serve-updates', not
# starting a bootserver (pave). This is a transitional state while incremental
# is opt-in, and will be the default once incremental is on by default.
if is_feature_enabled "incremental"; then
fx-info "This command does not initiate 'pave' anymore, please run 'fx pave' if you need a paving server."
fx-command-exec serve-updates "$@"
fi
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=()
pave_args=()
fx-standard-switches "$@"
set -- "${FX_ARGV[@]}"
while (($#)); do
case "$1" in
-v|-vv|--verbose)
serve_args+=("$1")
;;
--no-auto-config)
serve_args+=("$1")
;;
-l)
serve_args+=("$1" "$2")
shift
;;
-a)
pave_args+=("--no-bind" "$1" "$2")
shift
;;
*)
echo 2>&1 "Unknown argument: \"${1}\" ignored"
;;
esac
shift
done
if fx-is-bringup; then
fx-error "$0 is not supported in the bringup build configuration, as there are no package features in bringup."
exit 1
fi
fx-command-exec pave "${pave_args[@]}"&
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