blob: e7c33d4ba14522912297fd4187a28c81c385107f [file] [log] [blame]
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Job to start nebraska.py"
author "chromeos-core-services@google.com"
start on starting update-engine
stop on stopping update-engine
# We only run this on test images, but its a good idea to set this so we can
# change the default.
oom score -100
env NEBRASKA_CONFIG_FILE=/usr/local/nebraska/config.json
env NEBRASKA_CONFIG_POSTED=false
env OMAHA_FIELD="CHROMEOS_AUSERVER="
env STATEFUL_LSB_RELEASE_FILE=/mnt/stateful_partition/etc/lsb-release
pre-start script
# If no JSON file for updating nebraska's config was provided, don't run
# nebraska. We only want to run nebraska when we intend to do so.
if [ ! -f "${NEBRASKA_CONFIG_FILE}" ]; then
logger -t "${UPSTART_JOB}" "Can't run nebraska.py without its config file."
stop
exit 0
fi
logger -t "${UPSTART_JOB}" "Running nebraska.py."
end script
exec nebraska.py
post-start script
# Wait for the port file to appear for no more than 3 seconds.
nebraska.py --poll
if [ "$?" -ne 0 ]; then
logger -t "${UPSTART_JOB}" "Failed to find pid/port files of nebraska.py."
stop
exit 0
fi
NEBRASKA_URL="http://localhost:$(cat /run/nebraska/port)"
curl -X POST -d @"${NEBRASKA_CONFIG_FILE}" \
"${NEBRASKA_URL}/update_config"
NEBRASKA_CONFIG_POSTED=true
# Redirect the requests of update_engine to nebraska.
mkdir -p "$(dirname "${STATEFUL_LSB_RELEASE_FILE}")" && \
touch "${STATEFUL_LSB_RELEASE_FILE}"
sed -i "/${OMAHA_FIELD}/d" "${STATEFUL_LSB_RELEASE_FILE}"
echo "${OMAHA_FIELD}${NEBRASKA_URL}/update" >> "${STATEFUL_LSB_RELEASE_FILE}"
end script
post-stop script
# Only clean if nebraska config is provided.
if [ "${NEBRASKA_CONFIG_POSTED}" = true ]; then
sed -i "/${OMAHA_FIELD}/d" "${STATEFUL_LSB_RELEASE_FILE}"
fi
end script