@@ -59,9 +59,10 @@ public static Process setUp(String user, String key, LocalTunnel localTunnel, St
5959 logger .info ("Tunnel Binary downloaded from " + Constant .LINUX_BINARY_URL );
6060 }
6161 // Get Tunnel Log path name
62+ String tunnelPidPath = getPidPath (workspacePath , buildnumber );
6263 String tunnelLogPath = getTunnelLogPath (workspacePath , buildnumber );
6364 logger .info ("Tunnel Log Path:" + tunnelLogPath );
64- return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel );
65+ return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel , tunnelPidPath );
6566 } else {
6667 logger .warning ("tunnelFolderPath empty" );
6768 }
@@ -95,9 +96,10 @@ public static Process setUp(String user, String key, LocalTunnel localTunnel, St
9596 logger .info ("Tunnel Binary downloaded from " + Constant .MAC_BINARY_URL );
9697 }
9798 // Get Tunnel Log path name
99+ String tunnelPidPath = getPidPath (workspacePath , buildnumber );
98100 String tunnelLogPath = getTunnelLogPath (workspacePath , buildnumber );
99101 logger .info ("Tunnel Log Path:" + tunnelLogPath );
100- return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel );
102+ return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel , tunnelPidPath );
101103 } else {
102104 logger .warning ("tunnelFolderPath empty" );
103105 }
@@ -131,9 +133,10 @@ public static Process setUp(String user, String key, LocalTunnel localTunnel, St
131133 logger .info ("Tunnel Binary downloaded from " + binaryURL );
132134 }
133135 // Get Tunnel Log path name
136+ String tunnelPidPath = getTunnelPidPathForWindows (workspacePath , buildnumber );
134137 String tunnelLogPath = getTunnelLogPathForWindows (workspacePath , buildnumber );
135138 logger .info ("Tunnel Log Path:" + tunnelLogPath );
136- return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel ,Constant .OS .WIN );
139+ return runCommandLine (tunnelBinaryLocation , tunnelLogPath , user , key , tunnelName ,localTunnel ,tunnelPidPath , Constant .OS .WIN );
137140 } else {
138141 logger .warning ("tunnelFolderPath empty" );
139142 }
@@ -210,6 +213,36 @@ private static String getTunnelLogPath(FilePath workspacePath, String buildnumbe
210213 }
211214 return tunnelLogPath ;
212215 }
216+ private static String getPidPath (FilePath workspacePath , String buildnumber ) {
217+ String tunnelPidPath = ".pid" ;
218+ try {
219+ if (workspacePath != null ) {
220+ // Create Tunnel Log Path
221+ tunnelPidPath = new StringBuilder (buildnumber ).append (".pid" ).toString ();
222+
223+ // Create a Folder in workspace
224+ FilePath tunnelFolderPath = new FilePath (workspacePath , Constant .DEFAULT_TUNNEL_FOLDER_NAME );
225+ File folder = new File (tunnelFolderPath .getRemote ());
226+ if (!folder .exists ()) {
227+ if (folder .mkdir ()) {
228+ logger .info ("Directory is created! at " + tunnelFolderPath .getRemote ());
229+ FilePath tunnelPath = new FilePath (tunnelFolderPath , tunnelPidPath );
230+ return tunnelPath .getRemote ();
231+ } else {
232+ logger .info ("Failed to create directory! at " + tunnelFolderPath .getRemote ());
233+ FilePath tunnelPath = new FilePath (workspacePath , tunnelPidPath );
234+ return tunnelPath .getRemote ();
235+ }
236+ } else {
237+ FilePath tunnelPath = new FilePath (tunnelFolderPath , tunnelPidPath );
238+ return tunnelPath .getRemote ();
239+ }
240+ }
241+ } catch (Exception e ) {
242+ logger .info (e .getMessage ());
243+ }
244+ return tunnelPidPath ;
245+ }
213246
214247 private static String getTunnelLogPathForWindows (FilePath workspacePath , String buildnumber ) {
215248 String tunnelLogPath = "tunnel.log" ;
@@ -242,6 +275,37 @@ private static String getTunnelLogPathForWindows(FilePath workspacePath, String
242275 return tunnelLogPath ;
243276 }
244277
278+ private static String getTunnelPidPathForWindows (FilePath workspacePath , String buildnumber ) {
279+ String tunnelPidPath = ".pid" ;
280+ try {
281+ if (workspacePath != null ) {
282+ // Create Tunnel Log Path
283+ tunnelPidPath = new StringBuilder (buildnumber ).append (".log" ).toString ();
284+
285+ // Create a Folder in workspace
286+ FilePath tunnelFolderPath = new FilePath (workspacePath , Constant .DEFAULT_TUNNEL_FOLDER_NAME );
287+ File folder = new File (tunnelFolderPath .getRemote ());
288+ if (!folder .exists ()) {
289+ if (folder .mkdir ()) {
290+ logger .info ("Directory is created! at " + tunnelFolderPath .getRemote ());
291+ FilePath tunnelPath = new FilePath (tunnelFolderPath , tunnelPidPath );
292+ return tunnelPath .getRemote ();
293+ } else {
294+ logger .info ("Failed to create directory! at " + tunnelFolderPath .getRemote ());
295+ FilePath tunnelPath = new FilePath (workspacePath , tunnelPidPath );
296+ return tunnelPath .getRemote ();
297+ }
298+ } else {
299+ FilePath tunnelPath = new FilePath (tunnelFolderPath , tunnelPidPath );
300+ return tunnelPath .getRemote ();
301+ }
302+ }
303+ } catch (Exception e ) {
304+ logger .info (e .getMessage ());
305+ }
306+ return tunnelPidPath ;
307+ }
308+
245309 private static String getLatestHash (String url ) throws TunnelHashNotFoundException {
246310 try {
247311 return CapabilityService .sendGetRequest (url );
@@ -327,7 +391,7 @@ public static void unZipIt(String tunnelBinaryZipFileName, String tunnelBinaryFi
327391 }
328392
329393 public static Process runCommandLine (String filePath , String tunnelLogPath , String user , String key ,
330- String tunnelName , LocalTunnel localTunnel ,String ...args ) throws IOException {
394+ String tunnelName , LocalTunnel localTunnel , String tunnelPidPath , String ...args ) throws IOException {
331395 try {
332396 int availablePort = PortAvailabilityUtils .randomFreePort ();
333397 //Updating permissions
@@ -351,6 +415,7 @@ public static Process runCommandLine(String filePath, String tunnelLogPath, Stri
351415 list .addAll (Arrays .asList (extCommands ));
352416 }
353417 list .add ("-v" );
418+ list .add ("--pidfile" );list .add (tunnelPidPath );
354419
355420 // create the process
356421 ProcessBuilder processBuilder = new ProcessBuilder (list );
0 commit comments