Commit e2ecca8ee285b7f8d532b29e7c89b45bc36afe6e

Authored by kevin_fourie
1 parent 80ac29fd

KTS-2525

"Create windows service to wrap around scheduler"
Updated. Modified service scripts.

Committed By: Kevin Fourie
Reviewed By: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7443 c91229c3-7414-0410-bfa2-8a42b809f60b
bin/win32/installScheduler.php
1 <?php 1 <?php
2 2
3 -$dir = realpath(dirname(__FILE__) . '/schedulerService.php'); 3 +$scriptPath = realpath(dirname(__FILE__) . '/schedulerService.php');
  4 +
  5 +// Setup php binary path
  6 +$phpPath = realpath('../../php/php.exe');
  7 +if (!is_file($phpPath))
  8 +{
  9 + die('Cannot find php.exe');
  10 +}
4 11
5 -win32_create_service(array(  
6 - 'service' => 'ktscheduler',  
7 - 'display' => 'KnowledgeTree Scheduler Service',  
8 - 'params' => $dir  
9 - )); 12 +win32_create_service(array(
  13 + 'service' => 'ktscheduler',
  14 + 'display' => 'ktdmsScheduler',
  15 + 'params' => $scriptPath,
  16 + 'path' => $phpPath
  17 + ));
10 18
11 -?>  
12 \ No newline at end of file 19 \ No newline at end of file
  20 +?>
bin/win32/schedulerService.php
1 <?php 1 <?php
2 2
  3 +$myservicename = 'ktscheduler';
3 4
4 -$dir = realpath(dirname(__FILE__) . '/..');  
5 -chdir($dir); 5 +// Connect to service dispatcher and notify that startup was successful
  6 +if (!win32_start_service_ctrl_dispatcher($myservicename)) die('Could not connect to service :'.$myservicename);
  7 +win32_set_service_status(WIN32_SERVICE_RUNNING);
6 8
7 -$phpPath = realpath('../../../php/php.exe');  
8 -if (!is_file($phpPath))  
9 -{  
10 - die('Cannot find php.exe');  
11 -} 9 +// Main Scheduler Service Loop
  10 +while (1) {
  11 +
  12 + switch (win32_get_last_control_message()) {
  13 +
  14 + case WIN32_SERVICE_CONTROL_CONTINUE: break; // Continue server routine
  15 + case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_NO_ERROR); break; // Respond with status
  16 + case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); exit; // Terminate script
  17 + default: win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED); // Add more cases to handle other service calls
  18 + }
12 19
  20 + // Change to knowledgeTree/bin folder
  21 + $dir = realpath(dirname(__FILE__) . '/..');
  22 + chdir($dir);
13 23
14 - win32_start_service_ctrl_dispatcher('ktscheduler'); 24 + // Setup php binary path
  25 + $phpPath = realpath('../../php/php.exe');
  26 + if (!is_file($phpPath))
  27 + {
  28 + die('Cannot find php.exe');
  29 + }
  30 +
  31 + // Run the scheduler script
  32 + system("$phpPath scheduler.php");
15 33
16 - while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message())  
17 - {  
18 - system("$phpPath scheduler.php");  
19 - sleep(60);  
20 - } 34 + sleep(10); // Run every 10 seconds
  35 +
  36 +}
  37 +win32_set_service_status(WIN32_SERVICE_STOPPED);
21 38
22 -?>  
23 \ No newline at end of file 39 \ No newline at end of file
  40 +?>