blob: 032ad85e74fe16582afea7524414183a46eafcaf [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 "Metrics Library upstart file"
author "chromium-os-dev@chromium.org"
# The metrics library is used by several programs (daemons and others)
# to send UMA stats.
start on starting boot-services
pre-start script
# Create the file used as communication endpoint for metrics.
METRICS_DIR=/var/lib/metrics
EVENTS_FILE=${METRICS_DIR}/uma-events
perms=$(stat -c %a "${EVENTS_FILE}") || :
mkdir -p "${METRICS_DIR}"
if [ "${perms}" != 666 ]; then
# File does not exist or has wrong perms. This is not expected to happen,
# but we don't remove it unconditionally because it may already have
# accumulated samples.
if [ -e "${EVENTS_FILE}" ]; then
logger -t "${JOB}" "${EVENTS_FILE} has wrong perms (${perms}), removing"
rm "${EVENTS_FILE}"
fi
old_umask=$(umask)
umask 0
touch "${EVENTS_FILE}"
umask ${old_umask}
fi
chown chronos:chronos "${EVENTS_FILE}"
# Create all intermediate directories until external.
mkdir -p /run/metrics/external
# TRANSITION ONLY.
# TODO(semenzato) Remove after Chrome change, see issue 447256.
# Let Chrome read the metrics file from the old location.
ln -sf ${EVENTS_FILE} /run/metrics
# For reporting external flags to metrics.
chown -R metrics:metrics /run/metrics
end script