23 // trap SIGTERM |
23 // trap SIGTERM |
24 pcntl_signal(SIGTERM, 'sigterm'); |
24 pcntl_signal(SIGTERM, 'sigterm'); |
25 pcntl_signal(SIGINT, 'sigterm'); |
25 pcntl_signal(SIGINT, 'sigterm'); |
26 } |
26 } |
27 |
27 |
|
28 // |
|
29 // CONFIGURATION |
|
30 // |
|
31 |
|
32 // Listen on all interfaces. If this is false, it will only listen on |
|
33 // 127.0.0.1 (the loopback interface) |
28 $public = true; |
34 $public = true; |
|
35 // Allow control of playback. By default this is turned on but if you |
|
36 // set this to false, it will only display the playlist. |
29 $allowcontrol = true; |
37 $allowcontrol = true; |
|
38 // The default theme. This should be a name of a directory in ./themes. |
30 $theme = 'funkymonkey'; |
39 $theme = 'funkymonkey'; |
|
40 // Allow forking when an HTTP request is received. This has advantages |
|
41 // and disadvantages. If this experimental option is enabled, it will |
|
42 // result in faster responses and load times but more memory usage. |
|
43 $allow_fork = true; |
31 |
44 |
32 @ini_set('display_errors', 'on'); |
45 @ini_set('display_errors', 'on'); |
33 |
46 |
34 // include files |
47 // include files |
35 require('functions.php'); |
48 require('functions.php'); |
40 // create directories |
53 // create directories |
41 @mkdir('./compiled'); |
54 @mkdir('./compiled'); |
42 |
55 |
43 // start up... |
56 // start up... |
44 |
57 |
45 status('Starting WebControl v0.1-hg'); |
58 status('Starting Greyhound Web Control v0.1-hg'); |
46 status('loading files'); |
59 status('loading files'); |
47 |
60 |
48 require('webserver.php'); |
61 require('webserver.php'); |
49 define('SMARTY_DIR', GREY_ROOT . '/smarty/'); |
62 define('SMARTY_DIR', GREY_ROOT . '/smarty/'); |
50 require(GREY_ROOT . '/smarty/Smarty.class.php'); |
63 require(GREY_ROOT . '/smarty/Smarty.class.php'); |
97 $httpd->add_handler('index', 'function', 'amarok_playlist'); |
110 $httpd->add_handler('index', 'function', 'amarok_playlist'); |
98 $httpd->add_handler('action.json', 'function', 'ajax_request_handler'); |
111 $httpd->add_handler('action.json', 'function', 'ajax_request_handler'); |
99 $httpd->add_handler('scripts', 'dir', GREY_ROOT . '/scripts'); |
112 $httpd->add_handler('scripts', 'dir', GREY_ROOT . '/scripts'); |
100 $httpd->add_handler('favicon.ico', 'file', GREY_ROOT . '/amarok_icon.ico'); |
113 $httpd->add_handler('favicon.ico', 'file', GREY_ROOT . '/amarok_icon.ico'); |
101 $httpd->add_handler('apple-touch-icon.png', 'file', GREY_ROOT . '/apple-touch-icon.png'); |
114 $httpd->add_handler('apple-touch-icon.png', 'file', GREY_ROOT . '/apple-touch-icon.png'); |
|
115 // load all themes if forking is enabled |
|
116 // Themes are loaded when the playlist is requested. This is fine for |
|
117 // single-threaded operation, but if the playlist handler is only loaded |
|
118 // in a child process, we need to preload all themes into the parent before |
|
119 // children can respond to theme resource requests. |
|
120 if ( $allow_fork ) |
|
121 { |
|
122 status('Preloading themes'); |
|
123 |
|
124 $dh = @opendir(GREY_ROOT . '/themes'); |
|
125 if ( !$dh ) |
|
126 burnout('Could not open themes directory'); |
|
127 while ( $dir = @readdir($dh) ) |
|
128 { |
|
129 if ( $dir == '.' || $dir == '..' ) |
|
130 continue; |
|
131 if ( is_dir( GREY_ROOT . "/themes/$dir" ) ) |
|
132 load_theme($dir); |
|
133 } |
|
134 } |
102 $httpd->allow_dir_list = true; |
135 $httpd->allow_dir_list = true; |
|
136 $httpd->allow_fork = ( $allow_fork ) ? true : false; |
103 $httpd->default_document = 'index'; |
137 $httpd->default_document = 'index'; |
104 |
138 |
105 status("Entering main server loop - ^C to interrupt, listening on port $port"); |
139 status("Entering main server loop - ^C to interrupt, listening on port $port"); |
106 $httpd->serve(); |
140 $httpd->serve(); |
107 } |
141 } |
108 catch( Exception $e ) |
142 catch( Exception $e ) |
109 { |
143 { |
110 burnout("Exception caught while running webserver:\n$e"); |
144 burnout("Exception caught while running webserver:\n$e"); |
111 } |
145 } |
112 |
|