| # 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 "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" |
| |
| env FORCE_START_CROS_CAMERA_PATH="/run/camera/force_start_cros_camera" |
| |
| script |
| # 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 |