Skip to content

Commit ca975d5

Browse files
author
David Barnes
committed
- Add a tunneler:reset command
- Add pkill method to destroy the ssh tunnel
1 parent ec5c62e commit ca975d5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Console/TunnelerReset.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function __construct()
3838
public function handle()
3939
{
4040
$tunnel = new CreateTunnel();
41-
return 0;
41+
$tunnel->destoryTunnel();
42+
43+
\Artisan::call('tunneler:activate');
4244
}
4345
}

src/Jobs/CreateTunnel.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public function handle(): int
5858
}
5959

6060
$this->createTunnel();
61-
61+
6262
$tries = config('tunneler.tries');
6363
for ($i = 0; $i < $tries; $i++) {
6464
if ($this->verifyTunnel()) {
6565
return 2;
6666
}
67-
67+
6868
// Wait a bit until next iteration
6969
usleep(config('tunneler.wait'));
7070
}
@@ -101,6 +101,14 @@ protected function verifyTunnel()
101101
return $this->runCommand($this->ncCommand);
102102
}
103103

104+
/*
105+
* Use pkill to kill the SSH tunnel
106+
*/
107+
108+
public function destoryTunnel(){
109+
return $this->runCommand('pkill -f "'.$this->sshCommand.'"');
110+
}
111+
104112
/**
105113
* Runs a command and converts the exit code to a boolean
106114
* @param $command

0 commit comments

Comments
 (0)