blob: 6321b82175db195dcd17b1610b5d06379d79cc03 [file] [log] [blame]
# Copyright (c) 2011 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.
# cros-disks upstart job
env CROS_DISKS_UID=213
env CROS_DISKS_GID=213
env CROS_DISKS_OPTS=''
# Set the default polling interval in milliseconds on block devices.
# This in-kernel polling mechanism is available since kernel 2.6.38.
# The poll timer slack is set to 25% in kernel (linux/block/genhd.c).
# With a polling interval <= 1 second, the system seems to react to
# eject requests from a CD-ROM drive more responsively.
env BLOCK_DEFAULT_POLL_MSECS=1000
env BLOCK_DEFAULT_POLL_MSECS_SYSFS_PATH=/sys/module/block/parameters/events_dfl_poll_msecs
# Minimum log level defined in base/logging.h.
# 0:INFO, 1:WARNING, 2:ERROR, 3:ERROR_REPORT, 4:FATAL
# -1:VLOG(1), -2:VLOG(2), etc
# Set to log only INFO or above by default.
env CROS_DISKS_LOG_LEVEL=1
start on starting system-services
stop on stopping system-services
pre-start script
# Set default polling interval on block devices.
# This only affects block devices with removable media, which do not
# support asynchronous media change/eject events.
if [ -f "${BLOCK_DEFAULT_POLL_MSECS_SYSFS_PATH}" ]; then
echo "${BLOCK_DEFAULT_POLL_MSECS}" > "${BLOCK_DEFAULT_POLL_MSECS_SYSFS_PATH}"
fi
# Load the FUSE module, which is a dependency for AVFS.
# cros-disks should still run even the FUSE module is failed to load.
logger -t "$UPSTART_JOB" "Loading FUSE module"
modprobe fuse || logger -t "$UPSTART_JOB" "Failed to load FUSE module"
end script
post-stop script
if [ -f "${BLOCK_DEFAULT_POLL_MSECS_SYSFS_PATH}" ]; then
# Disable default polling on block devices.
echo 0 > "${BLOCK_DEFAULT_POLL_MSECS_SYSFS_PATH}"
fi
end script
respawn
expect fork
# Run cros-disks under minijail as follows:
# - Enter new IPC (-l) namespace.
#
# - Remain in the original network namespace in order to join to the system
# DBus.
#
# - Remain in the original cgroup namespace as it isn't supported on systems
# running kernel 3.8. TODO(benchan): Put cros-disks in new cgroup namespace
# once all systems support it.
#
# - Temporarily skip new mount (-v) and PID (-p) namespace as cros-disks
# needs to access /home/user/<hash> for archive support, which isn't
# accessible inside a new mount namesapce. TODO(benchan): Put cros-disks in
# new mount and PID namespace after archive support in cros-disks is
# deprecated (chromium:707327).
#
# - To let upstart to track the cros-disks process properly according to the
# 'expect fork' stanza, minijail exits immediately after fork (-i) while
# cros-disks stays in foreground (--foreground) without daemonizing itself
# inside the new pid namespace.
#
# - Use -K to prevent minijail to remount the shared mount at /media private.
# TODO(benchan): Remove -K once minijail provides a finer control over
# what should be remounted private and what can remain shared (b:62056108).
#
# - TODO(benchan): Use -c to remove unnecessary capabilities from cros-disks.
exec minijail0 -i -l -- \
/opt/google/cros-disks/disks --foreground \
--log-level="${CROS_DISKS_LOG_LEVEL}" ${CROS_DISKS_OPTS}