| # 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 |
| |
| # Importing the TZ environment variable to allow the time zone to be changed |
| # for tests. |
| import TZ |
| |
| start on starting system-services |
| stop on stopping system-services |
| |
| pre-start script |
| # The TZ variable is only allowed to exist in test builds for running |
| # autotests. The existence, even if set to empty, of TZ interferes with the |
| # regular functioning of the system timezone. |
| if crossystem "cros_debug?0" && [ -n "${TZ+set}" ]; then |
| logger -t "${UPSTART_JOB}" "TZ variable set in non-debug mode" |
| exit 1 |
| fi |
| |
| # 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" |
| mkdir -p ${dirs} |
| chown avfs:avfs ${dirs} |
| chmod 0770 ${dirs} |
| |
| # /run/fuse is used to hold temporary directories for individual |
| # FUSE mount helpers invocations. |
| dirs="/run/fuse" |
| mkdir -p ${dirs} |
| chown cros-disks:cros-disks ${dirs} |
| chmod 0775 ${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). |
| # |
| # - Do not lock SECBIT_KEEP_CAPS (-B 0x20) such that nested minijail invocations |
| # can enable the bit again to pass capabilities. |
| # |
| exec minijail0 -u cros-disks -g cros-disks -G \ |
| -c cap_chown,cap_setgid,cap_setuid,cap_sys_admin,cap_sys_chroot,cap_mknod,cap_setpcap=e \ |
| --ambient -B 0x20 \ |
| -i -l -n \ |
| -- /usr/bin/cros-disks --foreground \ |
| --log_level="${CROS_DISKS_LOG_LEVEL}" ${CROS_DISKS_OPTS} |