@@ -562,7 +562,12 @@ private static Process checkStartElasticSearch() {
562562 }
563563 String javaHome = System .getProperty ("java.home" );
564564 System .out .println ("Starting " + (osDirExists ? "OpenSearch" : "ElasticSearch" ) + " install found in " + workDir + ", pid file not found (JDK: " + javaHome + ")" );
565- boolean isWindows = System .getProperty ("os.name" ).toLowerCase ().startsWith ("windows" );
565+
566+ String os = System .getProperty ("os.name" ).toLowerCase ();
567+ boolean isWindows = os .startsWith ("windows" );
568+ boolean isMac = os .startsWith ("mac" );
569+ boolean isLinux = os .contains ("nix" ) || os .contains ("nux" ) || os .contains ("aix" );
570+
566571 try {
567572 String [] command ;
568573 if (isWindows ) {
@@ -571,9 +576,16 @@ private static Process checkStartElasticSearch() {
571576 command = new String []{"./bin/" + baseName };
572577 try {
573578 boolean elasticsearchOwner = Files .getOwner (Paths .get (runtimePath , baseName )).getName ().equals (baseName );
574- boolean suAble = Runtime .getRuntime ().exec (new String []{"/bin/su" , "-c" , "/bin/true" , baseName }).waitFor () == 0 ;
579+ boolean suAble = false ;
580+ if (isLinux ) {
581+ suAble = Runtime .getRuntime ().exec (new String []{"/bin/su" , "-c" , "/bin/true" , baseName }).waitFor () == 0 ;
582+ } else if (isMac ) {
583+ suAble = Runtime .getRuntime ().exec (new String []{"/usr/bin/sudo" , "-n" , "/usr/bin/true" }).waitFor () == 0 ;
584+ }
575585 if (elasticsearchOwner && suAble ) command = new String []{"su" , "-c" , "./bin/" + baseName , baseName };
576- } catch (IOException e ) {}
586+ } catch (IOException e ) {
587+ System .out .println ("Error to run " + (Arrays .toString (new String []{"/usr/bin/sudo" , "-n" , "/usr/bin/true" })) + ": " + e .getMessage ());
588+ }
577589 }
578590 ProcessBuilder pb = new ProcessBuilder (command );
579591 pb .redirectErrorStream (true );
0 commit comments