Sunday, August 30, 2009

help of useful commands

In this post, just a link of files contains help guide ([command] --help) for the most common unix shell commands.

Sunday, August 23, 2009

Monitor linux web-servers with monit

"monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.

Monit is controlled via an easy to configure control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions via customizable alert messages. Monit can perform various TCP/IP network checks, protocol checks and can utilize SSL for such checks. Monit provides a http(s) interface and you may use a browser to access the monit program."[ref] .

How to install in ubuntu 8.10

  • sudo apt-get install monit
  • edit /etc/monit/monitrc and remove comments
    #launch system mon every 2min
    set daemon 120
    #set web interface on port 2812
    set httpd port 2812 and
    # allow localhost and request from IP 1.2.3.4
    allow localhost
    allow 1.2.3.4
    #request username (admin) and password(monit)
    allow admin:monit
    #check apache
    check process apache with pidfile /usr/local/apache/logs/httpd.pid
    #check mysql service (other server)
    check host myserver with address 192.168.1.1
    if failed icmp type echo count 3 with timeout 3 seconds then alert
    if failed port 3306 protocol mysql with timeout 15 seconds then alert
    #set alerts via email
    set mailserver mail.domain.com
    set alert administrator@domain.com
  • check the syntax of the previous file with
    sudo monit -t
  • edit /etc/default/monit
    startup=1
  • start deamon !!
    sudo /etc/init.d/monit start
  • call web interface
    http://yourserverip:2812/
    use admin and password specified before

Saturday, August 22, 2009

Compare Files between two directories recursively - PHP script

In this post I'll present my PHP class to show differences (file missing or different file date) between files in two directories (recursively).
It's useful to compare two websites (Example, test and live versioning the same server) and show the differences, much faster than a FTP synchronization, and customizable (size differences instead of time, PHP copy commands with backup etc...).

Example of output:


How to use:
= new CompareDirs("e:/siti/symfapp/", "e:/siti/symfapp2/");
$c->addSkipPath(".svn".DIRECTORY_SEPARATOR);
$c->addSkipPath(".project".DIRECTORY_SEPARATOR);
$c->addSkipPath(".settings".DIRECTORY_SEPARATOR);
$c->compare();
echo
"{$c->totalFiles} files. {$c->skippedFiles} skipped.
{$c->differencesNotFound} missing.{$c->differencesTime} time differences. ".$c->getHTML();
?>


View the code
comparedirs.php
 

PHP and tips|PHP