blob: ab3465ca0f7040013112290d689d60d3102d3915 [file] [log] [blame] [edit]
# Copyright 2021 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Chrome OS camera service failsafe"
author "chromium-os-dev@chromium.org"
# By default we need cros-camera to start when all the built-in camera(s) are
# probed by the kernel, so that we can report the correct static built-in camera
# info to the camera clients. However, if any of the built-in cameras cannot be
# probed successfully (e.g. hardware failure), we still need cros-camera to run
# so users get to use external USB cameras.
# cros-camera has `respawn limit 10 60`. The failsafe is triggered when
# cros-camera fails to start after 10 retries in 60 seconds and transitions to
# `stopped`.
#
# When cros-camera is gracefully stopped, ${RESULT} is set to `ok`. We don't
# need to trigger the failsafe in this case (e.g. user running `stop
# cros-camera`, or cros-camera stops in pre-start because system-services
# isn't ready).
start on stopped cros-camera RESULT="failed"
# Make the camera jobs killable, because if it has a leak it's better to restart
# it than to OOM-panic.
oom score 0
env FORCE_START_CROS_CAMERA_PATH="/run/camera/force_start_cros_camera"
env EFFECTS_RUNNING_MARKER="/run/camera/effects_running"
script
# If the camera service starts crashing, it might be due to
# a bad or corrupted OpenCL cache in the effects pipeline.
# If the effects marker file is present, it means the effects
# system was enabled but the service didn't exit cleanly.
# In this scenario, dump out the OpenCL cache.
if [ -e "${EFFECTS_RUNNING_MARKER}" ]; then
rm -f -- /var/lib/ml_core/opencl_cache/* # croslint: disable: conditional delete as a failsafe
rm -f -- "${EFFECTS_RUNNING_MARKER}" # croslint: disable: conditional delete as a failsafe
fi
# We only want the failsafe to trigger the cros-camera service once, otherwise
# we may end up in a crash loop and spam the syslog.
if [ -f "${FORCE_START_CROS_CAMERA_PATH}" ]; then
stop
exit 0
fi
# We don't want to enable failsafe on test image so we can identify potential
# issue during tests.
if grep -q "CHROMEOS_RELEASE_TRACK=testimage-channel" "/etc/lsb-release"; then
logger -t cros-camera-failsafe \
"cros-camera-failsafe is disabled on test image"
stop
exit 0
fi
touch "${FORCE_START_CROS_CAMERA_PATH}"
initctl start cros-camera
end script