Automatically build after file change

I’m playing a lot with Docker lately. Building images, and then rebuilding, and then building again… It’s pretty boring. To automate this task a little I used inotify to build automatically after I changed any file. This trick could be used in many different situations.

You will need inotify-tools package:

    sudo apt-get install -y inotify-tools

Then run something like this:

while inotifywait -e modify -r .; do docker-compose build; done

This commands will rebuild my Docker images after any file change in current directory. Use Ctrl+c to exit from loop.

Install WordPress from command-line

I never tried it before but today I needed to install WordPress… From command line only. And there is a way to do this with wp-cli.

WP-CLI installation

First some requirements (as root):

apt-get install php5-cli php5-mysql mysql-client curl

And now installation of wp-cli (as root too):

curl -O
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp

Check if it’s working:

$ wp --version
WP-CLI 0.22.0

WordPress installation

Now you should switch to user of your web application, ex. like this:

su - www-data -s /bin/bash

And install WP:

wp core download --path=/var/www/wordpress

wp core config --path=/var/www/wordpress \
  --dbname=wordpress \
  --dbuser=wordpress \
  --dbpass=wordpresspass \
  --dbhost=localhost \

wp core install --path=/var/www/wordpress \
  --url="" \
  --title="Example blog" \
  --admin_user=never_use_admin_here \
  --admin_password=admin_pass \ \

Here you may find more about wp-cli configuration and commands.

Nagios – downtime on host/service from command line with curl

Sometimes deployment process or other havy task may cause some Nagios checks to rise below normal levels and bother admin. If this is expected and you want to add downtime on host/service during this task you may use this script:


function die {
  echo $1;
  exit 1;

if [[ $# -eq 0 ]] ; then
    die "Give hostname and time in minutes as parameter!"

if [[ $# -eq 1 ]] ; then

COMMENT="Deploying new code"

export MINUTES

echo "Scheduling downtime on $HOST for $MINUTES minutes..."

# The following is urlencoded already
#STARTDATE=`date "+%Y-%m-%d %H:%M:%S"`
STARTDATE=`date "+%d-%m-%Y %H:%M:%S"`
# This gives us the date/time X minutes from now
#ENDDATE=`date "+%Y-%m-%d %H:%M:%S" -d "$MINUTES min"`
ENDDATE=`date "+%d-%m-%Y %H:%M:%S" -d "$MINUTES min"`
curl --silent --show-error \
    --data cmd_typ=56 \
    --data cmd_mod=2 \
    --data host=$HOST \
    --data-urlencode "service=$SERVICENAME" \
    --data-urlencode "com_data=$COMMENT" \
    --data trigger=0 \
    --data-urlencode "start_time=$STARTDATE" \
    --data-urlencode "end_time=$ENDDATE" \
    --data fixed=1 \
    --data hours=2 \
    --data minutes=0 \
    --data btnSubmit=Commit \
    --insecure \
    $NAGURL -u "$USER:$PASS"| grep -q "Your command request was successfully submitted to Nagios for processing." || die "Failed to con
tact nagios";

echo Scheduled downtime on nagios from $STARTDATE to $ENDDATE

Threat this script as template with some tips:

  • I you want to add downtime on service, then provide SERVICENAME and --data cmd_typ=56 \.
  • If you want downtime on whole host, just remove this line: --data-urlencode "service=$SERVICENAME" \ and --data cmd_typ=86 \
  • Another thing that in my example nagios page use basic auth for security, if your don’t use it, you may remove -u "$USER:$PASS" from parameters.
  • If you get Start or end time not valid, then you have to adapt dates to your formats of dates accepted by Nagios (probably this depends on Nagios version or timezone configuration).


Changing default php.ini file for PHP-CLI on CentOS

On Debian in default installation you have different configuration files for PHP in Apache, FPM, CLI, etc. But on CentOS you have only one php.ini for all of them. In case I have, I need to have different configuration file for scripts running in CLI mode (more memory, etc). I could run it like this:

php -c /etc/php-cli.ini script.php

But this a little burdensome. So I do it like this:

cat > /etc/profile.d/ <<SCRIPT
alias php="php -c /etc/php-cli.ini"
cp /etc/php.ini /etc/php-cli.ini

Logout, login and now every user can run PHP scripts in CLI with different configuration – exactly what I need 🙂