EB: Trigger container commands / deploy scripts on configuration change
Asked Answered
L

1

3

I am running my web server on Elastic Beanstalk, and using Papertrail for logging. I am using the official .ebextensions script to get papertrail set up during deployment, but I have a problem. I use environment variables as part of my hostname used as the sender when remote_syslog uploads logs to papertrail, and while this works fine during deployment, when the 01_set_logger_hostname container command is triggered, I run into problems whenever I change environment variables by modifying the environment's configuration, since it seems an eb config call will only restart the application server, not run any of the scripts run during deployment, including the ebextensions container commands.

"/tmp/set-logger-hostname.sh":
    mode: "00555"
    owner: root
    group: root
    encoding: plain
    content: |
      #!/bin/bash
      logger_config="/etc/log_files.yml"
      appname=`{ "Ref" : "AWSEBEnvironmentName" }`
      instid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
      myhostname=${SOME_VARIABLE}_${appname}_${instid}

      if [ -f $logger_config ]; then
        # Sub the hostname
        sed "s/hostname:.*/hostname: $myhostname/" -i $logger_config       
      fi

As you can see, since my hostname depends on ${SOME_VARIABLE}, I need to refresh the hostname whenever ${SOME_VARIABLE} is modified following eb config.

Is there a way to trigger a script to be run whenever an eb config command is run, so that I can not only restart my web application but also reconfigure and restart remote_syslog with the updated hostname?

Larrabee answered 1/6, 2018 at 11:55 Comment(0)
F
2

This is now possible on AWS Linux 2 based environments with Configuration deployment platform hooks.

For example, you can make a shell script .platform/confighooks/predeploy/predeploy.sh that will run on all configuration changes. Make sure that you make this file executable according to git, or Elastic Beanstalk will give you a permission denied error.

Fairfield answered 20/12, 2021 at 20:18 Comment(1)
I had a similar issue as OP pulling env variables into a Django app. I moved the relevant code to a hook in .platform/hooks/prebuild/env.sh and it now runs on AWS console config changes. I chose prebuild because it runs right after download and extraction of the app which was the ideal time for my use case.Arsenide

© 2022 - 2024 — McMap. All rights reserved.