blob: 427f051bdcb516f21674a866c6b53210884350d5 [file] [log] [blame]
# Copyright (c) 2010 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 "Start the Chromium OS power daemon"
author ""
start on x-started
stop on stopping ui or starting halt or starting reboot
env HOME=/home/chronos
env LOG_DIR=/var/log/power_manager
env RUN_DIR=/var/run/power_manager
env PREFS_DIR=/var/lib/power_manager
env DEFAULT_PREFS_DIR=/usr/share/power_manager
env XAUTHORITY=/home/chronos/.Xauthority
env DISPLAY=:0.0
env USER_ID=1000
respawn limit 3 10 # if the job respawns 3 times in 10 seconds, stop trying.
# Run a single mkdir if either of our dirs is missing.
if [ ! -d ${PREFS_DIR} -o ! -d ${LOG_DIR} ]; then
mkdir -p ${LOG_DIR} ${PREFS_DIR}
chown ${USER_ID} ${LOG_DIR} ${PREFS_DIR}
# Set ownership of backlight files; make sure to handle the case where
# no backlight files exist.
BACKLIGHTS=$(echo /sys/class/backlight/*/*)
if [ "${BACKLIGHTS}" = '/sys/class/backlight/*/*' ]; then
chown ${USER_ID} /sys/power/state ${BACKLIGHTS}
# Start the powerd in a jail with chronos UID; note that we need full path
# to powerd because minijail doesn't look at the PATH.
cd ${HOME}
exec minijail --uid=${USER_ID} -- \
/usr/bin/powerd \
--prefs_dir=${PREFS_DIR} \
--default_prefs_dir=${DEFAULT_PREFS_DIR} \
--log_dir=${LOG_DIR} \
--run_dir=${RUN_DIR} \
> ${LOG_DIR}/powerd.out 2>&1
end script