8

I am using AWS Elastic Beanstalk on a Linux machine and need to install some fonts in .ebextensions:

container_commands:
  01_getfont: 
    command: sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm

That works well the 1st time, with the fonts installed.

The 2nd time when I deploy the EB again, it now gave me this error:

Application update failed at 2019-01-28T23:44:14Z with exit status 1 and error: container_command 01_getfont in .ebextensions/fonts.config failed.

Loaded plugins: priorities, update-motd, upgrade-helper
Examining /var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: webcore-fonts-3.0-1.noarch
/var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: does not update installed package.
Error: Nothing to do. 

How do I avoid getting that errors when that package has been installed on the same EC2 instance the 2nd time?

RichVel
  • 7,030
  • 6
  • 32
  • 48
Steven Yong
  • 5,163
  • 6
  • 35
  • 56

3 Answers3

6

I found out the answer to this problem later, posting it here for the benefits of others with similar issue.

I use reinstall instead:

sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm

This will work the 1st time and all other times of deployment.

Edit:

The above does not work as well as reinstall will fail if package is not installed. I ended up detecting if the package has been installed, if not, install it else re-install:

command: sudo yum -q list installed webcore-fonts.noarch &>/dev/null && sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm || sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
Steven Yong
  • 5,163
  • 6
  • 35
  • 56
3

Use the packages directive:

packages:
  rpm:
    webcore-fonts: http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm

This will handle not installed and already installed scenarios.

Jon Burgess
  • 2,035
  • 2
  • 17
  • 27
2

Yum can return a non-zero exit status for things that are not really errors, causing higher-level systems such as Elastic Beanstalk to think the script has failed.

In particular, yum sometimes says "Nothing to do" with exit status of 1 - this can mean various things but includes the case where required packages are already installed.

The way I work around this for scripts using yum is:

    yum -y install somepackage
    if [ $? -ne 1 ]; then   # Exit on any any error except 'nothing to do' 
      exit 0
    fi

A simpler way is just to ignore all errors by appending a true or exit 0 command - however, this is eventually going to bite you when the Yum repo is unreachable, or Yum has out of date metadata, etc.

Advanced tip

If you have several yum commands, or more error codes to handle, you might want to read up on the shell trap command, specifically on EXIT or ERR which lets you handle these cases in a single place, and potentially not exit on unwanted errors. See this stack for more on this.

Alternative for local installs

See this answer for more, including a simple alternative when installing RPMs that you have downloaded.

RichVel
  • 7,030
  • 6
  • 32
  • 48