private function action(callable $command = null) { $error = call_user_func($command); if ($error !== 0) { cmd::echoL2('ERROR: ' . HelpMsg::Get($error) . PHP_EOL); } else { cmd::echoL2('Job DONE' . PHP_EOL); SC::setFailture(Settings::$service); if (cmd::$errcode != ErrorCodes::SERVICE_DOES_NOT_EXIST) { echo PHP_EOL . SC::Info() . PHP_EOL; echo PHP_EOL . SC::getFailture() . str_repeat(PHP_EOL, 2); } } }
<?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; }); }