| # Copyright 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 servod" |
| author "chromium-os-dev@chromium.org" |
| |
| start on started system-services |
| stop on stopping system-services |
| respawn |
| |
| # If you change the respawn limit, change the log rotation, below. |
| respawn limit 3 10 |
| |
| env PORT=9999 |
| |
| pre-start script |
| mkdir -p /var/lib/servod |
| for CMD in iptables ip6tables ; do |
| $CMD -A INPUT -p tcp --dport $PORT -j ACCEPT || |
| logger -t "${UPSTART_JOB}" "Failed to configure $CMD." |
| done |
| end script |
| |
| script |
| LOG=/var/log/servod.log |
| |
| # We set OLD to ".4" to correspond to the respawn limit of 3 |
| # above. That way, if we die from the respawn limit, we'll have |
| # logs from all failed respawns, plus the original log that |
| # presumably contains the first failure. |
| OLD=.4 |
| for NEW in .3 .2 .1 ''; do |
| if [ -f $LOG$NEW ]; then |
| mv -f $LOG$NEW $LOG$OLD |
| fi |
| OLD=$NEW |
| done |
| exec >$LOG 2>&1 |
| |
| if [ ! -f /var/lib/servod/config ]; then |
| logger -t "$UPSTART_JOB" "No configuration; terminating" |
| stop |
| exit 0 |
| fi |
| |
| . /var/lib/servod/config |
| if [ -z "$BOARD" ]; then |
| logger -t "$UPSTART_JOB" "No board specified; terminating" |
| stop |
| exit 0 |
| fi |
| |
| logger -t "$UPSTART_JOB" "Launching servod for $BOARD" |
| BOARD_FLAG="--board ${BOARD}" |
| |
| SERVOD=/usr/lib/python2.7/site-packages/servo/servod.py |
| exec python $SERVOD --host 0.0.0.0 $BOARD_FLAG --port $PORT |
| end script |
| |
| post-stop script |
| for CMD in iptables ip6tables ; do |
| $CMD -D INPUT -p tcp --dport $PORT -j ACCEPT || true |
| done |
| end script |