Scott Zawalski | 20a9b58 | 2011-11-21 11:49:40 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # Author: Dale Curtis (dalecurtis@google.com) |
| 8 | # |
| 9 | # Small cron script which uses a PID file to check if Dev Server is running. If |
| 10 | # not, the Dev Server is started and the PID is recorded. |
| 11 | # |
| 12 | # Script is written with the layout of Kirkland test lab's Dev Server in mind. |
| 13 | # |
| 14 | |
| 15 | |
| 16 | # Path to Dev Server source code. |
| 17 | declare -r DEV_SERVER_PATH="/usr/local/google/chromeos/src/platform/dev/" |
| 18 | |
| 19 | # Path to Dev Server images directory. |
| 20 | declare -r IMAGES_PATH="/usr/local/google/images" |
| 21 | |
| 22 | # PID file location. |
| 23 | declare -r PID_FILE="/tmp/dev_server.pid" |
| 24 | |
| 25 | |
| 26 | function start_dev_server { |
| 27 | echo "Starting a new Dev Server instance..." |
| 28 | cd ${DEV_SERVER_PATH} |
Chris Sosa | ef81923 | 2012-08-21 15:08:21 -0700 | [diff] [blame^] | 29 | python devserver.py 8080 --archive_dir ${IMAGES_PATH} -t &>/dev/null& |
Scott Zawalski | 20a9b58 | 2011-11-21 11:49:40 -0800 | [diff] [blame] | 30 | echo $!>${PID_FILE} |
| 31 | } |
| 32 | |
| 33 | |
| 34 | # First check for PID file, then check if PID is valid. If either are false, |
| 35 | # start a new Dev Server instance. |
| 36 | if [ -f ${PID_FILE} ]; then |
| 37 | ps $(cat ${PID_FILE}) | grep -q devserver.py || start_dev_server |
| 38 | else |
| 39 | start_dev_server |
| 40 | fi |