# HG changeset patch # User Dan # Date 1210387077 14400 # Node ID 1d6e762433fef7e4b2f18e041df15b331bae8fde # Parent a802bb5b3e08cbf83c1eb88c94ed4975c082ab2e Added daemonizing (forking) support. diff -r a802bb5b3e08 -r 1d6e762433fe enanobot.php --- a/enanobot.php Fri May 09 22:19:32 2008 -0400 +++ b/enanobot.php Fri May 09 22:37:57 2008 -0400 @@ -5,7 +5,53 @@ * GPL and no warranty, see the LICENSE file for more info */ -// define('LIBIRC_DEBUG', ''); +// parse command line +if ( isset($argv[1]) ) +{ + $arg =& $argv[1]; + if ( $arg == '--daemon' || $arg == '-d' ) + { + // attempt to fork... + if ( function_exists('pcntl_fork') ) + { + $pid = pcntl_fork(); + if ( $pid == -1 ) + { + echo "Forking process failed.\n"; + exit(1); + } + else if ( $pid ) + { + echo "EnanoBot daemon started, pid $pid\n"; + exit(0); + } + else + { + // do nothing, just continue. + } + } + else + { + echo "No pcntl support in PHP, continuing in foreground\n"; + } + } + else if ( $arg == '-v' || $arg == '--verbose' ) + { + define('LIBIRC_DEBUG', ''); + } + else + { + echo <<