Checking system readiness for launching application (bash script)

It’s a simple bash script that checks system readiness for launching an application. It checks –

  • Command line programs and tools installed
  • Required PHP modules enabled (if php application)
  • Depending servers up and required ports are listening

Here is a sample output –
dependency_check.sh output

Get the script

Here is the script as public gist. Feel free to fork, copy or download it.

How to use it?

First of all, we need to adjust dependency list for target application. To do that, open the file and set the following arrays as per the applications requirement –

dependencies=(httpd php mysql supervisord beanstalkd wkhtmltopdf convert)
php_modules=(curl PDO pdo_mysql session Reflection hash json sockets oci8)
listeners=('127.0.0.1 3306' '127.0.0.1 11300' '192.168.10.10 1521')

Note that, servers and required ports should be mentioned as ‘IP-Address PORT’ (separated by space). And, if it’s not a PHP application, make the php_modules array empty.

Then, there are 2 ways to use it. We can run it as usual shell script. To do that, make it runnable (first time only) –

chmod +x dependency_check.sh

Then run the script as –

./dependency_check.sh

Or we can use it in other script to check if system is ready to run our application –

./path/to/dependency_check.sh > /dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo "ERROR: Some system dependency is missing"
    echo 'Run "./path/to/dependency_check.sh" for dependency details.'
fi

Thats all, it will return non-zero exit code if at least 1 test was failed.

BTW, this script was written with PHP web applications in mind. Starting from here, we may add/modify functions and dependency checking tricks based on application, OS or type of dependencies.

Thanks for starring the gist!

A little Background: We have been working with some Banks and corporates who prefers to deploy applications at their own premise, in very restricted intranet network. So, we don’t get internet access to prepare dependencies there, not even git clone to get the source code. For those deployments, we follow a procedure that is different than cloud deployment. This script is part of that procedure.

Leave a Comment

Your email address will not be published. Required fields are marked *