greyhound.php
changeset 8 a8d108f37363
parent 7 3ba432f8390b
child 12 b3fcc21e557f
--- a/greyhound.php	Sun Mar 23 23:17:06 2008 -0400
+++ b/greyhound.php	Sun Mar 23 23:55:50 2008 -0400
@@ -12,6 +12,13 @@
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
  */
 
+// required for signal handling to work
+declare(ticks=1);
+
+// trap SIGTERM
+pcntl_signal(SIGTERM, 'sigterm');
+pcntl_signal(SIGINT,  'sigterm');
+
 $public = true;
 $allowcontrol = true;
 $theme = 'funkymonkey';
@@ -21,24 +28,23 @@
 // include files
 require('functions.php');
 
+// get the root
+define('GREY_ROOT', dirname(__FILE__));
+
+// create directories
+@mkdir('./compiled');
+
 // start up...
 
 status('Starting WebControl v0.1-hg');
 status('loading files');
 
 require('webserver.php');
-define('SMARTY_DIR', './smarty/');
-require('smarty/Smarty.class.php');
-require('playlist.php');
-require('json.php');
-require('ajax.php');
-
-status('initializing Smarty');
-$smarty = new Smarty();
-$smarty->template_dir = "./themes/$theme";
-$smarty->compile_dir = "./themes/$theme/compiled";
-$smarty->cache_dir = "./cache";
-$smarty->config_dir = "./config";
+define('SMARTY_DIR', GREY_ROOT . '/smarty/');
+require(GREY_ROOT . '/smarty/Smarty.class.php');
+require(GREY_ROOT . '/playlist.php');
+require(GREY_ROOT . '/json.php');
+require(GREY_ROOT . '/ajax.php');
 
 status('doing home directory detection');
 
@@ -51,6 +57,15 @@
 
 $homedir =& $_ENV['HOME'];
 
+// signal handler
+function sigterm($signal)
+{
+  global $httpd;
+  status("Caught SIGTERM, cleaning up.");
+  @socket_close($httpd->sock);
+  exit();
+}
+
 status('initializing playlist');
 
 // init playlist object
@@ -68,12 +83,11 @@
   
   // setup handlers
   status('initializing handlers');
-  $httpd->add_handler('index', 'function', 'amarok_playlist');
-  $httpd->add_handler('action.json', 'function', 'ajax_request_handler');
-  $httpd->add_handler('scripts', 'dir', './scripts');
-  $httpd->add_handler('favicon.ico', 'file', './amarok_icon.ico');
-  $httpd->add_handler('apple-touch-icon.png', 'file', './apple-touch-icon.png');
-  $httpd->add_handler("themes/$theme", 'dir', "./themes/$theme");
+  $httpd->add_handler('index',                'function', 'amarok_playlist');
+  $httpd->add_handler('action.json',          'function', 'ajax_request_handler');
+  $httpd->add_handler('scripts',              'dir',      GREY_ROOT . '/scripts');
+  $httpd->add_handler('favicon.ico',          'file',     GREY_ROOT . '/amarok_icon.ico');
+  $httpd->add_handler('apple-touch-icon.png', 'file',     GREY_ROOT . '/apple-touch-icon.png');
   $httpd->allow_dir_list = true;
   $httpd->default_document = 'index';