Beispiel #1
0
 public function run()
 {
     //TRUE on success; FALSE on parameter problem; Win32 Error Code on error
     $code = win32_start_service_ctrl_dispatcher($this->serviceName);
     if (!$code) {
         throw new \Exception("Error running service: " . $this->serviceDisplayName . ". Was the service started?");
     }
     if ($code !== TRUE && php_sapi_name() !== 'cli') {
         $codeName = array_search($code, get_defined_constants(true)['win32service']);
         throw new \Exception("Error running service: " . $this->serviceDisplayName . " with code: " . $codeName);
     }
     win32_set_service_status(WIN32_SERVICE_START_PENDING);
     error_log("Service " . $this->serviceDisplayName . " setting up run...");
     $this->setupRun();
     win32_set_service_status(WIN32_SERVICE_RUNNING);
     error_log("Service " . $this->serviceDisplayName . " running...");
     while (WIN32_SERVICE_CONTROL_STOP !== win32_get_last_control_message()) {
         $this->msgs[] = win32_get_last_control_message();
         $this->work();
     }
 }
Beispiel #2
0
        KalturaLog::info('Service Installed');
        exit(0);
    case 'uninstall':
        win32_delete_service($serviceName);
        KalturaLog::info('Service Removed');
        exit(0);
    case 'start':
        win32_start_service($serviceName);
        KalturaLog::info('Service Started');
        exit(0);
    case 'stop':
        win32_stop_service($serviceName);
        KalturaLog::info('Service Stopped');
        exit(0);
    case 'run':
        win32_start_service_ctrl_dispatcher($serviceName);
        win32_set_service_status(WIN32_SERVICE_RUNNING);
        break;
    case 'debug':
        set_time_limit(10);
        break;
    default:
        KalturaLog::info('Unkown action');
        exit(-1);
}
$kscheduler = new KGenericScheduler($phpPath, $iniDir);
while (1) {
    //Handle Windows Service Request
    if ($serviceAction == 'run') {
        switch (win32_get_last_control_message()) {
            case WIN32_SERVICE_CONTROL_CONTINUE:
Beispiel #3
0
<?php

namespace Albus\Win32Service;

use Albus\CMD\SC;
use Albus\Win32Service\Win32Constants\ServiceStatusConstants;
switch (PHP_SAPI) {
    case !'cli':
        break;
    default:
        Settings::getCLIparams();
        win32_start_service_ctrl_dispatcher(Settings::$service);
        register_shutdown_function(function () {
            win32_set_service_status(ServiceStatusConstants::STOPPED);
        });
        SC::$onFailtureRun = 5000;
        SC::$onFailtureRestart = 3000;
        SC::$msFailterCountReset = 5000;
        echo 'Start action: ' . Settings::$action . PHP_EOL;
        Settings::$params = urldecode(http_build_query(['-f' => escapeshellarg(Settings::$ScriptPathName), '-- --action' => escapeshellarg('run'), '--service' => escapeshellarg(Settings::$service)], null, ' '));
        call_user_method(Settings::$action, new Deamon());
        register_shutdown_function(function () {
            echo 'Stop action: ' . Settings::$action . PHP_EOL;
        });
}
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * KnowledgeTree" logo and retain the original copyright notice. If the display of the
 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
 * must display the words "Powered by KnowledgeTree" and retain the original
 * copyright notice.
 * Contributor( s): ______________________________________
 *
 */
$myservicename = 'ktscheduler';
// Connect to service dispatcher and notify that startup was successful
if (!win32_start_service_ctrl_dispatcher($myservicename)) {
    die('Could not connect to service :' . $myservicename);
}
win32_set_service_status(WIN32_SERVICE_RUNNING);
// Scheduler is dependent on the mysql server being up,
// so we sleep for a minute to ensure the server is running before we start the scheduler
sleep(120);
chdir(dirname(__FILE__));
// need to be here to include dmsDefaults
require_once '../../config/dmsDefaults.php';
global $default;
$config = KTConfig::getSingleton();
$schedulerInterval = $config->get('KnowledgeTree/schedulerInterval', 30);
// interval in seconds
// Change to knowledgeTree/bin folder
$dir = realpath(dirname(__FILE__) . '/..');