Commit 6e3bf290 authored by Michael Hanselmann's avatar Michael Hanselmann

Cleanup of build-time shell variable replacements

Instead of having a different set in (almost) every shell script, this
inserts the most commonly used variables at build time. This way the
code for injecting a root directory for virtual clusters also is just
needed once.

I chose inserting the variables using “sed” at build time over a runtime
script as the latter would need to be located from within the script and
the path would be different depending on the environment (unittest vs.
actual installation).
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 6a5e841d
......@@ -23,6 +23,7 @@
/autotools/missing
/autotools/py-compile
/autotools/replace_vars.sed
/autotools/shell-env-init
/config.log
/config.status
/configure
......
......@@ -31,6 +31,7 @@ DOCPP = $(top_srcdir)/autotools/docpp
REPLACE_VARS_SED = autotools/replace_vars.sed
CONVERT_CONSTANTS = $(top_srcdir)/autotools/convert-constants
BUILD_RPC = $(top_srcdir)/autotools/build-rpc
SHELL_ENV_INIT = autotools/shell-env-init
# Note: these are automake-specific variables, and must be named after
# the directory + 'dir' suffix
......@@ -150,6 +151,7 @@ CLEANFILES = \
$(PYTHON_BOOTSTRAP) \
epydoc.conf \
$(REPLACE_VARS_SED) \
$(SHELL_ENV_INIT) \
daemons/daemon-util \
daemons/ganeti-cleaner \
devel/upload \
......@@ -1271,7 +1273,20 @@ lib/_vcsversion.py: Makefile vcs-version | stamp-directories
lib/_generated_rpc.py: lib/rpc_defs.py $(BUILD_RPC)
PYTHONPATH=. $(RUN_IN_TEMPDIR) $(CURDIR)/$(BUILD_RPC) lib/rpc_defs.py > $@
$(REPLACE_VARS_SED): Makefile stamp-directories
$(SHELL_ENV_INIT): Makefile stamp-directories
set -e; \
{ echo '# Allow overriding for tests'; \
echo 'readonly LOCALSTATEDIR=$${LOCALSTATEDIR:-$${GANETI_ROOTDIR:-}$(localstatedir)}'; \
echo 'readonly SYSCONFDIR=$${SYSCONFDIR:-$${GANETI_ROOTDIR:-}$(sysconfdir)}'; \
echo; \
echo 'readonly PKGLIBDIR=$(pkglibdir)'; \
echo 'readonly LOG_DIR="$$LOCALSTATEDIR/log/ganeti"'; \
echo 'readonly RUN_DIR="$$LOCALSTATEDIR/run/ganeti"'; \
echo 'readonly DATA_DIR="$$LOCALSTATEDIR/lib/ganeti"'; \
echo 'readonly CONF_DIR="$$SYSCONFDIR/ganeti"'; \
} > $@
$(REPLACE_VARS_SED): $(SHELL_ENV_INIT) Makefile stamp-directories
set -e; \
{ echo 's#@PREFIX@#$(prefix)#g'; \
echo 's#@SYSCONFDIR@#$(sysconfdir)#g'; \
......@@ -1299,6 +1314,11 @@ $(REPLACE_VARS_SED): Makefile stamp-directories
echo 's#@CUSTOM_ENABLE_CONFD@#$(ENABLE_CONFD)#g'; \
echo 's#@MODULES@#$(strip $(lint_python_code))#g'; \
echo 's#@ENABLE_SPLIT_QUERY@#$(ENABLE_SPLIT_QUERY)#g'; \
echo; \
echo '/^@SHELL_ENV_INIT@$$/ {'; \
echo ' r $(SHELL_ENV_INIT)'; \
echo ' d'; \
echo '}'; \
} > $@
# Using deferred evaluation
......
......@@ -20,8 +20,9 @@
set -e
readonly defaults_file="${GANETI_ROOTDIR}@SYSCONFDIR@/default/ganeti"
readonly localstatedir="${GANETI_ROOTDIR}@LOCALSTATEDIR@"
@SHELL_ENV_INIT@
readonly defaults_file="$SYSCONFDIR/default/ganeti"
# This is a list of all daemons and the order in which they're started. The
# order is important as there are dependencies between them. On shutdown,
......@@ -57,7 +58,7 @@ _ignore_error() {
}
_daemon_pidfile() {
echo "$localstatedir/run/ganeti/$1.pid"
echo "$RUN_DIR/$1.pid"
}
_daemon_executable() {
......@@ -86,7 +87,7 @@ _daemon_usergroup() {
# Checks whether the local machine is part of a cluster
check_config() {
local server_pem=$localstatedir/lib/ganeti/server.pem
local server_pem=$DATA_DIR/server.pem
local fname
for fname in $server_pem; do
......
#!/bin/bash
#
# Copyright (C) 2009, 2010, 2011 Google Inc.
# Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -18,7 +18,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
set -e -u
@SHELL_ENV_INIT@
# Overridden by unittest
: ${CHECK_CERT_EXPIRED:=$PKGLIBDIR/check-cert-expired}
readonly CLEANER_LOG_DIR=$LOG_DIR/cleaner
readonly QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive
readonly CRYPTO_DIR=$RUN_DIR/crypto
in_cluster() {
[[ -e $DATA_DIR/ssconf_master_node ]]
......@@ -60,15 +69,6 @@ cleanup_watcher() {
xargs -r0 rm -vf
}
# Overridden by unittest
: ${LOCALSTATEDIR:=@LOCALSTATEDIR@}
: ${CHECK_CERT_EXPIRED:=@PKGLIBDIR@/check-cert-expired}
DATA_DIR=$LOCALSTATEDIR/lib/ganeti
CLEANER_LOG_DIR=$LOCALSTATEDIR/log/ganeti/cleaner
QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive
CRYPTO_DIR=$LOCALSTATEDIR/run/ganeti/crypto
# Define how many days archived jobs should be left alone
REMOVE_AFTER=21
......
......@@ -18,6 +18,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
@SHELL_ENV_INIT@
if [ -z "$INTERFACE" ]; then
echo "No network interface specified"
exit 1
......@@ -29,8 +31,8 @@ if [ -z "$MODE" ]; then
fi
# Execute the user-supplied network script, if applicable
if [ -x "@SYSCONFDIR@/ganeti/kvm-vif-bridge" ]; then
exec @SYSCONFDIR@/ganeti/kvm-vif-bridge
if [ -x "$CONF_DIR/kvm-vif-bridge" ]; then
exec $CONF_DIR/kvm-vif-bridge
fi
if [ "$MODE" = "bridged" ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment