#!/bin/bash
#
# run-bridgedb
# -----------------
# This script is used to start an instance which has already been configured
# and installed.
#
# :authors: sysrqb <sysrqb@torproject.org> 0x017DD169EA793BE2
#           isis <isis@torproject.org> 0xA3ADB67A2CDB8B35
# :licence: This file is part of BridgeDB, please see the LICENSE file,
#           included with BridgeDB for more info.
# :copyright: (c) 2014-2015 The Tor Project, Inc.
#             (c) 2014-2015 Matthew Finkel
#             (c) 2014-2015 Isis Lovecruft
#-------------------------------------------------------------------------------

. /srv/bridges.torproject.org/etc/environment-production

. ${VIRTUALENV_ACTIVATE}
export PATH=${BIN_DIR}:${PATH}:/bin:/usr/bin

FLOG_PIDFILE=${RUN_DIR}/flog.pid

printf "Starting BridgeDB..."
if hash flog 2>/dev/null; then
    bridgedb -r ${RUN_DIR} -c ${BRIDGEDB_CONFIG} | flog -p ${FLOG_PIDFILE} ${BRIDGEDB_SERVER_LOGFILE} & disown
else
    bridgedb -r ${RUN_DIR} -c ${BRIDGEDB_CONFIG} < /dev/null >> ${BRIDGEDB_SERVER_LOGFILE} 2>&1 & disown
fi

STATUS="$?"
if test "$STATUS" == "0" ; then printf "\t\t[OK]\n" ; else printf "\t\t[FAIL]\n" ; fi
exit $STATUS
