xref: /aosp_15_r20/external/autotest/site_utils/admin/start_dev_server.sh (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
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 ([email protected])
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.
17declare -r DEV_SERVER_PATH="/usr/local/google/chromeos/src/platform/dev/"
18
19# Path to Dev Server images directory.
20declare -r IMAGES_PATH="/usr/local/google/images"
21
22# PID file location.
23declare -r PID_FILE="/tmp/dev_server.pid"
24
25
26function start_dev_server {
27  echo "Starting a new Dev Server instance..."
28  cd ${DEV_SERVER_PATH}
29  python devserver.py 8080 --archive_dir ${IMAGES_PATH} -t &>/dev/null&
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.
36if [ -f ${PID_FILE} ]; then
37  ps $(cat ${PID_FILE}) | grep -q devserver.py || start_dev_server
38else
39  start_dev_server
40fi
41