blob: c6abf18cb3a2e6477979ae822a9c237a50bee67a [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]] [-c version] [-a target] [--name NAME]
## -l host:port for "pm serve" to listen on
## -c version configuration format version for the served config.json
## that "pm" will serve. Valid choices: 1 or 2.
## Choosing `1` will serve a file which can be processed by
## `pkgctl repo add ... -f 1`.
## Choosing `2` will serve a file which can be processed by
## `pkgctl repo ...` without the `-f 1` switch.
## --no-auto-config do not configure this host as a package server on the device
## --name NAME Name the generated update source config NAME.
## --[no-]persist enable or disable persistent repo metadata. Disabled by default.
## -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=("--no-persist")
pave_args=(--reuseport)
fx-standard-switches "$@"
set -- "${FX_ARGV[@]}"
config_format="2"
while (($#)); do
case "$1" in
-v|-vv|--verbose)
serve_args+=("$1")
;;
--no-auto-config)
serve_args+=("$1")
;;
--no-persist)
;;
--persist)
serve_args+=("--persist")
;;
--name)
serve_args+=("--name" "$2")
shift
;;
-l)
serve_args+=("$1" "$2")
shift
;;
-c)
config_format=("$2")
shift
;;
-a)
pave_args+=("--no-bind" "$1" "$2")
shift
;;
*)
echo 2>&1 "Unknown argument: \"${1}\" ignored"
;;
esac
shift
done
serve_args+=("-c" "${config_format}")
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