- RedHat startup script for netxmsd added
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 28 Sep 2004 18:59:19 +0000 (18:59 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 28 Sep 2004 18:59:19 +0000 (18:59 +0000)
- PID file added (UNIX only)

.gitattributes
contrib/startup/redhat/netxmsd [new file with mode: 0644]
src/server/core/config.cpp
src/server/core/main.cpp
src/server/core/nms_core.h

index 60464fd..3af7361 100644 (file)
@@ -15,6 +15,7 @@
 contrib/dct/generic_agent.dct -text
 contrib/dct/generic_object.dct -text
 contrib/logo.jpg -text
+contrib/startup/redhat/netxmsd -text
 doc/Makefile.am -text
 doc/admin_guide.doc -text
 doc/internals.rtf -text
diff --git a/contrib/startup/redhat/netxmsd b/contrib/startup/redhat/netxmsd
new file mode 100644 (file)
index 0000000..37b86fe
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# netxmsd This script starts and stops the netxmsd daemon
+#
+# chkconfig: 2345 95 05
+#
+# description: netxmsd is a NetXMS server daemon process
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+# Source networking configuration.
+. /etc/sysconfig/network
+
+# Check that networking is up.
+[ ${NETWORKING} = "no" ] && exit 0
+
+# Source netxmsdd configuration.
+if [ -f /etc/sysconfig/netxmsd ] ; then
+        . /etc/sysconfig/netxmsd
+else
+        NETXMSD_OPTIONS=""
+        NETXMSD_CONFIG="/etc/netxmsd.conf"
+        NETXMSD_PID_FILE="/var/run/netxmsd.pid"
+fi
+
+[ -f /usr/bin/netxmsd -o -f /usr/local/bin/netxmsd ] || exit 0
+PATH=$PATH:/usr/bin:/usr/local/bin
+
+# See how we were called.
+case "$1" in
+  start)
+       # Start daemon.
+       echo -n "Starting netxmsd: "
+       daemon netxmsd $NETXMSD_OPTIONS --config $NETXMSD_CONFIG --pid-file $NETXMSD_PID_FILE
+       RETVAL=$?
+        echo
+        [ $RETVAL = 0 ] && touch /var/lock/subsys/netxmsd
+        ;;
+  stop)
+        # Stop daemons.
+        echo -n "Shutting down netxmsd: "
+        kill `cat $NETXMSD_PID_FILE 2>/dev/null` 2> /dev/null
+        RETVAL=$?
+        if [ $RETVAL = 0 ] ; then
+                success
+        else
+                failure
+        fi
+        echo
+        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/netxmsd
+        ;;
+  restart)
+        $0 stop
+        $0 start
+        ;;
+  condrestart)
+       [ -e /var/lock/subsys/netxmsd ] && $0 restart
+       ;;
+  status)
+       status netxmsd
+       ;;
+  *)
+       echo "Usage: $0 {start|stop|restart|status|condrestart}"
+       exit 1
+esac
+
+exit 0
index e21caca..3b91902 100644 (file)
@@ -43,6 +43,9 @@ static char help_text[]="NetXMS Server Version " NETXMS_VERSION_STRING "\n"
                         "   --debug-housekeeper : Print debug information for housekeeping thread.\n"
                         "   --debug-locks       : Print debug information about component locking.\n"
                         "   --dump-sql          : Dump all SQL queries to log.\n"
+#ifndef _WIN32
+                        "   --pid-file <file>   : Specify pid file.\n"
+#endif
                         "\n"
                         "Valid commands are:\n"
                         "   check-config        : Check configuration file syntax\n"
@@ -129,6 +132,13 @@ BOOL ParseCommandLine(int argc, char *argv[])
          i++;
          strcpy(g_szConfigFile, argv[i]);     // Next word should contain name of the config file
       }
+#ifndef _WIN32
+      else if (!strcmp(argv[i], "--pid-file"))  // PID file
+      {
+         i++;
+         strcpy(g_szPIDFile, argv[i]);     // Next word should contain name of the PID file
+      }
+#endif
       else if (!strcmp(argv[i], "--debug-all"))
       {
          g_dwFlags |= AF_DEBUG_ALL;
index 55b61c4..3d57a03 100644 (file)
@@ -61,6 +61,9 @@ THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg);
 DWORD g_dwFlags = AF_USE_EVENT_LOG;
 char g_szConfigFile[MAX_PATH] = DEFAULT_CONFIG_FILE;
 char g_szLogFile[MAX_PATH] = DEFAULT_LOG_FILE;
+#ifndef _WIN32
+char g_szPIDFile[MAX_PATH] = "/var/run/netxmsd.pid";
+#endif
 DB_HANDLE g_hCoreDB = 0;
 DWORD g_dwDiscoveryPollingInterval;
 DWORD g_dwStatusPollingInterval;
@@ -354,6 +357,11 @@ void Shutdown(void)
       delete g_pIndexById[i].pObject;
 
    CloseLog();
+
+   // Remove PID file
+#ifndef _WIN32
+   remove(g_szPIDFile);
+#endif
 }
 
 
@@ -549,6 +557,7 @@ int main(int argc, char *argv[])
 {
 #ifndef _WIN32
    int i;
+   FILE *fp;
 #endif
 
    if (!ParseCommandLine(argc, argv))
@@ -592,6 +601,14 @@ int main(int argc, char *argv[])
       }
    }
 
+   // Write PID file
+   fp = fopen(g_szPIDFile, "w");
+   if (fp != NULL)
+   {
+      fprintf(fp, "%d", getpid());
+      fclose(fp);
+   }
+
    // Setup signal handlers
    for(i = 0; i < 32; i++)
       signal(i, SIG_IGN);
index cfdb2cf..09ca610 100644 (file)
@@ -86,8 +86,8 @@
 #else    /* _WIN32 */
 
 #define DEFAULT_SHELL         "/bin/sh"
-#define DEFAULT_CONFIG_FILE   "/etc/netxms.conf"
-#define DEFAULT_LOG_FILE      "/var/log/netxms.log"
+#define DEFAULT_CONFIG_FILE   "/etc/netxmsd.conf"
+#define DEFAULT_LOG_FILE      "/var/log/netxmsd.log"
 #define DEFAULT_DATA_DIR      "/var/netxms"
 
 #define DDIR_MIBS             "/mibs"
@@ -455,6 +455,9 @@ void DumpSessions(void);
 extern DWORD g_dwFlags;
 extern char g_szConfigFile[];
 extern char g_szLogFile[];
+#ifndef _WIN32
+extern char g_szPIDFile[];
+#endif
 extern char g_szDataDir[];
 
 extern char g_szDbDriver[];