Installing a custom RPM hangs when trying to run a post-install script - linux

I'm building an RPM with my own code and am running into an issue where the RPM is hanging when I install it with yum if I try to launch something as part of the post-install script. For some background, this is a virtual appliance where we've replaced the shell with a program with minimal configuration options. Previously, I couldn't get the program to load via the post-install options in my spec file; it causes the 'installing' line during a yum install to hang. I put a bandaid on it by having a reboot occur. I need this menu to load after installation, but everything I've tried results in yum hanging on the 'installing' line. My latest attempt; using the trap command, causes the same hang. Does anyone have any other ideas?
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
%description
Installs the program.
%prep
%setup -q
%install
rsync -ar /home/makerpm/rpmbuild/BUILD/%{name}-%{version}/ /home/makerpm/rpmbuild/BUILDROOT/%{name}-%{version}-%{release}.x86_64
find $RPM_BUILD_ROOT -not -type d -printf "%%%attr(%%m,root,root) %%p\n" | sed -e "s|$RPM_BUILD_ROOT||g" > %{_tmppath}/%{name}_contents.txt
%clean
rm -rf ${RPM_BUILD_ROOT}
rm -rf %{_tmppath}/*
rm -rf ${RPM_BUILD_DIR}/*
%changelog
* Sun Jan 25 2014 - %{version} - Modified menu with trap ability so the first reboot isn't required.
%post
function finish {
/bin/launcher
}
chmod 755 /bin/launcher
cat /etc/shells | grep "/bin/launcher"
if [ $? -eq 1 ]
then
echo "/bin/bash" >> /etc/shells
fi
chsh -s /bin/launcher root
trap finish EXIT
#List of all files to be extracted
%files -f %{_tmppath}/%{name}_contents.txt

Related

Jira doesn't seem to be installing on my EC2 instance at all: Failed to start jira.service: Unit jira.service not found

I'm trying to run a user-data script to install Jira on my RHEL 8 EC2 instance. When I SSH into my instance and run ps -ef | grep jira which I found on their website it returns this in my terminal
ec2-user 5256 5199 0 20:39 pts/0 00:00:00 grep --color=auto jira
I also try running this command in my terminal to start Jira sudo systemctl start jira and this is the error I get Failed to start jira.service: Unit jira.service not found
I'm not too sure what's causing Jira not to be installed or why I can't start it manually when I SSH into my instance- here's my user-data script that I'm using to install jira
#!/usr/bin/env bash
set \
-o nounset \
-o pipefail \
-o errexit
echo "===== Downloading Jira ====="
cd ~
wget https://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-software-8.22.4-x64.bin
chmod +x atlassian-jira-software-8.22.4-x64.bin
wget -O ~/jira.bin ${jira_dl_url}
cat <<\EOF >> ~/jira.varfile
app.confHome=/var/atlassian/application-data/jira
app.install.service$Boolean=false
portChoice=custom
httpPort$Long=8080
rmiPort$Long=8443
launch.application$Boolean=false
sys.adminRights$Boolean=true
sys.confirmedUpdateInstallationString=false
sys.installationDir=/opt/atlassian/jira
sys.languageId=en
EOF
echo "done"
echo "===== Modify Jira Permissions ====="
chmod +x ~/jira.bin
echo "===== Start Jira Install ====="
sudo ./atlassian-jira-software-8.22.4-x64.bin -q
#sudo ~/jira.bin -q -varfile ~/jira.varfile
#sudo /opt/atlassian/jira/bin/startup.sh
echo "===== Stopping Jira Service ====="
sudo systemctl stop jira
echo "====== Change Ownership to Jira user ========="
sudo chown -R jira:jira /opt/atlassian/jira
sudo chown -R jira:jira /var/atlassian/application-data/jira
echo "===== Cleaning up Jira Files ====="
rm -f ~/jira.bin
rm -f ~/jira.varfile
chmod 750 /opt/atlassian/jira/logs/

Creating a docker Base Image

I have a private Linux distribution (based on redhat7).
I have an ISO file which holds the installation of that distribution, which can be used to install the OS on a clear system only.
I have some programs I would like to run as images on docker, each program on a different image.
Each program can only run on my Linux environment and so I am looking for a way to create the appropriate images, so they can be ran under docker.
I tried following Solomon instructions here:
mkdir rootfs
mount -o loop /path/to/iso rootfs
tar -C rootfs -c . | docker import - rich/mybase
But I don't know how to proceed. I can't run any command since the machine isn't running yet (no /bin/bash/ etc.)
How can I open the installation shell?
Is there a better way to run programs via docker on a private Linux distribution?
(Just to be clear, the programs can run only on that specific OS and that OS can only be installed on a clear machine. Not sure if I need a base image but I'd like to run these programs with Docker and that is possible only over this OS)
I ran into many questions like mine (like this) but I couldn't find answer that helped me.
Assumption
Server A where the ISO will be mount
Server R your private repositoy
Server N where container will be run
All server can connect to server R.
How to
build a base image as mentioned in your OP (named base/myimage)
Push the image to your private repository https://docs.docker.com/registry/deploying/
Create application images from your base base/myimage then push them to your private repo
From Server N, run the application image
docker run application/myapp
This script is from the official Docker contrib repo. It's used to create CentOS images from scratch. It should work with any Redhat/Centos based system and gives you plenty of control over the various steps. Anything beyond that you can then modify post-base-image through a Dockerfile.
The file is here
#!/usr/bin/env bash
#
# Create a base CentOS Docker image.
#
# This script is useful on systems with yum installed (e.g., building
# a CentOS image on CentOS). See contrib/mkimage-rinse.sh for a way
# to build CentOS images on other systems.
usage() {
cat <<EOOPTS
$(basename $0) [OPTIONS] <name>
OPTIONS:
-p "<packages>" The list of packages to install in the container.
The default is blank.
-g "<groups>" The groups of packages to install in the container.
The default is "Core".
-y <yumconf> The path to the yum config to install packages from. The
default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
EOOPTS
exit 1
}
# option defaults
yum_config=/etc/yum.conf
if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
yum_config=/etc/dnf/dnf.conf
alias yum=dnf
fi
install_groups="Core"
while getopts ":y:p:g:h" opt; do
case $opt in
y)
yum_config=$OPTARG
;;
h)
usage
;;
p)
install_packages="$OPTARG"
;;
g)
install_groups="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG"
usage
;;
esac
done
shift $((OPTIND - 1))
name=$1
if [[ -z $name ]]; then
usage
fi
target=$(mktemp -d --tmpdir $(basename $0).XXXXXX)
set -x
mkdir -m 755 "$target"/dev
mknod -m 600 "$target"/dev/console c 5 1
mknod -m 600 "$target"/dev/initctl p
mknod -m 666 "$target"/dev/full c 1 7
mknod -m 666 "$target"/dev/null c 1 3
mknod -m 666 "$target"/dev/ptmx c 5 2
mknod -m 666 "$target"/dev/random c 1 8
mknod -m 666 "$target"/dev/tty c 5 0
mknod -m 666 "$target"/dev/tty0 c 4 0
mknod -m 666 "$target"/dev/urandom c 1 9
mknod -m 666 "$target"/dev/zero c 1 5
# amazon linux yum will fail without vars set
if [ -d /etc/yum/vars ]; then
mkdir -p -m 755 "$target"/etc/yum
cp -a /etc/yum/vars "$target"/etc/yum/
fi
if [[ -n "$install_groups" ]];
then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall $install_groups
fi
if [[ -n "$install_packages" ]];
then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y install $install_packages
fi
yum -c "$yum_config" --installroot="$target" -y clean all
cat > "$target"/etc/sysconfig/network <<EOF
NETWORKING=yes
HOSTNAME=localhost.localdomain
EOF
# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target".
# locales
rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}
# docs and man pages
rm -rf "$target"/usr/share/{man,doc,info,gnome/help}
# cracklib
rm -rf "$target"/usr/share/cracklib
# i18n
rm -rf "$target"/usr/share/i18n
# yum cache
rm -rf "$target"/var/cache/yum
mkdir -p --mode=0755 "$target"/var/cache/yum
# sln
rm -rf "$target"/sbin/sln
# ldconfig
rm -rf "$target"/etc/ld.so.cache "$target"/var/cache/ldconfig
mkdir -p --mode=0755 "$target"/var/cache/ldconfig
version=
for file in "$target"/etc/{redhat,system}-release
do
if [ -r "$file" ]; then
version="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' "$file")"
break
fi
done
if [ -z "$version" ]; then
echo >&2 "warning: cannot autodetect OS version, using '$name' as tag"
version=$name
fi
tar --numeric-owner -c -C "$target" . | docker import - $name:$version
docker run -i -t --rm $name:$version /bin/bash -c 'echo success'
rm -rf "$target"

Shell out into zsh and execute commands from bash script

I'm trying my hand a little virtualisation, so I've been using vagrant to provision a centos7 vm and now I am configuring it with applications.
My vagrant config runs a bootstrap.sh file which is a bash script, in it I install zsh, then I want to configure it as per https://github.com/sorin-ionescu/prezto .
step 1 is launch zsh then run some commands.
This is the code I have at the moment.
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
exec /usr/bin/zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
I want this to be the default shell when I ssh into the VM. It does not appear to be working, there are no errors with the vagrant up step so I just want to know if this is possible and if this seems correct?
Thanks
exec zsh replaces your shell with zsh -- but doesn't in any way tell that instance of zsh to pick up at the same point in execution, or even to run the same script that the bash invocation was previously executing at all.
One easy fix is to feed the rest of your script to zsh via a heredoc:
/usr/bin/zsh <<'EOF'
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
EOF
exec /usr/bin/zsh replaces the running script with a new zsh process. Everything after that is not executed.
You have essentially two options:
Put the stuff specific to zsh into a separate script and run that with /usr/bin/zsh:
vagrant:
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
# run external script
/usr/bin/zsh /home/vagrant/install-prezto.zsh
chsh -s /bin/zsh
/home/vagrant/install-prezto.zsh:
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
Modify the script so that zsh is not needed for the installation:
echo "Installing zsh"
yum install -y zsh
echo "Configure zsh"
# touch /home/vagrant/.zshrc
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
# use find instead of *zsh* to link files
find "${ZDOTDIR:-$HOME}/.zprezto/runcoms/" -maxdepth 1 -type f -! -name README.md --exec ln -s {} "${ZDOTDIR:-$HOME}/" +
chsh -s /bin/zsh

How to update a bash script with the old version of this script?

I have a linux bash script, which has a parameter to update the script self. My problem is, that the script can't update itself, while it's used. Well.. Does someone have a solution?
Currently I try to update the script as following:
# Download latest version
wget -q https://github.com/TS3Tools/TS3UpdateScript/archive/master.zip
# Unzip latest version
unzip master.zip TS3UpdateScript-master/* -x TS3UpdateScript-master/configs/ && mv -f TS3UpdateScript-master/* . && rmdir TS3UpdateScript-master/
But I receive the following error by the script:
replace TS3UpdateScript-master/LICENSE_GNU_GPL.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
ateScript-master/configs
caution: excluded filename not matched: TS3UpdateScript-master/configs/
# many arguments
I hope, someone can help me. Thanks in advance!
It seems that your error comes from file name wildcard without quotes. Bash does globbing first and replaces * with lots of filenames and then runs unzip with this parameters. Try master.zip 'TS3UpdateScript-master/*' -x 'TS3UpdateScript-master/configs/' .
Then there will be a problem with running a new version of script instead of old one running. I think it should be done like that:
#!/bin/bash
version=4
if [ "$UPDATED" != "$0" ]; then
cp self_update.new.sh self_update.sh
exec env UPDATED="$0" "$0" "$#"
fi
echo "This script's version is $version"
Thanks for your help and ideas! I've "outsourced" the code to another script, which contains following code:
#!/usr/bin/env bash
sleep 5s
# Download latest version
wget -q https://github.com/TS3Tools/TS3UpdateScript/archive/master.zip
# Unzip latest version
if [[ $(unzip master.zip TS3UpdateScript-master/* -x TS3UpdateScript-master/configs/*) ]]; then
if [ $(cp -Rf TS3UpdateScript-master/* . && rm -rf TS3UpdateScript-master/) ]; then
rm -rf master.zip
exit 1;
fi
else
rm -rf master.zip
exit 0;
fi

GNU Make removes downloaded zip files for no apparent reason

I have this makefile tha sthould download and build openssh (along with other things):
ROOT_DIR=$(PWD)
DATA_DIR=$(ROOT_DIR)/data
SOURCES_DIR=$(ROOT_DIR)/sources
RESOURCES_DIR=$(ROOT_DIR)/resources
DRAFTS_DIR=$(ROOT_DIR)/drafts
$(SOURCES_DIR):
mkdir $(SOURCES_DIR)
$(RESOURCES_DIR):
mkdir $(RESOURCES_DIR)
$(DRAFTS_DIR):
mkdir $(DRAFTS_DIR)
openssh-tar-url="ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/OpenSSH/portable/openssh-6.2p2.tar.gz"
TAR_PROJECTS += openssh
openssh:
echo "Building $#"
openssh-clean: openssh-archive-clean
.SECONDEXPANSION :
$(TAR_PROJECTS) : $(SOURCES_DIR) $(SOURCES_DIR)/$$#-archive
$(DRAFTS_DIR)/%.tar.gz: $(DRAFTS_DIR)
echo "Pulling $*."
wget $($*-tar-url) -O $(DRAFTS_DIR)/$*.tar.gz
.SECONDEXPANSION :
$(SOURCES_DIR)/%-archive : | $(DRAFTS_DIR)/$$*.tar.gz
mkdir $#
cd $# && tar xvzf $(DRAFTS_DIR)/$*.tar.gz
%-archive-clean:
rm -rf $(SOURCES_DIR)/$*-archive $(DRAFTS_DIR)/$*.tar.gz
When i run make openssh it runs correctly but at the end it removes the archive it downloaded. This is very strange to me:
$ make openssh --just-print
echo "Pulling openssh."
wget "ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/OpenSSH/portable/openssh-6.2p2.tar.gz" -O /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz
mkdir /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/sources/openssh-archive
cd /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/sources/openssh-archive && tar xvzf /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz
echo "Building openssh"
rm /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz
Pretty sure you can list targets (and intermediates) as .PRECIOUS to avoid them being deleted for you. I'm afraid you'll need to RTFM for more details - I'm in visual studio rather than make these days, so my make skills are a bit rusty...

Resources