nocode
nocode

Reputation: 1316

AWS Beanstalk - running shell script where command does not execute successfully

I'm running an app on AWS beanstalk and troubleshooting an issue I'm having. Part of the deployment will create a shell script and execute it. When the command executes, the first line works fine. It's a simple 'cat file.txt >> /etc/httpd/file.conf' command.

The second line, I need to search for a string of text and place it within the file and it never runs successfully. I can run the script manually as root with no issues. Here is file:

#! /bin/bash
if ! grep -q 'Clickjacking' /etc/httpd/conf/httpd.conf ;
then
    cat /home/ec2-user/httpd-update.conf >> /etc/httpd/conf/httpd.conf
fi

# check if wsgi mod exists and insert into wsgi.conf if necessary
if ! grep -q 'TRACE|TRACK' /etc/httpd/conf.d/wsgi.conf;
then
  sed -i -e '/WSGIProcessGroup wsgi/r /home/ec2-user/wsgi-update.conf' /etc/httpd/conf.d/wsgi.conf
fi
sudo service httpd reload

Does anyone know why the sed command is not working in the shell script when Beanstalk deploys?

Upvotes: 0

Views: 948

Answers (1)

nocode
nocode

Reputation: 1316

So I didn't realize our company had AWS support plan and contacted them. The file I was trying to modify is also staged in beanstalk. So while technically my file was getting updated, Beanstalk was then pushing their staged file into production. You can run this command on the beanstalk instance:

[root@ip-10-0-90-168 ~]# /opt/elasticbeanstalk/bin/get-config container | python -mjson.tool
{
    "app_base_dir": "/opt/python/current",
    "app_deploy_dir": "/opt/python/current/app",
    "app_staging_base": "/opt/python/ondeck",
    "app_staging_dir": "/opt/python/ondeck/app",
    "app_user": "wsgi",
    "app_virtual_env": "/opt/python/run/venv",
    "base_path_dirs": "/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin",
    "bundle_dir": "/opt/python/bundle",
    "env_deploy_config": "/opt/python/current/env",
    "env_staging_config": "/opt/python/ondeck/env",
    "instance_port": "80",
    "python_version": "2.7",
    "source_bundle": "/opt/elasticbeanstalk/deploy/appsource/source_bundle",
    "wsgi_deploy_config": "/etc/httpd/conf.d/wsgi.conf",
    "wsgi_staging_config": "/opt/python/ondeck/wsgi.conf"
}

And the file I was trying to update is the last one. I need to run my command against that file and Amazon will then push that.

Upvotes: 1

Related Questions