blob: 72a7659a4efe6140af30fa0efc38296e926e20ba [file] [log] [blame] [edit]
# Copyright 2012 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "System software update service"
author "chromium-os-dev@chromium.org"
# N.B. The chromeos-factoryinstall ebuild edits the 'start on' line so as
# to disable update_engine in factory images. Do not change this without
# also updating that reference.
start on starting system-services
stop on stopping system-services
# OOM score as a critical CrOS daemon. Should rarely be killed.
oom score -900
# The default is 10 failures every 5 seconds, but even if we crash early, it is
# hard to catch that. So here we set the crash rate as 10 failures every 20
# seconds which will include the default and more.
respawn
respawn limit 10 20
expect fork
# Runs the daemon at low/idle IO priority so that updates don't
# impact system responsiveness.
exec ionice -c3 update_engine
env REC_KEY_READABLE=/var/lib/update_engine/recovery_key_readable
env REC_KEY_VERSION=/var/lib/update_engine/recovery_key_version
# Put update_engine process in its own cgroup.
# Default cpu.shares is 1024.
post-start script
pid=$(status | cut -f 4 -d ' ')
cgroup_cpu_dir="/sys/fs/cgroup/cpu/${UPSTART_JOB}"
mkdir -p "${cgroup_cpu_dir}"
echo ${pid} > "${cgroup_cpu_dir}/tasks"
# Assigns net_cls handle 1:1 to packets generated from update_engine. For
# routing and tagging purposes, that value will be redefined in
# patchpanel/routing_service.h .
cgroup_net_cls_dir="/sys/fs/cgroup/net_cls/${UPSTART_JOB}"
mkdir -p "${cgroup_net_cls_dir}"
echo ${pid} > "${cgroup_net_cls_dir}/tasks"
echo "0x10001" > "${cgroup_net_cls_dir}/net_cls.classid"
# Run this everytime on boot instead of caching and preserving because
# it's possible that the values will change if device is reflashed.
recovery_key_tmp="$(mktemp)"
flashrom -i GBB:"${recovery_key_tmp}" -r
if [ "$?" -ne 0 ]; then
logger -t "${UPSTART_JOB}" "Failed to read flashrom."
unlink "${recovery_key_tmp}"
exit 0
fi
futility show "${recovery_key_tmp}" > "${REC_KEY_READABLE}"
grep -A3 'Recovery Key:' "${REC_KEY_READABLE}" \
| grep 'Key Version:' \
| grep -Eo '[0-9]+' > "${REC_KEY_VERSION}"
unlink "${recovery_key_tmp}"
end script