Browse Source

HPCC-26880 Use dali port from environment if customized

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith 3 years ago
parent
commit
9f7fd94b05

+ 26 - 6
dali/dalistop/dalistop.cpp

@@ -17,32 +17,52 @@
 
 #include "platform.h"
 #include "jlib.hpp"
+#include "jfile.hpp"
 #include "jmisc.hpp"
 #include "mpbase.hpp"
 #include "mpcomm.hpp"
 #include "daclient.hpp"
 
 
-int main(int argc, char* argv[])
+int main(int argc, const char* argv[])
 {
     InitModuleObjects();
     int exitCode = 1;
     try
     {
+        unsigned port = 0;
+        const char *server = nullptr;
         if (argc<2)
         {
-            printf("usage: dalistop <server_ip:port> [/nowait]\n");
-            printf("eg:  dalistop .                          -- stop dali server running locally\n");
-            printf("     dalistop eq0001016                  -- stop dali server running remotely\n");
+            // with no args, use port from daliconfig if present (used by init scripts)
+            Owned<IFile> daliConfigFile = createIFile("daliconf.xml");
+            if (daliConfigFile->exists())
+            {
+                Owned<IPropertyTree> daliConfig = createPTree(*daliConfigFile, ipt_caseInsensitive);
+                port = daliConfig->getPropInt("@port", DALI_SERVER_PORT);
+                server = ".";
+            }
+            else
+            {
+                printf("usage: dalistop <server_ip:port> [/nowait]\n");
+                printf("eg:  dalistop .                          -- stop dali server running locally\n");
+                printf("     dalistop eq0001016                  -- stop dali server running remotely\n");
+            }
         }
         else
         {
+            server = argv[1];
+            port = DALI_SERVER_PORT;
+        }
+
+        if (server)
+        {
             SocketEndpoint ep;
-            ep.set(argv[1],DALI_SERVER_PORT);
+            ep.set(server, port);
             bool nowait = false;
             if (argc>=3)
                 nowait = stricmp(argv[2],"/nowait")==0;
-            printf("Stopping Dali Server on %s\n",argv[1]);
+            printf("Stopping Dali Server on %s, port=%u\n", server, port);
 
             Owned<IGroup> group = createIGroup(1,&ep); 
             initClientProcess(group, DCR_DaliStop);

+ 2 - 1
dali/server/daserver.cpp

@@ -469,6 +469,7 @@ int main(int argc, const char* argv[])
         serverConfig.setown(loadConfiguration(defaultYaml, argv, "dali", "DALI", DALICONF, nullptr));
         Owned<IFile> sentinelFile = createSentinelTarget();
         removeSentinelFile(sentinelFile);
+        port = serverConfig->getPropInt("@port");
 #ifndef _CONTAINERIZED
         if (!checkCreateDaemon(argc, argv))
             return EXIT_FAILURE;
@@ -681,7 +682,7 @@ int main(int argc, const char* argv[])
         SocketEndpointArray epa;
         if (!server)
         {
-            ep.setLocalHost(DALI_SERVER_PORT);
+            ep.setLocalHost(port ? port : DALI_SERVER_PORT);
             epa.append(ep);
         }
         else

+ 2 - 2
initfiles/bin/init_dali.in

@@ -30,8 +30,8 @@ rm -f ${SENTINEL}
 
 killed()
 {
-    log "calling dalistop ."
-    dalistop .
+    log "calling dalistop"
+    dalistop
     log "Attempting to kill $component"
     dali_kill_process ${PID_NAME} daserver 3 ${SENTINEL}
     if [[ $? -eq 1 ]]; then

+ 4 - 0
initfiles/componentfiles/configxml/dali.xsl

@@ -65,6 +65,7 @@
 
 
   <xsl:variable name="daliServerNode" select="/Environment/Software/DaliServerProcess[@name=$process]"/>
+  <xsl:variable name="daliServerPort" select="/Environment/Software/DaliServerProcess[@name=$process]/Instance[1]/@port"/>
 
 
   <xsl:template match="/">
@@ -82,6 +83,9 @@
       <xsl:attribute name="name">
         <xsl:value-of select="@name"/>
       </xsl:attribute>
+      <xsl:attribute name="port">
+        <xsl:value-of select="$daliServerPort"/>
+      </xsl:attribute>
       <xsl:if test="string(@LogDir)!=''">
         <xsl:attribute name="log_dir">
           <xsl:value-of select="@LogDir"/>