blob: f3ff3b423eb2abede3a1d7a44ca6974cd4bb36f6 [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_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"
# Create the /run/avfsroot directory tree on behalf of the non-privileged
# cros-disks process, which doesn't have the permission to modify the
# root-owned /run. The /run/avfsroot directory tree are used by the avfsd
# process for mounting archive files.
dirs="/run/avfsroot /run/avfsroot/media /run/avfsroot/users"
mkdir -p ${dirs}
chown avfs:avfs ${dirs}
chmod 0770 ${dirs}
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 namespace. TODO(benchan): Put cros-disks in
# new mount and PID namespace after archive support in cros-disks is
# deprecated (chromium:707327).
#
# - To let upstart 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.
#
# - Use -K to prevent Minijail from remounting the shared mount at /media as
# private.
# TODO(benchan): Remove -K once Minijail provides a finer control over
# what should be remounted private and what can remain shared (b:62056108).
#
# - Capabilities: CAP_CHOWN+CAP_SETGID+CAP_SETUID+CAP_SYS_MODULE+CAP_SYS_ADMIN
#
exec minijail0 -u cros-disks -g cros-disks -G -c 0x2100c1 --ambient -i -l -n \
-- /opt/google/cros-disks/disks --foreground \
--log_level="${CROS_DISKS_LOG_LEVEL}" ${CROS_DISKS_OPTS}