Commit fa05946c1f488aaeb8888a518bc5ea8da01f8c2e
1 parent
2e54cb3b
Merged in from DEV trunk...
KTS-3440 "Restart open office periodically" Fixed. A count is incremented on indexing a document (successfully or not), after 50 documents open office is restarted. Committed by: Megan Watson Reviewed by: Conrad Vermuelen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8637 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
100 additions
and
22 deletions
bin/checkopenoffice.php
| ... | ... | @@ -50,10 +50,25 @@ so for windows we use the win32 service status checks. |
| 50 | 50 | // Check if the calling function requires a return value |
| 51 | 51 | $sGiveOutput = (isset($argv[1]) && $argv[1] == 'output') ? true : false; |
| 52 | 52 | |
| 53 | +// Check indexed document count | |
| 54 | +// If the number of indexed documents is greater than the set amount, restart open office | |
| 55 | +// this clears open office's memory usage | |
| 56 | +$resetPoint = 50; // todo: put in config | |
| 57 | +$count = Indexer::getIndexedDocumentCount(); | |
| 58 | + | |
| 59 | +$restartOO = false; | |
| 60 | +if($count > $resetPoint){ | |
| 61 | + $restartOO = true; | |
| 62 | + | |
| 63 | + // reset the count | |
| 64 | + Indexer::updateIndexedDocumentCount(0); | |
| 65 | + $default->log->debug('Check Open Office Task: Restarting open office.'); | |
| 66 | +} | |
| 67 | + | |
| 53 | 68 | // First we check the host:port to see if open office is running |
| 54 | 69 | $sCheckOO = SearchHelper::checkOpenOfficeAvailablity(); |
| 55 | 70 | |
| 56 | -if(empty($sCheckOO)){ | |
| 71 | +if(empty($sCheckOO) && !$restartOO){ | |
| 57 | 72 | // If the check returns empty then it is available on that port so we exit |
| 58 | 73 | if($sGiveOutput){ |
| 59 | 74 | echo 1; |
| ... | ... | @@ -61,21 +76,44 @@ if(empty($sCheckOO)){ |
| 61 | 76 | exit; |
| 62 | 77 | } |
| 63 | 78 | |
| 64 | -// Open office appears not to be running. | |
| 65 | - | |
| 79 | +// Open office appears not to be running or requires a restart | |
| 66 | 80 | if(OS_WINDOWS){ |
| 67 | - // If this is vista, it might be being blocked, so we query the service | |
| 68 | 81 | $OOService = 'ktopenoffice'; |
| 69 | - $result = win32_query_service_status($OOService); | |
| 70 | - | |
| 71 | - if(is_array($result)){ | |
| 72 | - $iProcessId = $result['ProcessId']; | |
| 73 | - if(!empty($iProcessId) && $iProcessId != 0){ | |
| 74 | - // If there is a process id (PID) then open office is running so we exit | |
| 75 | - if($sGiveOutput){ | |
| 76 | - echo 1; | |
| 82 | + $default->log->debug('Check Open Office Task: ' . get_current_user()); | |
| 83 | + | |
| 84 | + if($restartOO){ | |
| 85 | + // If Open office needs to be restarted - stop it here | |
| 86 | + $result_stop = win32_stop_service($OOService); | |
| 87 | + | |
| 88 | + | |
| 89 | + // Wait for the service to stop fully before trying to restart it | |
| 90 | + $continue = false; | |
| 91 | + $cnt = 0; | |
| 92 | + while($continue === false && $cnt < 15){ | |
| 93 | + $result = win32_query_service_status($OOService); | |
| 94 | + | |
| 95 | + if(isset($result['ProcessId']) && $result['ProcessId'] != 0){ | |
| 96 | + // If there is still a process id then the service has not stopped yet. | |
| 97 | + sleep(2); | |
| 98 | + $continue = false; | |
| 99 | + $cnt++; | |
| 100 | + }else{ | |
| 101 | + $continue = true; | |
| 102 | + } | |
| 103 | + } | |
| 104 | + }else{ | |
| 105 | + // If this is vista, checking the port may not work so we query the service | |
| 106 | + $result = win32_query_service_status($OOService); | |
| 107 | + | |
| 108 | + if(is_array($result)){ | |
| 109 | + $iProcessId = $result['ProcessId']; | |
| 110 | + if(!empty($iProcessId) && $iProcessId != 0){ | |
| 111 | + // If there is a process id (PID) then open office is running so we exit | |
| 112 | + if($sGiveOutput){ | |
| 113 | + echo 1; | |
| 114 | + } | |
| 115 | + exit; | |
| 77 | 116 | } |
| 78 | - exit; | |
| 79 | 117 | } |
| 80 | 118 | } |
| 81 | 119 | |
| ... | ... | @@ -96,11 +134,14 @@ if(OS_WINDOWS){ |
| 96 | 134 | |
| 97 | 135 | $default->log->debug('Check Open Office Task: Open office service could not be started. Error code '.$result2); |
| 98 | 136 | |
| 99 | - | |
| 100 | 137 | // Attempt using the dmsctl batch script |
| 101 | 138 | $sPath = realpath('../../bin/dmsctl.bat'); |
| 139 | + | |
| 102 | 140 | if(file_exists($sPath)){ |
| 103 | 141 | $sCmd = "\"$sPath\" start"; |
| 142 | + $default->log->debug('Check Open Office Task: ' . get_current_user()); | |
| 143 | + $default->log->debug('Check Open Office Task: ' . $sCmd); | |
| 144 | + | |
| 104 | 145 | $res = KTUtil::pexec($sCmd); |
| 105 | 146 | |
| 106 | 147 | $default->log->debug('Check Open Office Task: Attempted start using dmsctl.bat.'); |
| ... | ... | @@ -119,25 +160,39 @@ if(OS_WINDOWS){ |
| 119 | 160 | // If the OS is Unix or Linux |
| 120 | 161 | $sPath = realpath('../../dmsctl.sh'); |
| 121 | 162 | if(file_exists($sPath)){ |
| 122 | - $sCmd = "\"$sPath\" start"; | |
| 123 | - KTUtil::pexec($sCmd); | |
| 163 | + // If Open office needs to be restarted - stop it here | |
| 164 | + if($restartOO){ | |
| 165 | + $sCmd = "\"$sPath\" restart soffice"; | |
| 166 | + $default->log->debug('Check Open Office Task: ' . get_current_user()); | |
| 167 | + $default->log->debug('Check Open Office Task: ' . $sCmd); | |
| 124 | 168 | |
| 125 | - $default->log->debug('Check Open Office Task: Attempted start using dmsctl.sh.'); | |
| 126 | - if($sGiveOutput){ | |
| 169 | + KTUtil::pexec($sCmd); | |
| 170 | + | |
| 171 | + $default->log->debug('Check Open Office Task: Attempted restart using dmsctl.sh.'); | |
| 172 | + }else{ | |
| 173 | + $sCmd = "\"$sPath\" start soffice"; | |
| 174 | + $default->log->debug('Check Open Office Task: ' . get_current_user()); | |
| 175 | + $default->log->debug('Check Open Office Task: ' . $sCmd); | |
| 176 | + | |
| 177 | + KTUtil::pexec($sCmd); | |
| 178 | + | |
| 179 | + $default->log->debug('Check Open Office Task: Attempted start using dmsctl.sh.'); | |
| 180 | + } | |
| 181 | + if($sGiveOutput){ | |
| 127 | 182 | echo 2; |
| 128 | 183 | } |
| 129 | 184 | exit; |
| 130 | 185 | }else{ |
| 131 | - $default->log->debug('Check Open Office Task: Can\'t find dmsctl.sh, this may be a source install.'); | |
| 132 | - if($sGiveOutput){ | |
| 186 | + $default->log->debug('Check Open Office Task: Can\'t find dmsctl.sh, this may be a source install.'); | |
| 187 | + if($sGiveOutput){ | |
| 133 | 188 | echo 0; |
| 134 | 189 | } |
| 135 | 190 | exit; |
| 136 | - } | |
| 191 | + } | |
| 137 | 192 | } |
| 138 | 193 | $default->log->debug('Check Open Office Task: Can\'t start Open office, this may be a source install.'); |
| 139 | 194 | if($sGiveOutput){ |
| 140 | 195 | echo 0; |
| 141 | 196 | } |
| 142 | 197 | exit; |
| 143 | -?> | |
| 144 | 198 | \ No newline at end of file |
| 199 | +?> | ... | ... |
search2/indexing/indexerCore.inc.php
| ... | ... | @@ -502,6 +502,26 @@ abstract class Indexer |
| 502 | 502 | DBUtil::runQuery($sql); |
| 503 | 503 | |
| 504 | 504 | $default->log->debug("index: Queuing indexing of $document_id"); |
| 505 | + | |
| 506 | + } | |
| 507 | + | |
| 508 | + private static function incrementCount() | |
| 509 | + { | |
| 510 | + // Get count from system settings | |
| 511 | + $count = Indexer::getIndexedDocumentCount(); | |
| 512 | + $count = (int)$count + 1; | |
| 513 | + Indexer::updateIndexedDocumentCount($count); | |
| 514 | + } | |
| 515 | + | |
| 516 | + public static function getIndexedDocumentCount() | |
| 517 | + { | |
| 518 | + $count = KTUtil::getSystemSetting('indexedDocumentCount', 0); | |
| 519 | + return (int) $count; | |
| 520 | + } | |
| 521 | + | |
| 522 | + public static function updateIndexedDocumentCount($cnt = 0) | |
| 523 | + { | |
| 524 | + KTUtil::setSystemSetting('indexedDocumentCount', $cnt); | |
| 505 | 525 | } |
| 506 | 526 | |
| 507 | 527 | public static function reindexQueue() |
| ... | ... | @@ -964,6 +984,9 @@ abstract class Indexer |
| 964 | 984 | |
| 965 | 985 | foreach($result as $docinfo) |
| 966 | 986 | { |
| 987 | + // increment indexed documents count | |
| 988 | + Indexer::incrementCount(); | |
| 989 | + | |
| 967 | 990 | $docId=$docinfo['document_id']; |
| 968 | 991 | $extension=$docinfo['filetypes']; |
| 969 | 992 | $mimeType=$docinfo['mimetypes']; | ... | ... |