Как исправить вывод '[stderr]' из команды sed в скрипте BeforeInstall при записи в файл php.ini для активации расширения imagick php? - PullRequest
1 голос
/ 02 июля 2019

Попытка использовать AWS CodeDeploy для приложения PHP Symfony.

Возникла проблема со сценарием BeforeInstall.

BeforeInstall Script (установить зависимости сервера), показанный ниже.

Сценарий выполняется от имени пользователя root, поэтому неясно, существует ли проблема с разрешениями.

Я попытался запустить альтернативную версию с sudo sed... безрезультатно.

appspec.yml

version: 0.0
os: linux 
files:
  - source: content/
    destination: /var/www/html/
hooks:
  BeforeInstall:
    - location: scripts/install_server_dependencies.sh
      timeout: 1000
      runas: root
  AfterInstall:
    - location: scripts/install_app_dependencies.sh
      timeout: 1000
      runas: root
  ApplicationStart:
    - location: scripts/start_server.sh
      timeout: 300
      runas: root
  ApplicationStop:
    - location: scripts/stop_server.sh
      timeout: 300
      runas: root

install_server_dependencies.sh

#!/bin/bash

# Navigate to public web directory
cd /var/www/html/

# Install Server Dependencies
yum -y update
yum -y install httpd24
yum -y install php73
yum -y install php73-devel
yum -y install php73-mysql
yum -y install php73-pgsql
yum -y install php73-pdo
yum -y install php73-mbstring
yum -y install php73-mcrypt 
yum -y install php73-pecl-gd
yum -y install php-pecl-imagick
yum -y install ImageMagick

# Store PHP Initialization file location
PHP_INI_PATH='/etc/php-7.3.d/php.ini' 

# Activate extensions
if ! grep -Fxq 'extension=imagick.so' ${PHP_INI_PATH}; then
    module_settings=$(cat ${PHP_INI_PATH} | grep -n '; Module Settings ;' | grep -o '^[0-9]*')
    dynamic_extensions=$((module_settings - 2))
    sed -i ${dynamic_extensions}'i\'$'\n''extension=imagick.so'$'\n' ${PHP_INI_PATH}
fi

Я ожидал, что выходные данные установят зависимости сервера и активируют расширение imagick до того, как сценарий AfterInstall выполнит установку composer.

Следующий вывод отображается в консоли CodeDeploy.

Error code
ScriptFailed
Script name
scripts/install_server_dependencies.sh
Message
Script at specified location: scripts/install_server_dependencies.sh run as user root failed with exit code 4
[stderr] --follow-symlinks
[stderr] follow symlinks when processing in place; hard links
[stderr] will still be broken.
[stderr] -i[SUFFIX], --in-place[=SUFFIX]
[stderr] edit files in place (makes backup if extension supplied).
[stderr] The default operation mode is to break symbolic and hard links.
[stderr] This can be changed with --follow-symlinks and --copy.
[stderr] -c, --copy
[stderr] use copy instead of rename when shuffling files in -i mode.
[stderr] While this will avoid breaking links (symbolic or hard), the
[stderr] resulting editing operation is not atomic. This is rarely
[stderr] the desired mode; --follow-symlinks is usually enough, and
[stderr] it is both faster and more secure.
[stderr] -l N, --line-length=N
[stderr] specify the desired line-wrap length for the `l' command
[stderr] --posix
[stderr] disable all GNU extensions.
[stderr] -r, --regexp-extended
[stderr] use extended regular expressions in the script.
[stderr] -s, --separate
[stderr] consider files as separate rather than as a single continuous
[stderr] long stream.
[stderr] -u, --unbuffered
[stderr] load minimal amounts of data from the input files and flush
[stderr] the output buffers more often
[stderr] --help display this help and exit
[stderr] --version output version information and exit
[stderr]
[stderr]If no -e, --expression, -f, or --file option is given, then the first
[stderr]non-option argument is taken as the sed script to interpret. All
[stderr]remaining arguments are names of input files; if no input files are
[stderr]specified, then the standard input is read.
[stderr]
[stderr]GNU sed home page: <http://www.gnu.org/software/sed/>.
[stderr]General help using GNU software: <http://www.gnu.org/gethelp/>.
...