AWS Beanstalk - 运行shell脚本,其中命令未成功执行

时间:2016-01-13 23:05:38

标签: linux amazon elastic-beanstalk ec2-ami

我在AWS beanstalk上运行应用程序并解决我遇到的问题。部署部署将创建一个shell脚本并执行它。执行命令时,第一行正常工作。它是一个简单的cat file.txt>> /etc/httpd/file.conf'命令。

第二行,我需要搜索一串文本并将其放在文件中,它永远不会成功运行。我可以以root身份手动运行脚本,没有任何问题。这是文件:

#! /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

当Beanstalk部署时,是否有人知道为什么sed命令在shell脚本中不起作用?

1 个答案:

答案 0 :(得分:1)

所以我没有意识到我们公司有AWS支持计划并与他们联系。我试图修改的文件也在beanstalk中进行了。因此,从技术上讲,我的文件正在更新,然后Beanstalk将他们的分阶段文件推送到生产中。您可以在beanstalk实例上运行此命令:

[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"
}

我试图更新的文件是最后一个。我需要针对该文件运行我的命令,然后亚马逊将推送它。