fixed broken agent restart if agent started manually on systemd managed system; minor...
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 30 Sep 2017 09:35:23 +0000 (12:35 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 30 Sep 2017 09:35:23 +0000 (12:35 +0300)
configure.ac
src/agent/core/Makefile.am
src/agent/core/nxagentd.cpp

index 580fc83..6187224 100644 (file)
@@ -65,6 +65,7 @@ STATIC_SUBAGENT_LIST=""
 PROPOSED_STATIC_SUBAGENTS="default"
 SUBAGENT_DIRS=""
 SUBAGENT_LIBS=""
+AGENT_LIBS=""
 AGENT_DIRS=""
 SERVER_LIBS=""
 SERVER_TOOLS=""
@@ -718,7 +719,7 @@ AC_ARG_WITH(tests,
 AC_ARG_ENABLE(systemd,
 [AS_HELP_STRING(--disable-systemd,disable Systemd support)],
 [
-       if test "x$$enableval" = "xno"; then
+       if test "x$enableval" = "xno"; then
                SYSTEMD_SUPPORT="no"
        fi
 ])
@@ -905,6 +906,8 @@ if test $? = 0; then
                        # unknown
                        ;;
        esac
+else
+       SYSTEMD_SUPPORT="no"
 fi
 
 check_substr "$COMPONENTS" "server"
@@ -2045,6 +2048,11 @@ else
        HAVE_LIBSSH=no
 fi
 
+
+#--------------------------------------------------------------------
+# Checks for LDAP libraries
+#--------------------------------------------------------------------
+
 if test "x$LDAP_SUPPORT" = "xyes"; then
        AC_CHECK_HEADER(ldap.h,HAVE_LDAP=yes,HAVE_LDAP=no)
        if test "x$HAVE_LDAP" = "xyes"; then
@@ -2086,15 +2094,24 @@ if test "x$LDAP_SUPPORT" = "xyes"; then
        LDAP_SUPPORT="$HAVE_LDAP"
 fi
 
+
+#--------------------------------------------------------------------
+# Checks for systemd libraries
+#--------------------------------------------------------------------
+
 if test "x$SYSTEMD_SUPPORT" = "xyes"; then
-       AC_CHECK_HEADER(systemd/sd-bus.h,HAVE_SYSTEMD=yes,HAVE_SYSTEMD=no)
+       AC_CHECK_HEADER(systemd/sd-bus.h, [ HAVE_SYSTEMD=yes ], [ HAVE_SYSTEMD=no ])
+       if test "x$HAVE_SYSTEMD" = "xyes"; then
+               AC_CHECK_LIB(systemd, sd_bus_open_system, [ HAVE_SYSTEMD=yes ], [ HAVE_SYSTEMD=no ])
+       fi
        if test "x$HAVE_SYSTEMD" = "xyes"; then
                AC_DEFINE(WITH_SYSTEMD, 1, Define to 1 if you have Systemd libraries and headers)
-               SUBAGENT_LIBS="-lsystemd $SUBAGENT_LIBS"
+               AGENT_LIBS="$AGENT_LIBS -lsystemd"
        fi
        SYSTEMD_SUPPORT="$HAVE_SYSTEMD"
 fi
 
+
 #--------------------------------------------------------------------
 # Checks for data types
 #--------------------------------------------------------------------
@@ -3474,6 +3491,7 @@ AS_IF([test "x$with_dist" = "xyes"],
 AC_SUBST(DB_DRIVERS)
 AC_SUBST(MODULES)
 AC_SUBST(AGENT_DIRS)
+AC_SUBST(AGENT_LIBS)
 AC_SUBST(SUBAGENT_DIRS)
 AC_SUBST(SERVER_INCLUDE)
 AC_SUBST(SERVER_LIBS)
@@ -3869,6 +3887,7 @@ else
 fi
 if test "x${BUILD_AGENT}" = "xyes"; then
        echo "Build Agent             : YES"
+       echo "Agent libs              :${AGENT_LIBS}"
        echo "Agent extra components  :${AGENT_DIRS}"
        echo "Subagents list          :${SUBAGENT_DIRS}"
        if test "x${SYSTEMD_SUPPORT}" = "xyes"; then
index f6c80d1..8e6c1ca 100644 (file)
@@ -8,9 +8,9 @@ nxagentd_SOURCES = messages.c actions.cpp appagent.cpp comm.cpp config.cpp \
                    static_subagents.cpp subagent.cpp sysinfo.cpp syslog.cpp \
                                   systemd.cpp tools.cpp trap.cpp tunnel.cpp upgrade.cpp watchdog.cpp
 if USE_INTERNAL_EXPAT
-nxagentd_LDADD = ../../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @top_srcdir@/src/libexpat/libexpat/libnxexpat.la @SUBAGENT_LIBS@
+nxagentd_LDADD = ../../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @top_srcdir@/src/libexpat/libexpat/libnxexpat.la @AGENT_LIBS@ @SUBAGENT_LIBS@
 else
-nxagentd_LDADD = ../../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @SUBAGENT_LIBS@ 
+nxagentd_LDADD = ../../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @AGENT_LIBS@ @SUBAGENT_LIBS@ 
 endif
 if STATIC_BUILD
 if ALL_STATIC
index 2929f4d..f82dd1c 100644 (file)
@@ -1304,16 +1304,16 @@ static void DoRestartActions(UINT32 dwOldPID)
          CloseHandle(hProcess);
       }
    }
-#elif WITH_SYSTEMD
-   if (RestartService(dwOldPID))
-      dwOldPID = 0; // Success
 #else
-   if (dwOldPID == 0) // Already killed
-      return;
-
-   int i;
-
+#if WITH_SYSTEMD
+   if (RestartService(dwOldPID))
+   {
+      // successfully restarted agent service using systemd, exit this instance
+      exit(0);
+   }
+#endif
    kill(dwOldPID, SIGTERM);
+   int i;
    for(i = 0; i < 30; i++)
    {
       sleep(2);