blob: b28368fb92a48ef28414c0536acb5542dd20d3fd [file] [log] [blame]
# Copyright (c) 2014 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 "Mount and setup moblab external storage."
author "chromium-os-dev@chromium.org"
start on started cros-disks and started moblab-database-init
normal exit 0
env MOUNT_DIR=/mnt/moblab
env EXTERNAL_RESULTS_DIR=/mnt/moblab/results
env ATEST_RESULTS_DIR=/usr/local/autotest/results
export ATEST_RESULTS_DIR
env STATIC_DIR=/mnt/moblab/static
export STATIC_DIR
env LOCAL_STORAGE_DIR=/usr/local/moblab-storage
env MIN_STATEFUL_DISKSPACE=32000000
script
mkdir -p /var/log/bootup/
exec >>/var/log/bootup/${UPSTART_JOB}.log 2>&1
set -x
logger -t "${UPSTART_JOB}" "Starting"
# REQUIRES A USB DRIVE WITH LABEL "MOBLAB-STORAGE"
sleep 1
usb_drive=$(readlink -f /dev/disk/by-label/MOBLAB-STORAGE)
if [ -e "${usb_drive}" ]; then
logger -t "${UPSTART_JOB}" "Mounting external storage using ${usb_drive}."
umount -A "${usb_drive}" || :
/sbin/e2fsck -p "${usb_drive}" || :
if ! mount "${usb_drive}" "${MOUNT_DIR}" -o exec,dev,nosuid; then
logger -t "${UPSTART_JOB}" "Mounting of ${usb_drive} onto ${MOUNT_DIR}"
logger -t "${UPSTART_JOB}" "failed. Please reconnect drive and reboot."
exit 1
fi
else
logger -t "${UPSTART_JOB}" "No disk labeled MOBLAB-STORAGE found!"
local_part=$(dirname "${LOCAL_STORAGE_DIR}")
diskspace=$(df "${local_part}" | awk '!/Filesystem/ { print $4 }')
if [ ${diskspace} -lt ${MIN_STATEFUL_DISKSPACE} ]; then
logger -t "${UPSTART_JOB}" "Moblab will not launch. Please insert a"
logger -t "${UPSTART_JOB}" "properly configured drive and reboot."
exit 1
fi
logger -t "${UPSTART_JOB}" "Moblab will launch using internal disk space."
mkdir -p "${LOCAL_STORAGE_DIR}"
logger -t "${UPSTART_JOB}" "Remounting /usr/local/ with dev permissions."
mount -o remount,dev /usr/local
mount --bind "${LOCAL_STORAGE_DIR}" "${MOUNT_DIR}"
fi
mkdir -p "${EXTERNAL_RESULTS_DIR}"
chown -R moblab:moblab "${EXTERNAL_RESULTS_DIR}"
# If the old results directory exists copy over the files and delete it.
if [ -e "${ATEST_RESULTS_DIR}" -a ! -L "${ATEST_RESULTS_DIR}" ]; then
logger -t "${UPSTART_JOB}" "Copying results directory."
cp -r "${ATEST_RESULTS_DIR}/" "${MOUNT_DIR}"
rm -rf "${ATEST_RESULTS_DIR}"
fi
# Create the results directory symlink if it does not exist.
if [ ! -e "${ATEST_RESULTS_DIR}" ]; then
logger -t "${UPSTART_JOB}" "Creating autotest results dir symlink."
ln -s "${EXTERNAL_RESULTS_DIR}" "${ATEST_RESULTS_DIR}"
fi
# If the database is empty clear out any old files in the results directory.
jobcount="$(mysql -u root -pmoblab_db_passwd -D chromeos_autotest_db \
-e 'select count(*) from afe_jobs' | tail -1)"
if [ "${jobcount}" = "0" ]; then
rm -rf "${EXTERNAL_RESULTS_DIR}"/*
fi
mkdir -p "${STATIC_DIR}"
chown moblab:moblab "${MOUNT_DIR}" || :
chown -R moblab:moblab "${MOUNT_DIR}/static" || :
chown -R moblab:moblab "${MOUNT_DIR}/results" || :
logger -t "${UPSTART_JOB}" "Ending."
end script