| #!/bin/bash |
| # Copyright 2015 The Vanadium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style |
| # license that can be found in the LICENSE file. |
| |
| # Starts an instance of measured and required services. |
| # |
| # mounttabled is started locally at IPADDR:PORT, mounting itself to the global |
| # mount table at $GLOBAL_MT/users/$USER/$PREFIX/$DEVID. syncbased is started in |
| # the local mount table at $PREFIX/$DEVID/syncbased. |
| # measured is started, creating a syncgroup published at the local syncbased as |
| # reached through the global mount table: |
| # $GLOBAL_MT/users/$USER/$PREFIX/$DEVID/$PREFIX/$DEVID/syncbased |
| # Once the syncgroup is joined, sync is configured to use either the global or |
| # the local mount table (unless the local mount table IPADDR:PORT changes). |
| # measured drops most permissions on prefixes in the syncgroup. Full admin |
| # permissions are granted to $ADMIN (as a blessing extension of the same |
| # default blessing as the one running this script). |
| |
| set -eu |
| |
| source "${JIRI_ROOT}/release/projects/sensorlog/go/src/v.io/x/sensorlog/scripts/runner_lib.sh" |
| |
| # Must be run with V23_CREDENTIALS set or through the agent. |
| # Optional environment variables: SL_PREFIX, SL_DEVID, SL_ADMIN, SL_IPADDR_PORT, SL_USER, SL_GLOBAL_MT, SL_TMPDIR |
| function main() { |
| local -r PREFIX="${SL_PREFIX:-sl/measured}" |
| local -r DEVID="${SL_DEVID:-$(gen_uuid)}" |
| local -r ADMIN="${SL_ADMIN:-sl/client}" |
| local -r NAME="${PREFIX}/${DEVID}" |
| local -r IPADDR_PORT="${SL_IPADDR_PORT:-$(dig $(hostname) +short):8707}" |
| local -r USER="${SL_USER:-$(get_user_email)}" |
| local -r GLOBAL_MT="${SL_GLOBAL_MT:-/ns.dev.v.io:8101}" |
| local -r TMPDIR="${SL_TMPDIR:-sltmp}/${NAME}" |
| |
| mkdir -p "${TMPDIR}" |
| trap "kill_child_processes; exit 1" ERR EXIT |
| run_mounttabled "${NAME}" "${IPADDR_PORT}" "${GLOBAL_MT}/users/${USER}" |
| run_syncbased "/${IPADDR_PORT}" "${NAME}" "${TMPDIR}" |
| run_measured "/${IPADDR_PORT}" "${NAME}" "${DEVID}" "${ADMIN}" \ |
| "${GLOBAL_MT}/users/${USER}/${NAME}/${NAME}/syncbased" \ |
| "${GLOBAL_MT}/users/${USER}" |
| # Wait for signal. |
| while true; do |
| sleep 10 |
| done |
| } |
| |
| main "$@" |