Commit 0f54d782077622a29b7543c9c5723d087eac066b

Authored by kevin_fourie
1 parent 375cbf4e

Merged in from DEV trunk...

KTS-2525
"Create windows service to wrap around scheduler"
Updated. scheduler service must be run from correct relative location.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7544 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 22 additions and 16 deletions
bin/win32/schedulerService.php
... ... @@ -6,6 +6,7 @@ $myservicename = 'ktscheduler';
6 6 if (!win32_start_service_ctrl_dispatcher($myservicename)) die('Could not connect to service :'.$myservicename);
7 7 win32_set_service_status(WIN32_SERVICE_RUNNING);
8 8  
  9 +chdir(dirname(__FILE__)); // need to be here to include dmsDefaults
9 10 require_once('../../config/dmsDefaults.php');
10 11  
11 12 global $default;
... ... @@ -15,35 +16,38 @@ $schedulerInterval = $config->get('KnowledgeTree/schedulerInterval',10); // inte
15 16 //$phpPath = $config->get('externalBinary/php','php'); // TODO - fix me
16 17  
17 18 // Change to knowledgeTree/bin folder
18   -
19 19 $dir = realpath(dirname(__FILE__) . '/..');
20 20 chdir($dir);
21 21  
22 22 // Setup php binary path
23 23 $phpPath = realpath('../../php/php.exe');
24   -
25 24 if (!is_file($phpPath))
26 25 {
27 26 $default->log->error("Scheduler: php not found: $phpPath");
28 27 exit;
29 28 }
30 29  
31   -// Main Scheduler Service Loop
32   -while (1) {
33   -
34   - switch (win32_get_last_control_message()) {
  30 +$default->log->error("Scheduler Service: starting main loop");
35 31  
36   - case WIN32_SERVICE_CONTROL_CONTINUE: break; // Continue server routine
37   - case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_NO_ERROR); break; // Respond with status
38   - case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); exit; // Terminate script
39   - default: win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED); // Add more cases to handle other service calls
  32 +$loop = true;
  33 +// Main Scheduler Service Loop
  34 +while ($loop)
  35 +{
  36 + switch (win32_get_last_control_message())
  37 + {
  38 +
  39 + case WIN32_SERVICE_CONTROL_CONTINUE:
  40 + break; // Continue server routine
  41 + case WIN32_SERVICE_CONTROL_INTERROGATE:
  42 + win32_set_service_status(WIN32_NO_ERROR);
  43 + break; // Respond with status
  44 + case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED);
  45 + $loop = false; // Terminate script
  46 + continue;
  47 + default:
  48 + win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED); // Add more cases to handle other service calls
40 49 }
41   -
42   -
43   -
44   -
45 50 // Run the scheduler script
46   -
47 51 $cmd = "\"$phpPath\" scheduler.php";
48 52  
49 53 $cmd = str_replace( '/','\\',$cmd);
... ... @@ -58,4 +62,6 @@ while (1) {
58 62 }
59 63 win32_set_service_status(WIN32_SERVICE_STOPPED);
60 64  
61   -?>
  65 +$default->log->error("Scheduler Service: exiting main loop");
  66 +
  67 +?>
62 68 \ No newline at end of file
... ...