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?
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
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.
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.
Related
Description: Ansible yum module doesn't install through control host, but local yum install works perfectly? What could cause such issue? I appreciate any response. Thank you guys. I worked on this 8 hours, I have researched various of things, and tried very different approaches. No success.
Node: Centos7 (newly installed), Control-Node: Ubuntu-LTS18.
Command:
ansible ansitest2 -i ../inv -b -m yum -a "name=epel-release state=present"
it can be any package though.
This fails, however at the bottom I can see that it found the package and tried to install it. ()
If I go to host itself and try to install it, it is successful. :
yum install epel-release -y
After spending almost 2 days on this, finally found answer, /etc/resolve.conf file needed to be updated with option rotate timeout:1,
So, if you have such issue, it is mainly about resolve.conf
man resolve.conf will give very good description.
I'm writing a basic script in bash to automatically install a few packages on new machines (basically, the first script to run on a new machine before doing anything else). I'm downloading openssh-server and python for example.
My goal is just to launch the script in sudo mode, wait a few minutes and get started. The only problem I'm facing is the machine requires the user to input "y" when needed and I can't find a way to bypass this.
This is just a sample of my script :
#!/bin/bash
sudo apt update
sudo apt install openssh-server
sudo apt-get install python3
what I expect is just run this command and let it roll without the user to have and put "y" when needed
sudo bash start-script.sh
Use the -y option of apt-get. From the apt-get man page:
-y, --yes, --assume-yes
Automatic yes to prompts; assume "yes" as answer to all prompts and
run non-interactively. If an undesirable situation, such as
changing a held package, trying to install a unauthenticated
package or removing an essential package occurs then apt-get will
abort. Configuration Item: APT::Get::Assume-Yes.
I just created rpm package which contains few shell scripts and My rpm executes those shell scripts in post installation step ( i.e %post section).
My RPM is created successfully and when I run
rpm -ivh myrpmfile.rpm RPM able to find my shell scripts and running them properly. Those scripts also install few other packages with yum so when yum try to install those packages it hangs with the following error
Warning: RPMDB altered outside of yum
Sometimes it hangs at the following state.
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
You can't call yum from your %post because the database is locked. If you need other packages installed, you set them as Required. If your RPM also installs the yum repo files, then you need to make them into two RPMs.
That warning is just because you used rpm directly "behind its back" and most likely is a red herring.
I have a shell script which checks if there is an internet connection (by pinging google), and then calls
yum install packageA packageB --assumeyes
How would I confirm that the packages were installed (or were already installed)? Do I make another yum call and parse the output (I presume this gets very complicated if the system is in another language)?
I've used the following method, which might not be foolproof, but seems to work:
Assuming the variable PACKAGES contains the list of packages you want to install, then:
Run yum -y install $PACKAGES (I assume if this is a script, you really want to pass -y to avoid prompting).
Check its exit status in order to detect some failure conditions.
Run rpm --query --queryformat "" $PACKAGES, which will output nothing for each package that was installed successfully, and will output package <name> is not installed for each failure.
Check its exit status, which appears to be the number of packages that were not successfully installed, i.e. will be 0 on success as usual.
This will only work if PACKAGES contains plain package names that yum is expected to find in a repository, not if it contains other things that yum accepts like URLs, file names or Provides: names.
Based on this random post, it looks like yum returns an error code to the shell. You can test this out by running a command and then immediately (as the next command) doing:
echo $?
That will print the previous command's return code. Success should be 0, failure of some kind nonzero. But that's just a guess since I don't have a box accessible to me at the moment. :)
By ping google.com does not ensure the yum repo you trying to connect is available
The command to check whether a package is already installed :-
yum list installed PACKAGE_NAME
When i try t install, i get error:
aptitude install hudson
The following NEW packages will be installed:
hudson
0 packages upgraded, 1 newly installed, 0 to remove and 279 not upgraded.
Need to get 38.8MB of archives. After unpacking 39.7GB will be used.
WARNING: untrusted versions of the following packages will be installed!
Untrusted packages could compromise your system's security.
You should only proceed with the installation if you are certain that
this is what you want to do.
hudson
Do you want to ignore this warning and proceed anyway?
To continue, enter "Yes"; to abort, enter "No": Yes
Get:1 http://hudson-ci.org/debian/ binary/ hudson 1.397 [38.8MB]
Fetched 1B in 0s (2B/s)
E: Failed to fetch http://hudson-ci.org/debian/binary/hudson_1.397_all.deb: Size mismatch
apt-get clean
apt-get update
apt-get install hudson
this should work.
This question is probably best posted to serverfault.com; but regardless; it appears the mirror you are using is busted and you most likely downloaded an error page (which is why the failure). Try doing an update for your repository to get the latest mirror information.
apt-get update
execute aptitude update first
I had the same problem.
I followed the steps here: http://makeitfaster.wordpress.com/2010/12/14/install-the-hudson-build-server-on-ubuntu-10-10-server/
Which then also failed at the "sudo dpkg --install /tmp/hudson.deb" line. Then I did this:
aptitude install openjdk-6-jre
At which point hudson finished installing and came on line.
I've got the same problem...
Need to get 38.8MB of archives. After
this operation, 39.7GB of additional
disk space will be used. WARNING: The
following packages cannot be
authenticated!
hudson Install these
packages without verification [y/N]? y
Get:1 http://hudson-ci.org/debian/
binary/ hudson 1.397 [38.8MB] Fetched
38.8MB in 59s (655kB/s)
Failed to fetch
http://hudson-ci.org/debian/binary/hudson_1.397_all.deb
Size mismatch E: Unable to fetch some
archives, maybe run apt-get update or
try with --fix-missing?
I have done
apt-get clean
apt-get update
apt-get install hudson
as root.
Still don't understand what the size mismatch is - I can't see any errors downloaded.
The main difference between me and the original poster is that I am downloading 38.8MB, but it still reports the wrong size.