Change return values and logic for starting and stopping tmux scripts

This commit is contained in:
DariusIII
2017-05-24 11:55:31 +02:00
parent 32b48dcb05
commit d3c456ee98
4 changed files with 22 additions and 15 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
2017-05-24 DariusIII
* Fix: Fix user creation in admin area
* Chg: Change return values and logic for starting and stopping tmux scripts
* Fix: Fix user creation in admin area
2017-05-23 DariusIII
* Chg: Update ReleaseComments and comments-list
* Chg: Update DNZBFailures class
+6 -6
View File
@@ -6,11 +6,11 @@
*
* It will start the tmux server and monitoring scripts if needed.
*/
//require_once realpath(dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
require_once dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'bootstrap.php';
use nntmux\db\DB;
use nntmux\Tmux;
use nntmux\ColorCLI;
$pdo = new DB();
@@ -18,15 +18,15 @@ $pdo = new DB();
if (`which tmux`) {
$tmux_version = trim(str_replace('tmux ', '', shell_exec('tmux -V')));
if (version_compare($tmux_version, '2.0', '>') && version_compare($tmux_version, '2.3', '<')) {
exit($pdo->log->error("tmux versions 2.1 and 2.2 are not compatible with NNTmux. Aborting\n"));
exit(ColorCLI::error('tmux versions 2.1 and 2.2 are not compatible with NNTmux. Aborting' . PHP_EOL));
}
} else {
exit($pdo->log->error("tmux binary not found. Aborting\n"));
exit(ColorCLI::error('tmux binary not found. Aborting' . PHP_EOL));
}
$tmux = new Tmux();
$tmux_settings = $tmux->get();
$tmux_session = (isset($tmux_settings->tmux_session)) ? $tmux_settings->tmux_session : 0;
$tmux_session = $tmux_settings->tmux_session ?? 0;
$path = __DIR__;
// Set running value to on.
@@ -39,7 +39,7 @@ exec('tmux new-session -ds placeholder 2>/dev/null');
$session = shell_exec("tmux list-session | grep $tmux_session");
// Kill the placeholder
exec('tmux kill-session -t placeholder');
if (count($session) == 0) {
echo $pdo->log->info("Starting the tmux server and monitor script.\n");
if (count($session) === 0) {
echo ColorCLI::info("Starting the tmux server and monitor script.\n");
passthru("php $path/run.php");
}
+5 -5
View File
@@ -29,15 +29,15 @@ Start or stop the processing of tmux scripts. This is functionally equivalent to
'tmux running' setting in admin.
HELP_TEXT;
if ($argc == 1) {
if ($argc === 1) {
exit($message);
}
if (in_array($argv[1], $start)) {
if (in_array($argv[1], $start, false)) {
passthru('php start.php');
} else if (in_array($argv[1], $stop)) {
} else if (in_array($argv[1], $stop, false)) {
passthru('php stop.php');
} else {
echo "Unrecognised command '{$argv[1]}''\n";
echo 'Unrecognised command '. $argv[1] . PHP_EOL;
exit($message);
}
}
+9 -3
View File
@@ -585,33 +585,39 @@ class Tmux
if ($running === false) {
throw new \RuntimeException('Tmux\\\'s running flag was not found in the database.' . PHP_EOL . 'Please check the tables are correctly setup.' . PHP_EOL);
}
return ($running === 1);
if ((int)$running === 0) {
return false;
}
return true;
}
/**
* Check if Tmux is running, if it is, stop it.
*
* @return bool true if scripts were running, false otherwise.
* @throws \RuntimeException
* @access public
*/
public function stopIfRunning(): bool
{
if ($this->isRunning() === 1) {
if ($this->isRunning() === true) {
$this->pdo->queryExec("UPDATE tmux SET value = 0 WHERE setting = 'running'");
$sleep = $this->get()->monitor_delay;
echo ColorCLI::header('Stopping tmux scripts and waiting ' . $sleep . ' seconds for all panes to shutdown');
sleep($sleep);
return true;
}
ColorCLI::doEcho(ColorCLI::info('Tmux scripts are not running!'));
return false;
}
/**
* @return bool|\PDOStatement
* @throws \RuntimeException
*/
public function startRunning()
{
if (!$this->isRunning()) {
if ($this->isRunning() === false) {
return $this->pdo->queryExec("UPDATE tmux SET value = 1 WHERE setting = 'running'");
}
return true;