]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add -conf, -db, and -log params to the binary to allow for running multiple copies...
authorMichael Jerris <mike@jerris.com>
Tue, 6 Feb 2007 17:05:14 +0000 (17:05 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 6 Feb 2007 17:05:14 +0000 (17:05 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4133 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch.c
src/switch_core.c

index a548e571a8f95b2062181ac7c4c501384f8e2353..0b0ec561c2466fee2d2f3bae8cee73df1e6a0448 100644 (file)
@@ -26,6 +26,7 @@
  * Anthony Minessale II <anthmct@yahoo.com>
  * Michael Jerris <mike@jerris.com>
  * Pawel Pierscionek <pawel@voiceworks.pl>
+ * Bret McDanel <trixter AT 0xdecafbad.com>
  *
  *
  * switch.c -- Main
@@ -206,6 +207,8 @@ int main(int argc, char *argv[])
        pid_t pid = 0;                          // 
        int x;                                          //
        int die = 0;                            //
+    char *usageDesc;
+       int alt_dirs = 0;
 
 #ifdef WIN32
        SERVICE_TABLE_ENTRY dispatchTable[] =
@@ -213,9 +216,35 @@ int main(int argc, char *argv[])
                { SERVICENAME, &service_main },
                { NULL, NULL }
        };
+    usageDesc = "these are the optional arguments you can pass to freeswitch\n"
+        "\t-service         -- start freeswitch as a service, cannot be used if loaded as a console app\n"
+        "\t-install         -- install freeswitch as a service\n"
+        "\t-uninstall       -- remove freeswitch as a service\n"
+        "\t-hp              -- enable high priority settings\n"
+        "\t-stop            -- stop freeswitch\n"
+        "\t-nc              -- do not output to a console and background\n"
+        "\t-conf [confdir]  -- specify an alternate config dir\n"
+        "\t-log [logdir]    -- specify an alternate log dir\n"
+        "\t-db [dbdir]      -- specify an alternate db dir\n";
+#else
+    usageDesc = "these are the optional arguments you can pass to freeswitch\n"
+        "\t-help            -- this message\n"
+        "\t-nf              -- no forking\n"
+        "\t-hp              -- enable high priority settings\n"
+        "\t-stop            -- stop freeswitch\n"
+        "\t-nc              -- do not output to a console and background\n"
+        "\t-vg              -- enable valgrind mode\n"
+        "\t-conf [confdir]  -- specify an alternate config dir\n"
+        "\t-log [logdir]    -- specify an alternate log dir\n"
+        "\t-db [dbdir]      -- specify an alternate db dir\n";
+
 #endif
 
        for (x = 1; x < argc; x++) {
+               if (argv[x] && !strcmp(argv[x], "-help")) {
+                       printf("%s\n",usageDesc);
+            exit(0);
+               }
 #ifdef WIN32
                if (x == 1) {
                        if (argv[x] && !strcmp(argv[x], "-service")) {
@@ -281,12 +310,54 @@ int main(int argc, char *argv[])
                if (argv[x] && !strcmp(argv[x], "-vg")) {
                        vg++;
                }
+
+        if (argv[x] && !strcmp(argv[x], "-conf")) {
+            x++;
+            if (argv[x] && strlen(argv[x])) {
+                SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(argv[x])+1);
+                strcpy(SWITCH_GLOBAL_dirs.conf_dir,argv[x]);
+                               alt_dirs++;
+            } else {
+                fprintf(stderr, "When using -conf you must specify a config directory\n");
+                return 255;
+            }
+        }
+
+        if (argv[x] && !strcmp(argv[x], "-log")) {
+            x++;
+            if (argv[x] && strlen(argv[x])) {
+                SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(argv[x])+1);
+                strcpy(SWITCH_GLOBAL_dirs.log_dir,argv[x]);
+                               alt_dirs++;
+            } else {
+                fprintf(stderr, "When using -log you must specify a log directory\n");
+                return 255;
+            }
+        }
+
+        if (argv[x] && !strcmp(argv[x], "-db")) {
+            x++;
+            if (argv[x] && strlen(argv[x])) {
+                SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(argv[x])+1);
+                strcpy(SWITCH_GLOBAL_dirs.db_dir,argv[x]);
+                               alt_dirs++;
+            } else {
+                fprintf(stderr, "When using -db you must specify a db directory\n");
+                return 255;
+            }
+        }
+            
        }
 
        if (die) {
                return freeswitch_kill_background();
        }
 
+       if (alt_dirs && alt_dirs !=3) {
+               fprintf(stderr, "You must use -conf, -log, and -db together\n");
+               return 255;
+       }
+
        if (nc) {
 
                signal(SIGHUP, handle_SIGHUP);
index 41f10104b066e51b75273f10d5bca597fb4cd334..717b31c020711e8e794215a794b9c3cee86ae31e 100644 (file)
@@ -3936,9 +3936,9 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
 #else
        SWITCH_GLOBAL_dirs.base_dir = SWITCH_PREFIX_DIR;
        SWITCH_GLOBAL_dirs.mod_dir = SWITCH_MOD_DIR;
-       SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR;
-       SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR;
-       SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR;
+       if(!SWITCH_GLOBAL_dirs.conf_dir) SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR;
+       if(!SWITCH_GLOBAL_dirs.log_dir) SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR;
+       if(!SWITCH_GLOBAL_dirs.db_dir) SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR;
        SWITCH_GLOBAL_dirs.script_dir = SWITCH_SCRIPT_DIR;
        SWITCH_GLOBAL_dirs.htdocs_dir = SWITCH_HTDOCS_DIR;
        SWITCH_GLOBAL_dirs.grammar_dir = SWITCH_GRAMMAR_DIR;