Reworked the DaemonCommand.
* Accepts options for PID and log file. * Uses posix_kill whenever available. * Checks that the daemon actually started or stopped. * Try to terminate then kill the daemon. * Uses the logger or output instead of "echo". Added a ProcessControl interface and implementations. Closed #908
This commit is contained in:
parent
15b6917f68
commit
4edefee761
11 changed files with 572 additions and 45 deletions
52
PHPCI/ProcessControl/PosixProcessControl.php
Normal file
52
PHPCI/ProcessControl/PosixProcessControl.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\ProcessControl;
|
||||
|
||||
/**
|
||||
* Control process using the POSIX extension.
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
class PosixProcessControl implements ProcessControlInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param int $pid
|
||||
* @return bool
|
||||
*/
|
||||
public function isRunning($pid)
|
||||
{
|
||||
// Signal "0" is not sent to the process, but posix_kill checks the process anyway;
|
||||
return posix_kill($pid, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a TERMINATE or KILL signal to the process using posix_kill.
|
||||
*
|
||||
* @param int $pid
|
||||
* @param bool $forcefully Whetehr to send TERMINATE (false) or KILL (true).
|
||||
*/
|
||||
public function kill($pid, $forcefully = false)
|
||||
{
|
||||
posix_kill($pid, $forcefully ? 9 : 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this posix_kill is available.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function isAvailable()
|
||||
{
|
||||
return function_exists('posix_kill');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue