File tree 3 files changed +65
-2
lines changed
3 files changed +65
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace STS \Tunneler \Console ;
3
+
4
+ use Illuminate \Console \Command ;
5
+ use STS \Tunneler \Jobs \CreateTunnel ;
6
+
7
+ class TunnelerReset extends Command
8
+ {
9
+ /**
10
+ * The name and signature of the console command.
11
+ *
12
+ * @var string
13
+ */
14
+ protected $ signature = 'tunneler:reset ' ;
15
+
16
+ /**
17
+ * The console command description.
18
+ *
19
+ * @var string
20
+ */
21
+ protected $ description = 'Destroy and reconnect the SSH tunnel ' ;
22
+
23
+ /**
24
+ * Create a new command instance.
25
+ *
26
+ * @return void
27
+ */
28
+ public function __construct ()
29
+ {
30
+ parent ::__construct ();
31
+ }
32
+
33
+ /**
34
+ * Execute the console command.
35
+ *
36
+ * @return int
37
+ */
38
+ public function handle ()
39
+ {
40
+ $ tunnel = new CreateTunnel ();
41
+ $ tunnel ->destoryTunnel ();
42
+
43
+ \Artisan::call ('tunneler:activate ' );
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -58,13 +58,13 @@ public function handle(): int
58
58
}
59
59
60
60
$ this ->createTunnel ();
61
-
61
+
62
62
$ tries = config ('tunneler.tries ' );
63
63
for ($ i = 0 ; $ i < $ tries ; $ i ++) {
64
64
if ($ this ->verifyTunnel ()) {
65
65
return 2 ;
66
66
}
67
-
67
+
68
68
// Wait a bit until next iteration
69
69
usleep (config ('tunneler.wait ' ));
70
70
}
@@ -101,6 +101,15 @@ protected function verifyTunnel()
101
101
return $ this ->runCommand ($ this ->ncCommand );
102
102
}
103
103
104
+ /*
105
+ * Use pkill to kill the SSH tunnel
106
+ */
107
+
108
+ public function destoryTunnel (){
109
+ $ ssh_command = preg_replace ('/[\s]{2}[\s]*/ ' ,' ' ,$ this ->sshCommand );
110
+ return $ this ->runCommand ('pkill -f " ' .$ ssh_command .'" ' );
111
+ }
112
+
104
113
/**
105
114
* Runs a command and converts the exit code to a boolean
106
115
* @param $command
Original file line number Diff line number Diff line change 2
2
3
3
use Illuminate \Support \ServiceProvider ;
4
4
use STS \Tunneler \Console \TunnelerCommand ;
5
+ use STS \Tunneler \Console \TunnelerReset ;
5
6
use STS \Tunneler \Jobs \CreateTunnel ;
6
7
7
8
@@ -50,6 +51,14 @@ function ($app) {
50
51
);
51
52
52
53
$ this ->commands ('command.tunneler.activate ' );
54
+
55
+ $ this ->app ->singleton ('command.tunneler.reset ' ,
56
+ function ($ app ) {
57
+ return new TunnelerReset ();
58
+ }
59
+ );
60
+
61
+ $ this ->commands ('command.tunneler.reset ' );
53
62
}
54
63
55
64
/**
You can’t perform that action at this time.
0 commit comments