enanobot.php
changeset 7 1d6e762433fe
parent 6 a802bb5b3e08
child 8 0acb8d9a3194
equal deleted inserted replaced
6:a802bb5b3e08 7:1d6e762433fe
     3 /**
     3 /**
     4  * EnanoBot - the Enano CMS IRC logging and help automation bot
     4  * EnanoBot - the Enano CMS IRC logging and help automation bot
     5  * GPL and no warranty, see the LICENSE file for more info
     5  * GPL and no warranty, see the LICENSE file for more info
     6  */
     6  */
     7 
     7 
     8 // define('LIBIRC_DEBUG', '');
     8 // parse command line
       
     9 if ( isset($argv[1]) )
       
    10 {
       
    11   $arg =& $argv[1];
       
    12   if ( $arg == '--daemon' || $arg == '-d' )
       
    13   {
       
    14     // attempt to fork...
       
    15     if ( function_exists('pcntl_fork') )
       
    16     {
       
    17       $pid = pcntl_fork();
       
    18       if ( $pid == -1 )
       
    19       {
       
    20         echo "Forking process failed.\n";
       
    21         exit(1);
       
    22       }
       
    23       else if ( $pid )
       
    24       {
       
    25         echo "EnanoBot daemon started, pid $pid\n";
       
    26         exit(0);
       
    27       }
       
    28       else
       
    29       {
       
    30         // do nothing, just continue.
       
    31       }
       
    32     }
       
    33     else
       
    34     {
       
    35       echo "No pcntl support in PHP, continuing in foreground\n";
       
    36     }
       
    37   }
       
    38   else if ( $arg == '-v' || $arg == '--verbose' )
       
    39   {
       
    40     define('LIBIRC_DEBUG', '');
       
    41   }
       
    42   else
       
    43   {
       
    44     echo <<<EOF
       
    45 Usage: {$argv[0]}
       
    46 Options:
       
    47   -d, --daemon     Run in background (requires pcntl support)
       
    48   -v, --verbose    Log communication to stdout (ignored if -d specified)
       
    49   -h, --help       This help message
       
    50 
       
    51 EOF;
       
    52     exit(1);
       
    53   }
       
    54 }
     9 
    55 
    10 require('libirc.php');
    56 require('libirc.php');
    11 require('config.php');
    57 require('config.php');
    12 
    58 
    13 @ini_set('display_errors', 'on');
    59 @ini_set('display_errors', 'on');