db7e3b447f8871be5ffeebf09fcd56847a6dfec4
java/target/refreshInstance.sh
| ... | ... | @@ -70,10 +70,10 @@ checks () |
| 70 | 70 | |
| 71 | 71 | copy_user_data_to_tmp_file () |
| 72 | 72 | { |
| 73 | - echo "Reading user-data provided by Amazon instance data to $ec2EnvVars_tmpFile" |
|
| 73 | + echo "Reading user-data provided by Amazon instance data to ${ec2EnvVars_tmpFile}" |
|
| 74 | 74 | VARS=$(ec2-metadata -d | sed "s/user-data\: //g") |
| 75 | 75 | if [[ "$VARS" != "not available" ]]; then |
| 76 | - ec2-metadata -d | sed "s/user-data\: //g" >>"$ec2EnvVars_tmpFile" |
|
| 76 | + ec2-metadata -d | sed "s/user-data\: //g" >>"${ec2EnvVars_tmpFile}" |
|
| 77 | 77 | else |
| 78 | 78 | echo "No user data has been provided." |
| 79 | 79 | fi |
| ... | ... | @@ -83,7 +83,7 @@ copy_user_data_to_tmp_file () |
| 83 | 83 | activate_user_data () |
| 84 | 84 | { |
| 85 | 85 | # make sure to reload data |
| 86 | - source "$ec2EnvVars_tmpFile" |
|
| 86 | + source "${ec2EnvVars_tmpFile}" |
|
| 87 | 87 | INSTANCE_NAME=`ec2-metadata -i | cut -f2 -d " "` |
| 88 | 88 | INSTANCE_IP4=`ec2-metadata -v | cut -f2 -d " "` |
| 89 | 89 | INSTANCE_DNS=`ec2-metadata -p | cut -f2 -d " "` |
| ... | ... | @@ -110,7 +110,7 @@ append_user_data_to_envsh () |
| 110 | 110 | echo "INSTANCE_INTERNAL_IP4=`ec2-metadata -o | cut -f2 -d \" \"`" >> $SERVER_HOME/env.sh |
| 111 | 111 | echo "INSTANCE_DNS=`ec2-metadata -p | cut -f2 -d \" \"`" >> $SERVER_HOME/env.sh |
| 112 | 112 | # Append EC2 user data to env.sh file: |
| 113 | - cat "$ec2EnvVars_tmpFile" >>$SERVER_HOME/env.sh |
|
| 113 | + cat "${ec2EnvVars_tmpFile}" >>$SERVER_HOME/env.sh |
|
| 114 | 114 | |
| 115 | 115 | echo "INSTANCE_ID=\"$INSTANCE_NAME ($INSTANCE_IP4)\"" >> $SERVER_HOME/env.sh |
| 116 | 116 | echo "# User-Data: END" >> $SERVER_HOME/env.sh |
| ... | ... | @@ -237,6 +237,34 @@ deploy () |
| 237 | 237 | fi |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | +auto_install () |
|
| 241 | +{ |
|
| 242 | + # activate everything found in user data |
|
| 243 | + activate_user_data |
|
| 244 | + # Now build or fetch the correct release, based on activated user data: |
|
| 245 | + if [[ $BUILD_BEFORE_START = "True" ]]; then |
|
| 246 | + checkout_code |
|
| 247 | + build |
|
| 248 | + deploy |
|
| 249 | + else |
|
| 250 | + load_from_release_file |
|
| 251 | + fi |
|
| 252 | + # then download and install environment and append to env.sh |
|
| 253 | + install_environment |
|
| 254 | + # then append user data to env.sh as it shall take precedence over the installed environment's defaults |
|
| 255 | + append_user_data_to_envsh |
|
| 256 | + # then append the rules that compute defaults for variables not set elsewhere; this has to come last: |
|
| 257 | + append_default_envsh_rules |
|
| 258 | + # make sure to reload data, this time including defaults from release's env.sh, environment settings and user data |
|
| 259 | + source `pwd`/env.sh |
|
| 260 | + echo "" |
|
| 261 | + echo "INSTALL_FROM_RELEASE: $INSTALL_FROM_RELEASE" |
|
| 262 | + echo "DEPLOY_TO: $DEPLOY_TO" |
|
| 263 | + echo "BUILD_BEFORE_START: $BUILD_BEFORE_START" |
|
| 264 | + echo "USE_ENVRIONMENT: $USE_ENVIRONMENT" |
|
| 265 | + echo "" |
|
| 266 | +} |
|
| 267 | + |
|
| 240 | 268 | OPERATION=$1 |
| 241 | 269 | PARAM=$2 |
| 242 | 270 | |
| ... | ... | @@ -245,39 +273,20 @@ if [[ $OPERATION == "auto-install" ]]; then |
| 245 | 273 | if [[ ! -z "$ON_AMAZON" ]]; then |
| 246 | 274 | # first check and activate everything found in user data |
| 247 | 275 | copy_user_data_to_tmp_file |
| 248 | - activate_user_data |
|
| 249 | - # Now build or fetch the correct release, based on activated user data: |
|
| 250 | - if [[ $BUILD_BEFORE_START = "True" ]]; then |
|
| 251 | - checkout_code |
|
| 252 | - build |
|
| 253 | - deploy |
|
| 254 | - else |
|
| 255 | - load_from_release_file |
|
| 256 | - fi |
|
| 257 | - # then download and install environment and append to env.sh |
|
| 258 | - install_environment |
|
| 259 | - # then append user data to env.sh as it shall take precedence over the installed environment's defaults |
|
| 260 | - append_user_data_to_envsh |
|
| 261 | - # then append the rules that compute defaults for variables not set elsewhere; this has to come last: |
|
| 262 | - append_default_envsh_rules |
|
| 263 | - |
|
| 264 | - # make sure to reload data, this time including defaults from release's env.sh, environment settings and user data |
|
| 265 | - source `pwd`/env.sh |
|
| 266 | - |
|
| 267 | - echo "" |
|
| 268 | - echo "INSTALL_FROM_RELEASE: $INSTALL_FROM_RELEASE" |
|
| 269 | - echo "DEPLOY_TO: $DEPLOY_TO" |
|
| 270 | - echo "BUILD_BEFORE_START: $BUILD_BEFORE_START" |
|
| 271 | - echo "USE_ENVRIONMENT: $USE_ENVIRONMENT" |
|
| 272 | - echo "" |
|
| 276 | + auto_install |
|
| 273 | 277 | else |
| 274 | 278 | echo "This server does not seem to be running on Amazon! Automatic install only works on Amazon instances." |
| 275 | 279 | exit 1 |
| 276 | 280 | fi |
| 277 | 281 | |
| 282 | +elif [[ $OPERATION == "auto-install-from-stdin" ]]; then |
|
| 283 | + # copy stdin to user data tmp file, |
|
| 284 | + cat >"${ec2EnvVars_tmpFile}" |
|
| 285 | + # then auto-install |
|
| 286 | + auto_install |
|
| 287 | + |
|
| 278 | 288 | elif [[ $OPERATION == "install-release" ]]; then |
| 279 | 289 | INSTALL_FROM_RELEASE=$PARAM |
| 280 | - |
|
| 281 | 290 | # Honor the no-overrite setting if there is one |
| 282 | 291 | if [ -f $SERVER_HOME/no-overwrite ]; then |
| 283 | 292 | 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 |
| 348 | 357 | else |
| 349 | 358 | echo "Script to prepare a Java instance running on Amazon." |
| 350 | 359 | echo "" |
| 360 | + 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" |
|
| 361 | + 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." |
|
| 351 | 362 | echo "install-release <release>: Downloads the release specified by the second option and overwrites all code for this server. Preserves env.sh." |
| 352 | 363 | 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." |
| 353 | 364 | 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!" |
wiki/info/landscape/amazon-ec2.md
| ... | ... | @@ -200,9 +200,6 @@ Make sure to use the preconfigured environment from `http://releases.sapsailing. |
| 200 | 200 | ``` |
| 201 | 201 | INSTALL_FROM_RELEASE=(name-of-release) |
| 202 | 202 | USE_ENVIRONMENT=live-replica-server |
| 203 | -REPLICATE_MASTER_SERVLET_HOST=(IP of your master server or external -master hostname) |
|
| 204 | -REPLICATE_MASTER_SERVLET_PORT=(port your master is listening on for HTTP/HTTPS requests; defaults to 8888; use 443 for -master hostname) |
|
| 205 | -REPLICATE_MASTER_EXCHANGE_NAME=myspecificevent |
|
| 206 | 203 | # Provide authentication credentials for a user on the master permitted to replicate, either by username/password... |
| 207 | 204 | #REPLICATE_MASTER_USERNAME=(user for replicator login on master server having SERVER:REPLICATE:<server-name> permission) |
| 208 | 205 | #REPLICATE_MASTER_PASSWORD=(password of the user for replication login on master) |
| ... | ... | @@ -211,12 +208,13 @@ REPLICATE_MASTER_EXCHANGE_NAME=myspecificevent |
| 211 | 208 | # or by logging in to the master server using your web browser and then navigating to |
| 212 | 209 | # https://master-server.sapsailing.com/security/api/restsecurity/access_token |
| 213 | 210 | REPLICATE_MASTER_BEARER_TOKEN=(a bearer token allowing this master to replicate from your master) |
| 214 | -SERVER_NAME=MYSPECIFICEVENT |
|
| 215 | -MONGODB_URI="mongodb://mongo0.internal.sapsailing.com,mongo1.internal.sapsailing.com/myspecificevent-replica?replicaSet=live&retryWrites=true&readPreference=nearest" |
|
| 211 | +SERVER_NAME=myspecificevent |
|
| 216 | 212 | EVENT_ID={some-uuid-of-an-event-you-want-to-feature} |
| 217 | 213 | SERVER_STARTUP_NOTIFY=you@email.com |
| 218 | 214 | ``` |
| 219 | 215 | |
| 216 | +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`. |
|
| 217 | + |
|
| 220 | 218 | #### Setting up a new image (AMI) from scratch (more or less) |
| 221 | 219 | |
| 222 | 220 | See [here](/wiki/creating-ec2-image-from-scratch) |