Skip to content

determine if an apache process is still running via bash to prevent multiple instances running

Given is the fact that you have some processes (like cronjobs) executed via an webserver like apache. Furthermore you have installed and enables apache server status. To add some re usability benefits, we should divide and conquer the problems into either shell scripts or shell functions. Side note, if I am writing about shell, I am in the bash environment. What are the problems we want to tackle down?:

  • find the correct environment
  • check all available webservers if a process is not running
  • specify which process should not run and start it if possible

We can put the first two problems into shell functions like the following ones. I am referencing to some self written shell functions. The reference is indicated by the "net_bazzline_" prefix.

#!/bin/bash
#find the correct environment

if net_bazzline_string_contains $HOSTNAME 'production';
    NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT=1
else
    NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT=0
fi

And the mighty check.

#!/bin/bash
#check all available webservers if a process is not running
####
# @param string <process name>
# @return int (0 if at least one process was found)
####
function local_is_there_at_least_one_apache_process_running()
{
    if [[ $# -lt 1 ]]; then
       echo 'invalid number of arguments'
       echo '    local_is_there_at_least_one_apache_process_running <process name>'

       return 1
    fi

    if [[ $NET_BAZZLINE_IS_PRODUCTION_ENVIRONMENT -eq 1 ]]; then
        LOCAL_ENVIRONMENT='production'
    else
        LOCAL_ENVIRONMENT='staging'
    fi

    #variables are prefixed with LOCAL_ to prevent overwriting system variables
    LOCAL_PROCESS_NAME="$1"

    #declare the array with all available host names
    declare -a LOCAL_HOSTNAMES=("webserver01" "webserver02" "webserver03");

    for LOCAL_HOSTNAME in ${LOCAL_HOSTNAMES[@]}; do
        APACHE_STATUS_URL="http://$LOCAL_HOSTNAME.my.domain/server-status"

        OUTPUT=$(curl -s $APACHE_STATUS_URL | grep -i $LOCAL_PROCESS_NAME)
        EXIT_CODE_OF_LAST_PROCESS="$?"

        if [[ $EXIT_CODE_OF_LAST_PROCESS == "0" ]]; then
            echo "$LOCAL_PROCESS_NAME found on $LOCAL_HOSTNAME"
            return 0
        fi
    done;

    return 1
}

And here is an example how to use it.

#!/bin/bash
#specify which process should not run and start it if possible

source /path/to/your/bash/functions

LOCAL_PROCESS_NAME="my_process"

local_is_there_at_least_one_apache_process_running $LOCAL_PROCESS_NAME

EXIT_CODE_OF_LAST_PROCESS="$?"

if [[ $EXIT_CODE_OF_LAST_PROCESS == "0" ]]; then
    echo "$LOCAL_PROCESS_NAME still running"
    exit 0;
else
    #execute your process
    echo 'started at: '$(date +'%Y-%m-%d %H:%M:%S');
    curl "my.domain/$LOCAL_PROCESS_NAME"
    echo 'started at: '$(date +'%Y-%m-%d %H:%M:%S');
fi

You can put this into a loop by calling it via the cronjob environment or use watch if you only need it from time to time:

watch -n 60 'bash /path/to/your/shell/script'

Enjoy your day :-).

Translate to de es fr it pt ja

web - The Apache Software Foundation Celebrates 15 Years of Open Source Innovation and Community Leadership

The Apache Software Foundation Celebrates 15 Years of Open Source Innovation and Community Leadership


Apache has been at the forefront of dozens of today's industry-defining technologies and tools; nearly every end-user computing device has been touched by at least one Apache product. Budapest, Hungary –19 November– At ApacheCon Europe, members of the Apache community commemorated The Apache Software Foundation (ASF)'s fifteenth anniversary and congratulated the people, projects, initiatives, and organizations that played a role in its success.

Recognized as the leader in community-led Open Source software development, the ASF was established to shepherd, develop, and incubate Open Source innovations "The Apache Way". Reflections on achievements over the past 15 years include:
ASF @ 15 Statement by Chairman Brett Porter http://s.apache.org/RYD
Sponsorship and Stewardship by President Ross Gardler http://s.apache.org/oLh
Community Over Code by Executive Vice President Rich Bowen http://s.apache.org/AQJ

Source

Thanks for all the fish :-). Fingers crossed the foundation will stay

Translate to de es fr it pt ja

Prevent Overwriting PHP Settings By An Application

Assumptive you have a apache webserver and you need to deal with an old application that fills up your log file with many strict entries. You need to prevent your "error_reporting" level to get overwritten.
You can achieve this by adding the following line in your apache httpd.conf.

php_admin_value error_reporting 22517

It is important you are using "php_admin_value" (or "php_admin_flag" when needed) instead of "php_value" to set the value. If you use "php_admin_value", you prevent the value gets overwritten by the ".htaccess" or a "ini_set()" call from your application.

Want to know more? Here are some links fitting to this topic.

Translate to de es fr it pt ja

howto - regex - apache php

Currently, there is no howto. But by the time of running into and solving problems with regex, a view pages helped my a lot. So here they are.

regex php german by phpwcms-howto.de regex howto german by danielfett.de regex howto english by zytrax.com regex in apache mod_rewrite by apache.org regex online tool by gskinner.com regex online test by regexplanet.com

Translate to de es fr it pt ja

howto - Apache Tomcat Configuration

All the needed configuration parameters you can/have to to are linked below. In this entry i want to point out the use of setenv.sh.

With setenv.sh you don't have to edit the default startup script from the tomcat. This means you also can backup/store your settings on a well know place and then just create a link into the directory where your catalina.sh file is placed. The catalina.sh script itself looks for a setenv.sh and reads it. Everything that is configured inside the setenv.sh script overwrites the default settings inside the catalina.sh.

links: tomcate.apache.org how to run a tomcat how to configurate a tomcate

Translate to de es fr it pt ja