Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EB: Trigger container commands / deploy scripts on configuration change

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?

like image 408
JHH Avatar asked Sep 20 '25 23:09

JHH


1 Answers

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.

like image 117
Zags Avatar answered Sep 23 '25 11:09

Zags