OPT_CONFIG=""
OPT_PID_DIR=""
OSRF_HOSTNAME=""
+OSRF_AUTO_HOST=""
# ---------------------------------------------------------------------------
# Make sure we're running as the correct user
-c full path to C configuration file (opensrf_core.xml)
-d store PID files in this directory
-l accept 'localhost' as the fully-qualified domain name
+ -g guess for use of 'localhost' based on configuration
Actions include:
start_router
# ---------------------------------------------------------------------------
# Load the command line options and set the global vars
# ---------------------------------------------------------------------------
-while getopts "a:d:c:lh" flag; do
+while getopts "a:d:c:lgh" flag; do
case $flag in
"a") OPT_ACTION="$OPTARG";;
"c") OPT_CONFIG="$OPTARG";;
"d") OPT_PID_DIR="$OPTARG";;
"l") export OSRF_HOSTNAME="localhost";;
+ "g") OSRF_AUTO_HOST="YES";;
"h"|*) usage;;
esac;
done
echo "Please specify the location of the opensrf_core.xml file using the -c flag";
exit 1;
fi;
+
+if [ "_$OSRF_HOSTNAME" == "_" -a "$OSRF_AUTO_HOST" == "YES" ]; then
+ temp_settings_file=$(xpath -q -e '/config/opensrf/settings_config/text()' $OPT_CONFIG 2>/dev/null || echo '')
+ if [ -n "$temp_settings_file" -a -r "$temp_settings_file" ]; then
+ temp_host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()')
+ temp_host_block=$(xpath -q -e "/opensrf/hosts/$temp_host" $temp_settings_file 2>/dev/null || echo '')
+ temp_localhost_block=$(xpath -q -e '/opensrf/hosts/localhost' $temp_settings_file 2>/dev/null || echo '')
+ if [ -z "$temp_host_block" -a -n "$temp_localhost_block" ]; then
+ echo "Guess: Found no $temp_host config, but found localhost. Using localhost."
+ export OSRF_HOSTNAME="localhost"
+ elif [ -z "$temp_host_block$temp_localhost_block" ]; then
+ echo "Found no host config and no localhost config."
+ exit 1;
+ fi
+ else
+ echo "Guess: Could not read $OPT_CONFIG. Maybe missing xpath?"
+ exit 1;
+ fi
+fi
+
[ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run/opensrf;
[ -z "$OPT_ACTION" ] && usage;