v/services/mgmt/node/noded,v/tools/mgmt/nminstall: args for node manager
This change provides the node manager will optional arguments when using the
self-install feature: all unparsed args will be passed into the script generated
for the node manager by the installer. This generic mechanism replaces the
special-casing we had for the publish name flag.
nminstall is updated to pass through optional args to the node manager
self-installer.
While at it, also fix a bug (in how we handled the SINGLE_USER variable).
Also, change nminstall to use exec when running the node manager at the end (as
per Robin's suggestion).
Change-Id: Ib7962774c61e90311a2fd9bc93ef3ee19b2b5ae9
diff --git a/services/mgmt/node/noded/main.go b/services/mgmt/node/noded/main.go
index f384663..afb84ff 100644
--- a/services/mgmt/node/noded/main.go
+++ b/services/mgmt/node/noded/main.go
@@ -37,11 +37,8 @@
}
if *installSelf {
- // If the user specified a name to publish as, pass that through
- // to the installed node manager script.
- // TODO(caprita): Make the flag survive updates.
- args := append([]string{"--name=" + *publishAs}, flag.Args()...)
- if err := impl.SelfInstall(args, os.Environ()); err != nil {
+ // TODO(caprita): Make the flags survive updates.
+ if err := impl.SelfInstall(flag.Args(), os.Environ()); err != nil {
vlog.Errorf("SelfInstall failed: %v", err)
os.Exit(1)
}
diff --git a/tools/mgmt/nminstall b/tools/mgmt/nminstall
index 02e59a6..a9b6406 100755
--- a/tools/mgmt/nminstall
+++ b/tools/mgmt/nminstall
@@ -28,7 +28,7 @@
usage() {
echo "usage:"
- echo "./nminstall [--single_user] <install parent dir> [<binary source>]"
+ echo "./nminstall [--single_user] <install parent dir> [<binary source>] [-- args for node manager...]"
}
readonly BIN_NAMES=(noded suidhelper agentd)
@@ -132,6 +132,7 @@
usage
exit 1
fi
+ shift
if [[ ! -d "${INSTALL_PARENT_DIR}" ]]; then
echo "${INSTALL_PARENT_DIR} is not a directory!"
@@ -143,7 +144,7 @@
# TODO(caprita): Check that the node manager is not already installed before
# proceeding. We should require an explicit uninstall to avoid wiping away
# the node manager accidentally.
- if [[ ! ${SINGLE_USER} ]]; then
+ if [[ ${SINGLE_USER} == false ]]; then
sudo rm -rf "${INSTALL_DIR}"
else
rm -rf "${INSTALL_DIR}"
@@ -154,7 +155,12 @@
mkdir -m 700 "${BIN_INSTALL}"
# Fetch the binaries.
- local -r BIN_SOURCE="$2"
+ if [[ $# = 0 || "$1" = "--" ]]; then
+ local -r BIN_SOURCE=""
+ else
+ local -r BIN_SOURCE="$1"
+ shift
+ fi
get_binaries "${BIN_INSTALL}" "${BIN_SOURCE}"
for bin_name in "${BIN_NAMES[@]}"; do
local BINARY="${BIN_INSTALL}/${bin_name}"
@@ -168,7 +174,7 @@
# Set up the suidhelper.
echo "Configuring suidhelper ..."
local -r SETUID_SCRIPT="${BIN_INSTALL}/suidhelper"
- if [[ ! ${SINGLE_USER} ]]; then
+ if [[ ${SINGLE_USER} == false ]]; then
sudo bash -c "chown root:root \"${SETUID_SCRIPT}\"; chmod 4551 \"${SETUID_SCRIPT}\""
fi
echo "Suidhelper configured."
@@ -177,7 +183,15 @@
local -r NM_ROOT="${INSTALL_DIR}/nmroot"
echo "Installing node manager under ${NM_ROOT} ..."
local -r PUBLISH=$(hostname)
- VEYRON_NM_CURRENT="${INSTALL_DIR}/noded.curr" VEYRON_NM_ROOT="${NM_ROOT}" VEYRON_NM_HELPER="${SETUID_SCRIPT}" "${BIN_INSTALL}/noded" --install_self --name="${PUBLISH}"
+ if [[ "$1" = "--" ]]; then
+ shift
+ elif [[ $# != 0 ]]; then
+ echo "Unexpected arguments: $@"
+ usage
+ exit 1
+ fi
+
+ VEYRON_NM_CURRENT="${INSTALL_DIR}/noded.curr" VEYRON_NM_ROOT="${NM_ROOT}" VEYRON_NM_HELPER="${SETUID_SCRIPT}" "${BIN_INSTALL}/noded" --install_self -- --name="${PUBLISH}" "$@"
echo "Node manager installed."
local -r SECURITY_DIR="${INSTALL_DIR}/security"
@@ -194,7 +208,7 @@
echo
# NOTE: If you update the command below, please also update the command echoed
# above to keep the two in sync.
- VEYRON_CREDENTIALS="${PRINCIPAL_DIR}" "${BIN_INSTALL}/agentd" "${AGENT_FLAG}" --additional_principals="${AGENT_KEY_DIR}" "${INSTALL_DIR}/noded.curr"
+ VEYRON_CREDENTIALS="${PRINCIPAL_DIR}" exec "${BIN_INSTALL}/agentd" ${AGENT_FLAG} --additional_principals="${AGENT_KEY_DIR}" "${INSTALL_DIR}/noded.curr"
}
main "$@"