blob: e4db69da5183d75ac176e1d0cb3d7e00358de463 [file] [log] [blame]
# Copyright 2016 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 based on config files"
author "chromium-os-dev@chromium.org"
start on started system-services
env CONFIG_DIR="/var/lib/servod"
pre-start script
# Create the config dir if it doesn't exist.
if [ ! -d $CONFIG_DIR ]; then
mkdir -p $CONFIG_DIR
fi
# If we have an existing config file, move it to the new style (config_$PORT).
OLD_CONFIG_FILE=${CONFIG_DIR}/config
PORT=9999
NEW_CONFIG_FILE=${OLD_CONFIG_FILE}_${PORT}
if [ -f $OLD_CONFIG_FILE -a ! -f $NEW_CONFIG_FILE ]; then
# We only copy it if the new config file doesn't exist and the existing
# old config file exists. This is to ensure backward compatibility so if we
# need to downgrade, the existing config file is there since the original
# servod.conf expects that file to be there.
#
# TODO(kevcheng): Get rid of this once the old style config is completely
# gone from fleet.
cp $OLD_CONFIG_FILE $NEW_CONFIG_FILE
fi
end script
script
# Config files are in the format config_$PORT, pull out the port and
# pass it in to the upstart job.
for PORT in $(ls ${CONFIG_DIR}/config_* | cut -d _ -f 2); do
start servod PORT=$PORT
done
end script