blob: b64b5da97360d37a2c456c196c11df4d25c6614d [file] [log] [blame]
# Copyright (c) 2012 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 user interface"
author "chromium-os-dev@chromium.org"
# Note, the 'start on' line is modified by the chromeos-factoryinstall
# ebuild. Please do not change it without also changing that
# reference.
#
# This job's post-stop script depends on cryptohomed being running;
# cryptohomed in turn depends on chapsd and dbus-daemon. This job's
# stop condition uses a special stop job to keep those processes
# from terminating until after this job has cleaned up. See the
# pre-shutdown job for more details.
# NB: Respawning is now handled by ui-respawn.conf, as the logic is
# more complex than upstart was designed to handle.
start on started boot-services
stop on starting pre-shutdown
# Enables chrome to renice background tabs (lower priority), and to set the
# priority of realtime threads to real time.
limit nice 20 20
limit rtprio 10 10
# Extend the grace period given to the session_manager before upstart decides
# it's gone unresponsive on job termination and must be killed. Chrome gets 12s
# (configured below) to shut down on devices with HDDs, so give a cushion.
kill timeout 20 # In seconds.
# Uncomment line below to output to VT02
#console output
# Directory where session manager logs are written and prefix of files there.
env UI_LOG_DIR=/var/log/ui
env UI_LOG_FILE=ui.LATEST
pre-start script
mkdir -p $UI_LOG_DIR
ln -sf ui.$(date +%Y%m%d-%H%M%S) $UI_LOG_DIR/$UI_LOG_FILE
# Set up cgroups for chrome. We create two task groups, one for at most one
# foreground renderer and one for all the background renderers and set the
# background group to a very low priority. We specifically do not set it to
# the lowest "2" such that other processes like the update-engine can be even
# lower. The default value is 1024.
CHROME_CPU_CGROUP_DIR=/sys/fs/cgroup/cpu/chrome_renderers
if [ ! -d $CHROME_CPU_CGROUP_DIR ]; then
mkdir -p ${CHROME_CPU_CGROUP_DIR}/foreground
mkdir -p ${CHROME_CPU_CGROUP_DIR}/background
echo "10" > ${CHROME_CPU_CGROUP_DIR}/background/cpu.shares
chown -R chronos ${CHROME_CPU_CGROUP_DIR}
fi
# Set up the renderer freezer. This is used during the suspend/resume cycle
# to freeze all the chrome renderers so that they don't take up a lot of power
# when the system comes up in dark resume
CHROME_FREEZER_CGROUP_DIR=/sys/fs/cgroup/freezer/chrome_renderers
if [ ! -d $CHROME_FREEZER_CGROUP_DIR ]; then
mkdir -p ${CHROME_FREEZER_CGROUP_DIR}
mkdir -p "${CHROME_FREEZER_CGROUP_DIR}/to_be_frozen"
chown -R chronos ${CHROME_FREEZER_CGROUP_DIR}
fi
# Set up the lucid sleep debug flag. This file only exists on devices that
# use kernel 3.14. When this sysfs entry is set to 1, the kernel will treat
# all resumes as dark resumes, relying on chrome and powerd to detect any user
# activity and to transition out of dark resume into regular resume. Since we
# are currently unable to distinguish the source that woke up the system, this
# is a temporary workaround to allow for apps and extensions to test lucid
# sleep functionality. Chrome will write 1 to this file only if the
# wake-on-packets flag is set.
#
# TODO(chirantan): Remove this once the firmware change and corresponding
# kernel change for querying the wakeup source is ready (crbug.com/414949).
DARK_RESUME_ALWAYS_FILE=/sys/power/dark_resume_always
if [ -e "${DARK_RESUME_ALWAYS_FILE}" ]; then
chown chronos "${DARK_RESUME_ALWAYS_FILE}"
fi
end script # pre-start
# This may be used to wrap the Chrome executable within another command
# instead of calling it directly. The flag's value will be split on whitespace
# into an absolute path and arguments, after which session_manager will add
# Chrome's arguments. For example:
#
# env CHROME_COMMAND_FLAG="--chrome-command=/usr/local/bin/strace /opt/google/chrome/chrome"
env CHROME_COMMAND_FLAG
exec session_manager \
"${CHROME_COMMAND_FLAG}" \
>"${UI_LOG_DIR}/${UI_LOG_FILE}" 2>&1
post-stop script
bootstat ui-post-stop
set +e
. /sbin/killers
# Terminate PKCS #11 services.
cryptohome --action=pkcs11_terminate
# Terminate any processes with files open on the mount point
# TODO(wad) parallelize with VFS/PID namespaces.
kill_with_open_files_on /home/chronos/u-*
# Make sure everything is going down. No exceptions.
# The loop is so that clever daemons can't evade the kill by
# racing us and killing us first; we'll just try over and over
# until we win the race, and kill with pid -1 is atomic with
# respect to process creation.
while ! sudo -u chronos kill -9 -- -1 ; do
sleep .1
done
# Check for still-living chronos processes and log their status.
ps -u chronos --no-headers -o pid,stat,args |
logger -i -t "${UPSTART_JOB}-unkillable" -p crit
bootstat other-processes-terminated
term_process '^X$'
bootstat x-terminated
cryptohome --action=unmount
bootstat cryptohome-unmounted
end script