| # Copyright (c) 2012 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 cromo daemon" |
| author "chromium-os-dev@chromium.org" |
| |
| # Carriers prefer modems to disconnect cleanly when systems are shutting |
| # down. cromo can take on the order of several seconds to exit. Stop the |
| # process on "starting pre-shutdown" so its exiting blocks the |
| # chromeos_shutdown script from running (jobs that "stop on stopping |
| # boot-services" or "stop on stopping system-services" may still be running |
| # in parallel with chromeos_shutdown if they do not exit quickly). |
| start on gobi_modem and started system-services |
| stop on starting pre-shutdown |
| kill timeout 5 |
| respawn |
| |
| pre-start script |
| mkdir -p /run/cromo |
| chown cromo:cromo /run/cromo |
| |
| if [ -h /var/lib/cromo ] ; then |
| logger -t "$UPSTART_JOB" "removing /var/lib/cromo symlink" |
| rm -f /var/lib/cromo |
| fi |
| mkdir -p /var/lib/cromo |
| chown root:root /var/lib/cromo |
| chmod 755 /var/lib/cromo |
| |
| config_group=/var/lib/cromo/madison-config-group |
| if [ -h $config_group ] ; then |
| logger -t "$UPSTART_JOB" "removing $config_group symlink" |
| rm -f $config_group |
| fi |
| |
| # Force upgrade from madison to madison-v2 |
| if [ -e $config_group ] ; then |
| if grep -q '^madison$' $config_group ; then |
| rm $config_group |
| fi |
| fi |
| if [ ! -e $config_group ] ; then |
| echo madison-v2 > $config_group |
| chown chronos:cromo $config_group |
| chmod 640 $config_group |
| fi |
| end script |
| |
| exec cromo |
| |
| # |
| # post-stop cleans up (resets) any gobi devices that are listed in the |
| # usb-devices file. On normal shutdown, gobi-cromo-plugin will empty |
| # the file and nothing will be reset. On abnormal termination, the |
| # file will contain a list of devices which require a reset. |
| # |
| post-stop script |
| logger -t "$UPSTART_JOB" "rebooting modems after abnormal termination" |
| for dev in $(cat /run/cromo/usb-devices); do |
| VALID='^[[:digit:].:-]\+$' |
| if ! echo "$dev" | grep -q "$VALID" ; then |
| logger -t "$UPSTART_JOB" "not rebooting invalid device $dev" |
| continue |
| fi |
| if [ ! -e /sys/bus/usb/devices/$dev ] ; then |
| logger -t "$UPSTART_JOB" "not rebooting missing device $dev" |
| continue |
| fi |
| logger -t "$UPSTART_JOB" "rebooting device $dev" |
| ( echo 0 > /sys/bus/usb/devices/$dev/authorized && |
| echo 1 > /sys/bus/usb/devices/$dev/authorized && |
| logger -t "$UPSTART_JOB" "rebooted device $dev" ) || |
| logger -t "$UPSTART_JOB" "failed to reboot device $dev" |
| done |
| end script |