Archive

Archive for April, 2014

Finding dependencies for PHP applications

April 27, 2014 1 comment

Blame and lies, contradictions arise
Blame and lies, contradictions arise
Nobody will change my way
Life betrays, but I keep on going
(Sepultura – Inner Self)

I’m a big fan of packaging systems and I pretty much tend to hate deploying unpackaged software. So, I tend to build native OS pacakges as often as I can. Packaging PHP applicatoins (like WordPress for example) is pretty much straightforward job. Only problem one may encounter is listing all software dependencies correctly. Here comes pci to the rescue!

So what is a ‘pci‘ – it’s part of the phpcompatinfo PHP module. The purpose of the module, and of ‘pci’ executable is to find out version and the extensions required for a piece of (PHP) code to run. Yeah, it’s that simple! So, lets try it, on CentOS 6 + EPEL offcourse:

# yum -y install php-pear-PHP-CompatInfo
# mkdir /tmp/pcitest
# echo "<?php phpinfo(); ?>" >> /tmp/pcitest/phpinfo.ph
# pci -d /tmp/pcitest
+-----------------------------+---------+---+------------+--------------------+
| Files                       | Version | C | Extensions | Constants/Tokens   |
+-----------------------------+---------+---+------------+--------------------+
| /tmp/pcitest/*              | 4.0.0   | 0 |            |                    |
+-----------------------------+---------+---+------------+--------------------+

As you can see, phpinfo() requires at least versoin 4.0.0 of PHP and doesn’t require any extension. Let’s run it now on some real project, like TeamPass:

# pci -d teampass > pci.log
# cat pci.log | cut -d'|' -f 5 | grep -v ^+ | sort | uniq | \
    sed 's/^ /Requires: php-/g'
Requires: php-           
Requires: php-bcmath     
Requires: php-ctype      
Requires: php-date       
Requires: php-Extensions 
Requires: php-filter     
Requires: php-gd         
Requires: php-hash       
Requires: php-json       
Requires: php-mbstring   
Requires: php-mysql      
Requires: php-mysqli     
Requires: php-openssl    
Requires: php-pcre       
Requires: php-pgsql      
Requires: php-session    
Requires: php-SimpleXML  
Requires: php-SPL        
Requires: php-xml

With two simple commands we can get output that can easily be copy/pasted and used used in rpm spec file. Enjoy building packages! INNER SELF!

Highly available cron jobs

April 27, 2014 Leave a comment

Travel in Stygian
The damned scream my name
Travel in Stygian
I can’t repent it’s too late
(Iced Earth – Travel in Stygian)

Cronjobs are mostly a node-specific tasks that have to run at regular intervals – like for example logrotate. You have to rotate and compress your logs regularly otherwise nodes would run out of space. But sometimes there are cron jobs that have to run once per a cluster of machines. Now, setting up that job only on one of the nodes can be a pain. That specific node will be different, which is a pain to automatize. Either we hack it manually or add another clause in automation tool of choice (Puppet, Chef). Neither approach is really satisfying. Here comes rcron to the rescue 🙂

rcron is a simple binary that runs other commands, similar to ‘time’. It’s purpose is to run the command only if state file says current node is active. Otherwise, whatever the command, it won’t be run. So, a typical cronjob looking something like:

10 10 * * * /usr/local/bin/my_precious

would get changed to:

10 10 * * * /usr/bin/rcron /usr/local/bin/my_precious

Rcron configuration file /etc/rcron/rcron.conf defines “state” file. State file is a simple text file which consists out of one o two key words: ‘active’ or ‘passive’. If ‘state’ file has a word active, then rcron will run commands run after it, if not, it will just exit and return 0 (success). So this makes it ideal intermediary step between classic cron and cron job. State file can be changed via some cluster-aware management like RHCS, so you can set up a fully HA cron service.

Categories: Linux Tags: , , , ,
%d bloggers like this: