mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 22:43:57 +00:00
bug4811: added a "auto-install-from-stdin" option to refreshInstance.sh
This commit is contained in:
1 parent
f018c2f3fe
commit
db7e3b447f
2 files changed
+44
-35
No files matched your search
@@ -70,10 +70,10 @@ checks ()
|
||||
|
||||
copy_user_data_to_tmp_file ()
|
||||
{
|
||||
echo "Reading user-data provided by Amazon instance data to $ec2EnvVars_tmpFile"
|
||||
echo "Reading user-data provided by Amazon instance data to ${ec2EnvVars_tmpFile}"
|
||||
VARS=$(ec2-metadata -d | sed "s/user-data\: //g")
|
||||
if [[ "$VARS" != "not available" ]]; then
|
||||
ec2-metadata -d | sed "s/user-data\: //g" >>"$ec2EnvVars_tmpFile"
|
||||
ec2-metadata -d | sed "s/user-data\: //g" >>"${ec2EnvVars_tmpFile}"
|
||||
else
|
||||
echo "No user data has been provided."
|
||||
fi
|
||||
@@ -83,7 +83,7 @@ copy_user_data_to_tmp_file ()
|
||||
activate_user_data ()
|
||||
{
|
||||
# make sure to reload data
|
||||
source "$ec2EnvVars_tmpFile"
|
||||
source "${ec2EnvVars_tmpFile}"
|
||||
INSTANCE_NAME=`ec2-metadata -i | cut -f2 -d " "`
|
||||
INSTANCE_IP4=`ec2-metadata -v | cut -f2 -d " "`
|
||||
INSTANCE_DNS=`ec2-metadata -p | cut -f2 -d " "`
|
||||
@@ -110,7 +110,7 @@ append_user_data_to_envsh ()
|
||||
echo "INSTANCE_INTERNAL_IP4=`ec2-metadata -o | cut -f2 -d \" \"`" >> $SERVER_HOME/env.sh
|
||||
echo "INSTANCE_DNS=`ec2-metadata -p | cut -f2 -d \" \"`" >> $SERVER_HOME/env.sh
|
||||
# Append EC2 user data to env.sh file:
|
||||
cat "$ec2EnvVars_tmpFile" >>$SERVER_HOME/env.sh
|
||||
cat "${ec2EnvVars_tmpFile}" >>$SERVER_HOME/env.sh
|
||||
|
||||
echo "INSTANCE_ID=\"$INSTANCE_NAME ($INSTANCE_IP4)\"" >> $SERVER_HOME/env.sh
|
||||
echo "# User-Data: END" >> $SERVER_HOME/env.sh
|
||||
@@ -237,6 +237,34 @@ deploy ()
|
||||
fi
|
||||
}
|
||||
|
||||
auto_install ()
|
||||
{
|
||||
# activate everything found in user data
|
||||
activate_user_data
|
||||
# Now build or fetch the correct release, based on activated user data:
|
||||
if [[ $BUILD_BEFORE_START = "True" ]]; then
|
||||
checkout_code
|
||||
build
|
||||
deploy
|
||||
else
|
||||
load_from_release_file
|
||||
fi
|
||||
# then download and install environment and append to env.sh
|
||||
install_environment
|
||||
# then append user data to env.sh as it shall take precedence over the installed environment's defaults
|
||||
append_user_data_to_envsh
|
||||
# then append the rules that compute defaults for variables not set elsewhere; this has to come last:
|
||||
append_default_envsh_rules
|
||||
# make sure to reload data, this time including defaults from release's env.sh, environment settings and user data
|
||||
source `pwd`/env.sh
|
||||
echo ""
|
||||
echo "INSTALL_FROM_RELEASE: $INSTALL_FROM_RELEASE"
|
||||
echo "DEPLOY_TO: $DEPLOY_TO"
|
||||
echo "BUILD_BEFORE_START: $BUILD_BEFORE_START"
|
||||
echo "USE_ENVRIONMENT: $USE_ENVIRONMENT"
|
||||
echo ""
|
||||
}
|
||||
|
||||
OPERATION=$1
|
||||
PARAM=$2
|
||||
|
||||
@@ -245,39 +273,20 @@ if [[ $OPERATION == "auto-install" ]]; then
|
||||
if [[ ! -z "$ON_AMAZON" ]]; then
|
||||
# first check and activate everything found in user data
|
||||
copy_user_data_to_tmp_file
|
||||
activate_user_data
|
||||
# Now build or fetch the correct release, based on activated user data:
|
||||
if [[ $BUILD_BEFORE_START = "True" ]]; then
|
||||
checkout_code
|
||||
build
|
||||
deploy
|
||||
else
|
||||
load_from_release_file
|
||||
fi
|
||||
# then download and install environment and append to env.sh
|
||||
install_environment
|
||||
# then append user data to env.sh as it shall take precedence over the installed environment's defaults
|
||||
append_user_data_to_envsh
|
||||
# then append the rules that compute defaults for variables not set elsewhere; this has to come last:
|
||||
append_default_envsh_rules
|
||||
|
||||
# make sure to reload data, this time including defaults from release's env.sh, environment settings and user data
|
||||
source `pwd`/env.sh
|
||||
|
||||
echo ""
|
||||
echo "INSTALL_FROM_RELEASE: $INSTALL_FROM_RELEASE"
|
||||
echo "DEPLOY_TO: $DEPLOY_TO"
|
||||
echo "BUILD_BEFORE_START: $BUILD_BEFORE_START"
|
||||
echo "USE_ENVRIONMENT: $USE_ENVIRONMENT"
|
||||
echo ""
|
||||
auto_install
|
||||
else
|
||||
echo "This server does not seem to be running on Amazon! Automatic install only works on Amazon instances."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [[ $OPERATION == "auto-install-from-stdin" ]]; then
|
||||
# copy stdin to user data tmp file,
|
||||
cat >"${ec2EnvVars_tmpFile}"
|
||||
# then auto-install
|
||||
auto_install
|
||||
|
||||
elif [[ $OPERATION == "install-release" ]]; then
|
||||
INSTALL_FROM_RELEASE=$PARAM
|
||||
|
||||
# Honor the no-overrite setting if there is one
|
||||
if [ -f $SERVER_HOME/no-overwrite ]; then
|
||||
echo "Found a no-overwrite file in the servers directory. Please remove it to complete this operation!"
|
||||
@@ -348,6 +357,8 @@ elif [[ $OPERATION == "install-user-data" ]]; then
|
||||
else
|
||||
echo "Script to prepare a Java instance running on Amazon."
|
||||
echo ""
|
||||
echo "auto-install: downloads, builds, or takes from a local file a release, unpacks it in the current directory and applies the environment, user data, and environment defaults to the env.sh file"
|
||||
echo "auto-install-from-stdin: like auto-install, only that the additional configuration data is sourced from standard input (stdin), not the AWS EC2 instance's user data."
|
||||
echo "install-release <release>: Downloads the release specified by the second option and overwrites all code for this server. Preserves env.sh."
|
||||
echo "install-local-release <release-file>: Installs the release file specified by the second option and overwrites all code for this server. Preserves env.sh."
|
||||
echo "install-env <environment>: Downloads and updates the environment with the one specified as a second option. Does NOT take into account Amazon user-data!"
|
||||
|
||||
@@ -200,9 +200,6 @@ Make sure to use the preconfigured environment from `http://releases.sapsailing.
|
||||
```
|
||||
INSTALL_FROM_RELEASE=(name-of-release)
|
||||
USE_ENVIRONMENT=live-replica-server
|
||||
REPLICATE_MASTER_SERVLET_HOST=(IP of your master server or external -master hostname)
|
||||
REPLICATE_MASTER_SERVLET_PORT=(port your master is listening on for HTTP/HTTPS requests; defaults to 8888; use 443 for -master hostname)
|
||||
REPLICATE_MASTER_EXCHANGE_NAME=myspecificevent
|
||||
# Provide authentication credentials for a user on the master permitted to replicate, either by username/password...
|
||||
#REPLICATE_MASTER_USERNAME=(user for replicator login on master server having SERVER:REPLICATE:<server-name> permission)
|
||||
#REPLICATE_MASTER_PASSWORD=(password of the user for replication login on master)
|
||||
@@ -211,12 +208,13 @@ REPLICATE_MASTER_EXCHANGE_NAME=myspecificevent
|
||||
# or by logging in to the master server using your web browser and then navigating to
|
||||
# https://master-server.sapsailing.com/security/api/restsecurity/access_token
|
||||
REPLICATE_MASTER_BEARER_TOKEN=(a bearer token allowing this master to replicate from your master)
|
||||
SERVER_NAME=MYSPECIFICEVENT
|
||||
MONGODB_URI="mongodb://mongo0.internal.sapsailing.com,mongo1.internal.sapsailing.com/myspecificevent-replica?replicaSet=live&retryWrites=true&readPreference=nearest"
|
||||
SERVER_NAME=myspecificevent
|
||||
EVENT_ID={some-uuid-of-an-event-you-want-to-feature}
|
||||
SERVER_STARTUP_NOTIFY=you@email.com
|
||||
```
|
||||
|
||||
This will automatically start replication from your master which is assumed to be reachable at `${SERVER_NAME}.sapsailing.com`. Adjust `REPLICATE_MASTER_SERVLET_HOST` and `REPLICATE_MASTER_SERVLET_PORT` accordingly if this is not the case. The RabbitMQ exchange to subscribe to is also defaulted with the `${SERVER_NAME}`, just like is the case for the outbound side on the master, defining this exchange. Each replica gets its own outbound RabbitMQ exchange by default, using the `${SERVER_NAME}` to which the replica's Amazon instance ID is appended, in case transitive replication should become a need. The database connection string (`MONGODB_URI`) defaults to master's DB with the database name extended by the suffix `-replica`.
|
||||
|
||||
#### Setting up a new image (AMI) from scratch (more or less)
|
||||
|
||||
See [here](/wiki/creating-ec2-image-from-scratch)
|
||||
|
||||
Reference in new issue
Block a user