| # Copyright 2018 The ChromiumOS Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| description "Start the fingerprint study webserver" | |
| author "chromium-os-dev@chromium.org" | |
| start on started system-services | |
| stop on stopping system-services | |
| respawn | |
| respawn limit 3 10 # if the job respawns 3 times in 10 seconds, stop trying. | |
| oom score 0 | |
| env INSTALL_ROOT=/opt/google/fingerprint_study | |
| env LOG_DIR=/var/log/fpstudy | |
| env PICTURE_DIR=/var/lib/fingers | |
| # GNUPGHOME should be set/exported for the gpg tool used within the | |
| # study_serve.py. | |
| env GNUPGHOME=/var/lib/fpstudygnupg | |
| env KEYRING_FILE=chromeos-fpstudy-public-device.gpg | |
| env RECIPIENTS_FILE=chromeos-fpstudy-recipients.txt | |
| script | |
| # Setup logging of all output in this script to append to server.out. | |
| exec >>"${LOG_DIR}/server.out" 2>&1 | |
| if ! fp_board="$(cros_config /fingerprint board)"; then | |
| echo "Error - Failed to get fingerprint board name." | |
| exit 1 | |
| fi | |
| echo "Using parameters for fingerprint board '${fp_board}'." | |
| parameters_file="${INSTALL_ROOT}/parameters/${fp_board}.sh" | |
| if [ ! -f "${parameters_file}" ]; then | |
| echo "Error - Parameters file '${parameters_file}' doesn't exist." | |
| stop | |
| exit 1 | |
| fi | |
| # Source the parameters file, which sets the following variables: | |
| # - FINGER_COUNT | |
| # - ENROLLMENT_COUNT | |
| # - VERIFICATION_COUNT | |
| . "${parameters_file}" | |
| echo "FINGER_COUNT: ${FINGER_COUNT}" | |
| echo "ENROLLMENT_COUNT: ${ENROLLMENT_COUNT}" | |
| echo "VERIFICATION_COUNT: ${VERIFICATION_COUNT}" | |
| # Enable encryption if encryption files exist. | |
| keyring_file="${INSTALL_ROOT}/${KEYRING_FILE}" | |
| recipients_file="${INSTALL_ROOT}/${RECIPIENTS_FILE}" | |
| if [ -f "${keyring_file}" -o -f "${recipients_file}" ]; then | |
| echo "Enabling encryption." | |
| if ! [ -f "${keyring_file}" -a -f "${recipients_file}" ]; then | |
| echo "Missing one of the required encryption files." | |
| stop | |
| exit 1 | |
| fi | |
| if ! recipients=$(cat "${recipients_file}"); then | |
| echo "Failed to read recipients file." | |
| stop | |
| exit 1 | |
| fi | |
| export GPG_KEYRING="${keyring_file}" | |
| export GPG_RECIPIENTS="${recipients}" | |
| fi | |
| export FINGER_COUNT ENROLLMENT_COUNT VERIFICATION_COUNT | |
| export LOG_DIR PICTURE_DIR | |
| exec "${INSTALL_ROOT}/study_serve" --syslog | |
| end script |