$instance_key = $device . ($sudo ? '_sudo' : '');
- if (!isset($ssh[$instance_key])) {
+ if (!isset($ssh[$instance_key]) || !is_resource($ssh[$instance_key])) {
if (!isset($devices[$device])) {
$ssh[$instance_key] = false;
} else {
}
}
}
- return $ssh[$device];
+ return $ssh[$instance_key];
}
function sshCommand($command, $device = null, $blocking = true, $sudo = false)
{
- return sshRunCommand($command, $device, $blocking, $sudo);
-// $redis = connectRedis();
-// $queue = $redis->get('ssh_queue');
-// if (!is_array($queue)) {
-// $queue = [];
-// }
-// $queue[] = ['command' => $command, 'device' => $device, 'blocking' => $blocking, 'sudo' => $sudo];
-// $redis->igbset('ssh_queue', $queue);
-// $redis->publish('ssh_event', 'handle_queue');
+ //return sshRunCommand($command, $device, $blocking, $sudo);
+ $redis = connectRedis();
+ $queue = $redis->get('ssh_queue');
+ if (!is_array($queue)) {
+ $queue = [];
+ }
+ $queue[] = ['command' => $command, 'device' => $device, 'blocking' => $blocking, 'sudo' => $sudo];
+ $redis->igbset('ssh_queue', $queue);
+ $redis->publish('ssh_event', 'handle_queue');
}
function sshRunCommand($command, $device = null, $blocking = true, $sudo = false)