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.
Related
To install mdbtools on an EC2 instance I entered the following:
curl http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mdbtools-0.7.1-3.el7.x86_64.rpm > mdbtools-0.7.1-3.el7.x86_64.rpm
rpm -Uvh mdbtools-0.7.1-3.el7.x86_64.rpm
yum -q install mdbtools -y
but I get the following
error: Failed dependencies:
libmdb.so.2()(64bit) is needed by mdbtools-0.7.1-3.el7.x86_64
libmdbsql.so.2()(64bit) is needed by mdbtools-0.7.1-3.el7.x86_64
mdbtools-libs = 0.7.1-3.el7 is needed by mdbtools-0.7.1-3.el7.x86_64
I have no idea how to fix these on EC2.
Any suggestions?
You're fetching a single package directly, then attempting to install it.
The package has a bunch of dependencies that can't be satisfied when it is taken outside a repository context.
What you should do, is install the EPEL repository configuration as detailed here.
Then let yum install the package while picking up whichever dependencies required:
yum install mdbtools
If for whatever reason, you want to install things without EPEL repository being configured, you will have one fun time fetching all the dependencies, which depends on a particular package :)
In this particular case you need at least mdbtools-libs, which direct URL is https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mdbtools-libs-0.7.1-3.el7.x86_64.rpm
Using a GCP Ubuntu 18.04 image, plain.
I use startup scripts on vm to automate the deployment of features and changes to the base image. I have one that start with the following :
#! /bin/bash
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
apt update
apt -y upgrade
export DEBIAN_FRONTEND=noninteractive
apt -y install libpam-dev libpam-ldap r-base
Unfortunatly on some machine that haven't ran in a while, I get the following error:
From /var/log/syslog :
startup-script: INFO startup-script: dpkg: error: dpkg frontend is locked by another process
From my investigation I can see that the process unattended upgrades is locking the file because it is doing the automatic security updates to the system. If I let the automatic upgrades complete and launch the script manually, everything runs just fine.
Is there a way to delay the execution of the startup script so that it starts after unattended upgrades is done? I mean, something that is more reliable than a simple wait command.
The startup script is configured via the metadata of the vm per GCP documentation.
Thanks a lot and have a great day.
You can have your script wait until the dpkg lock is no longer held. This AskUbuntu answer suggests a solution using fuser to see if the lock file is in use by another process:
#!/bin/bash
while fuser /var/lib/dpkg/lock >& /dev/null; do
echo "waiting for other package installs to complete..."
sleep 1
done
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
apt update
apt -y upgrade
export DEBIAN_FRONTEND=noninteractive
apt -y install libpam-dev libpam-ldap r-base
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.
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
I'm writing a Bash script that sets up a Drupal development environment for people using Ubuntu. To test this out I've installed a fresh copy of Ubuntu in VirtualBox and am constantly using the snapshot feature to get back my fresh install after every run of the script.
Currently however my script is re-downloading all the packages that need to be installed every time I run the script. Is there a way I can get apt-get to install these packages from local storage?
Perhaps downloading them, but not installing them at once. Taking a snapshot then, and then usage of apt-get that will use the local packages that were downloaded.
How would I go about doing this? Is there perhaps some apt-get magic that will do the trick?
apt-get --download-only install should do the trick.
Then make the snapshot, then run apt-get install again without --download-only.