Creating an auto-deployment script for centos

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Creating an auto-deployment script for centos
# 1  
Old 06-26-2016
Creating an auto-deployment script for centos

Hi Guys,

Is this script good enough??

I build a CentOS VM every now and then and I what I want to achieve is to create a package(much preferred) but to begin with I want to create an auto deployment script which would do all the work for me while I do rest of the things.

Code:
[root@agent2 jim]# cat installation.sh 
#!/bin/bash

set -x

function failed
{
STATUS=$(echo $?)

if [[ "${STATUS}" ==  "0" ]]; then
	echo "All good continue"
else
	exit 1
fi
}

cd /tmp
failed

yum -y install epel-release #Adding EPEL Repositories
failed

cd /tmp/
failed

wget https://centos7.iuscommunity.org/ius-release.rpm
failed

sudo rpm -Uvh ius-release*.rpm
failed

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
failed

sudo rpm -Uvh remi-release-7*.rpm
failed

cd /tmp/ && wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

yum repolist
failed

rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
failed

yum -y install http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
failed

yum -y install flash-plugin
failed

yum -y install icedtea-web
failed

yum -y install vlc smplayer ffmpeg HandBrake-{gui,cli}
failed

yum -y install libdvdcss gstreamer{,1}-plugins-ugly gstreamer-plugins-bad-nonfree gstreamer1-plugins-bad-freeworld
failed

yum groupinstall "Development Tools"
failed

yum -y update
failed

exit 0
[root@agent2 jim]#

Output:
Code:
+ sudo rpm -Uvh ius-release.rpm
warning: ius-release.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
Preparing...                          ################################# [100%]
	package ius-release-1.0-14.ius.centos7.noarch is already installed
+ failed
++ echo 1
+ STATUS=1
+ [[ 1 == \0 ]]
+ exit 1
[root@agent2 jim]#

1. At professional level is this script good enough? Yeah I am newbie therefore asking.
2. Why I am getting error at the execution step ? The installation shouldn't failed because a package is already existing but carry on with rest of the script.

Any help would be very much appreciated.
# 2  
Old 06-26-2016
A few thoughts on - not necessarily exhaustive answers to - your questions:
1. "good enough" for me means: fulfills its purpose to satisfaction. Does it do the installation (on a sunny day)? If yes: sounds "good enough". Is it fail-safe? Not on first sight. Do you want the reason why it fails, and does it show that: no, so "not good enough" on rainy days. Any action to repair a failure: No.
My experience is it takes way more than half the programming effort to do error checking and handling. Which immediately leads to the second question:
2. While applications may give a plethora of exit codes indicating what went wrong and how severe this was, you're ignoring this diversity, only testing the result being zero, if not treat this as a failure, and quit with an exit code 1. So your failed function may be a bit too simplistic.
# 3  
Old 06-26-2016
Here is the new version of the script:

Code:
[root@agent2 jim]# cat installation.sh
#!/bin/bash

set -x

function failed
{
STATUS=$(echo $?)

if [[ "${STATUS}" ==  "0" ]]; then
	echo "All good continue"
else
	exit 1
fi
}

function isInstalled-yum
{
isinstalled_yum=$(yum list installed |grep $1)

if [[ "${isinstalled_yum}" ==  "0" ]]; then
	echo -e "$1 package is already installed"
else
	yum -y install $1
fi
}

function isInstalled-rpm
{

isinstalled_rpm=$(rpm -q -p $1 --queryformat "%{NAME} %{VERSION} %{RELEASE} %{ARCH}\n")

if [[ "${isinstalled_rpm}" ==  "0" ]]; then
	echo -e "$1 package is already installed"
else
	rpm -Uvh $1
fi

}

cd /tmp
failed
isInstalled-yum epel-release
failed

cd /tmp/
failed

wget https://centos7.iuscommunity.org/ius-release.rpm
failed
isInstalled-rpm ius-release.rpm
failed

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
failed
isInstalled-rpm remi-release-7.rpm
failed

cd /tmp/ && wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

isInstalled-rpm rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

wget http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
failed

isInstalled-rpm nux-dextop-release-0-5.el7.nux.noarch.rpm
failed

cd /tmp
failed
pwd
failed

wget http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
failed
isInstalled-rpm adobe-release-x86_64-1.0-1.noarch.rpm
failed

isInstalled-yum flash-plugin
failed

isInstalled-yum icedtea-web
failed

isInstalled-yum vlc smplayer ffmpeg HandBrake-{gui,cli}
failed

isInstalled-yum libdvdcss gstreamer{,1}-plugins-ugly gstreamer-plugins-bad-nonfree gstreamer1-plugins-bad-freeworld
failed

isInstalled-yum "Development Tools"
failed

yum repolist

yum -y update
failed

exit 0
[root@agent2 jim]#

Here is the Output:

Limited to the area where it has failed.

Code:
2016-06-26 21:43:59 (9.16 MB/s) - ‘ius-release.rpm.7' saved [8264/8264]

+ failed
++ echo 0
+ STATUS=0
+ [[ 0 == \0 ]]
+ echo 'All good continue'
All good continue
+ isInstalled-rpm ius-release.rpm
++ rpm -q -p ius-release.rpm --queryformat '%{NAME} %{VERSION} %{RELEASE} %{ARCH}\n'
warning: ius-release.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
+ isinstalled_rpm='ius-release 1.0 14.ius.centos7 noarch'
+ [[ ius-release 1.0 14.ius.centos7 noarch == \0 ]]
+ rpm -Uvh ius-release.rpm
warning: ius-release.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
Preparing...                          ################################# [100%]
	package ius-release-1.0-14.ius.centos7.noarch is already installed
+ failed
++ echo 1
+ STATUS=1
+ [[ 1 == \0 ]]
+ exit 1
[root@agent2 jim]#


No idea why failed subroutine is return 1??
# 4  
Old 06-26-2016
Hi,

I'm a sysadmin who does a lot of automating too.

Your script maybe good for a start. I have some points for you:

  • Yous script could use some improvements to make it simpler. But hey! It works? It may stay as it is.
  • Maybe you want a result mailed to you when the installation is read, so you know when something had failed and you'll be informed to fix it. Of course your system needs a configured mailer to do this.
  • Another buzzword of automation "idempotency": Run it as often as you want, you get always the correct result. What's regarding your script, this point should be fulfilled. Nothing bad should happen if you call it more than once, except some download trash is accumulating. So cleaning up after your script runs is a good idea.
  • You may go with your own scripts, but things tend to get more complex. So you may choose one of the configuration management or automated install systems. I'm using FAI(Nice,Primarily for Debian/Ubuntu, but also possible for CentOS(I use it to install CentOS 6+7) for automated install and chef(quite complex, steep learning curve) for configuration management. If you stay with centos, kickstart may be more convenient for you for the topic of automatic installation. And what I've read ansible is a more easy approach than chef, if you want to manage your nodes after installation.
# 5  
Old 06-26-2016
Isn't that clear? rpm gives an exit code of 1 which is different from 0 so you exit 1.
So you need to differentiate the handling of the exit codes in failed depending on the application called upfront. Or you need different check functions for different applications.
# 6  
Old 06-26-2016
Quote:
Originally Posted by stomp
Hi,

I'm a sysadmin who does a lot of automating too.

Your script maybe good for a start. I have some points for you:

  • Yous script could use some improvements to make it simpler. But hey! It works? It may stay as it is.
  • Maybe you want a result mailed to you when the installation is read, so you know when something had failed and you'll be informed to fix it. Of course your system needs a configured mailer to do this.
  • Another buzzword of automation "idempotency": Run it as often as you want, you get always the correct result. What's regarding your script, this point should be fulfilled. Nothing bad should happen if you call it more than once, except some download trash is accumulating. So cleaning up after your script runs is a good idea.
  • You may go with your own scripts, but things tend to get more complex. So you may choose one of the configuration management or automated install systems. I'm using FAI(Nice,Primarily for Debian/Ubuntu, but also possible for CentOS(I use it to install CentOS 6+7) for automated install and chef(quite complex, steep learning curve) for configuration management. If you stay with centos, kickstart may be more convenient for you for the topic of automatic installation. And what I've read ansible is a more easy approach than chef, if you want to manage your nodes after installation.
I know puppet at very beginner level.And it can do the job but I want to lessen the burden on puppet. My main aim is once I install CentOS, all my configurations/package installations should occur via just one script.

Yep, script is idempotent. The mail aspect is easy to configure but I am not doing it right now. My main aim is to have this script ready so I can execute it multiple number of times without any issue.

---------- Post updated at 10:25 PM ---------- Previous update was at 10:16 PM ----------

Quote:
Originally Posted by RudiC
Isn't that clear? rpm gives an exit code of 1 which is different from 0 so you exit 1.
So you need to differentiate the handling of the exit codes in failed depending on the application called upfront. Or you need different check functions for different applications.
Yeah, I did figured that out now. But not sure how do i handle it...

---------- Post updated at 11:17 PM ---------- Previous update was at 10:25 PM ----------

I now know what is the problem. rpm has different type of return codes.Therefore I either need to explore more rpm switches or write another subroutine code for "failed"

Any idea how to get list of return codes for rpm?
# 7  
Old 06-26-2016
Thanks mate. Really appreciate it, shall try first thing tomorrow Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to provide auto inputs for a sub-script within a script?

Hi All, I am writing a shell script. #!/bin/bash cat /etc/hosts mkdir -p /var/tmp mount 113.123.35.37:/vol/vol615/syb /var/tmp In above script I am trying to add below predefined script/command (/var/tmp/db_tools) This command in turn ask for user input, which will be always option... (17 Replies)
Discussion started by: madhur.baharani
17 Replies

2. Shell Programming and Scripting

auto kill script

Hi, I have created a shell script which is used by many users to change their password/unlock, etc., via menu. There is possibility users just close the putty window without proper exit from menu. I want a solution so that if anybody forgets to stop that session, it should kill automatically... (9 Replies)
Discussion started by: prashant2507198
9 Replies

3. Red Hat

How to Upgrade Centos 5.7 using Centos 5.8 ISO image on Vmware workstation

Dear Linux Experts, On my windows 7 desktop with the help of Vmware workstation (Version 7.1), created virtual machine and installed Centos 5.7 successfully using ISO image. Query : Is this possible to upgrade the Centos 5.7 using Centos 5.8 ISO image to Centos version 5.8?.. if yes kindly... (2 Replies)
Discussion started by: Ananthcn
2 Replies

4. Shell Programming and Scripting

Application Deployment Script

Hi, I need to develop a script which will deploy my web application binary(.war) file in the jboss application server. I also need to take the back up of the existing binary file and rename the same with current date and then deploy the new binary from my specified location. The same... (1 Reply)
Discussion started by: Siddheshk
1 Replies

5. Shell Programming and Scripting

Application Deployment Script

Dear All, I have been deploying my web application binary on Jboss application server manually on 13 servers with 2 instances on each server. i.e. 26 instances. It is really becoming time consuming to deploy the application manually. I am looking for a script which would deploy my binary file... (1 Reply)
Discussion started by: Siddheshk
1 Replies

6. Shell Programming and Scripting

Using cp: preserving file/folder attributes and auto creating folders

Hi, Is there a way to use cp in such a way that when a file is copied to a destination, the required destination folders are automatically created with the proper permissions, and the resulting copied file has the same attributes as the original. For example if I copied... (1 Reply)
Discussion started by: pcwiz
1 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. Shell Programming and Scripting

Wrapper script for image deployment - stdin/stdout - named pipes and the like

Hi everyone, first post here. Anyone who isn't interested in the background, press pagedown :). I sometimes need to make scripts for little things I need in the infrastructure at the company I work at. Currently I am trying to make a wrapper script for a proprietary image-deployment program.... (2 Replies)
Discussion started by: andreas.ericson
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script to Auto Run PHP Script

Hello All! I am looking to build a monitoring script. The script should always run as a system service of some type and should always check that a PHP script is running. Maybe there is a way to assign a PHP script to a certain PID so that the monitor script that check for the PID in top... (4 Replies)
Discussion started by: elDeuce
4 Replies
Login or Register to Ask a Question